Hey
Im currently working on a game project (a turnbased multiplayer tactical strategy game ). The idea was to handle menus using Swing and then start the game. The game would be run on a different JFrame, using a class that extends Canvas. Render calls are made from inside the gameloop. Both the menus and the game work as they are supposed to separetly, but when trying to start the game from a call in the menus thereās a problem. I surmize its from the heavyweight/lightweight issue.
The JFrame that houses the GameCanvas ( extended from a Canvas in the same way as in http://fivedots.coe.psu.ac.th/~ad/jg/jogl1/index.html, active rendering ) doesnt seem to get focus when calling the canvas.requestFocusInWindow() method. No events are passed to the listeners that have been added to the JFrame or the GameCanvas on it. The method is called after a āLaunch gameā button is pressed, but the button seems to keep focus. I also tried to change the button to .setFocusable(false), but then focus was just given to another Swing component (a JTextfield).
I thought I could fix this by changing the code so that GameCanvas extends JPanel instead of Canvas, but this causes the following exception:
Exception in thread āmainā javax.media.opengl.GLException: Unable to lock surface
at com.sun.opengl.impl.windows.WindowsOnscreenGLDrawable.lockSurface(WindowsOnscreenGLDrawable.java:170)
at com.sun.opengl.impl.windows.WindowsOnscreenGLContext.makeCurrentImpl(WindowsOnscreenGLContext.java:57)
at com.sun.opengl.impl.GLContextImpl.makeCurrent(GLContextImpl.java:134)
at top.game.renderer.GameCanvas.makeContentCurrent(GameCanvas.java:457)
This is not the case when extended from Canvas.
So, what would be the best way to fix this? Can i fix the code so that the hw component gets focus, or is there a way to extend a JPanel to use with JOGL (similar to the extend Canvas solution, but for GLJPanel)?
The code of the constructor
public class GameCanvas extends Canvas {
...
public GameCanvas(GameWindow top, int width, int height,
GraphicsConfiguration config, GLCapabilities caps,
SpriteFactory store, SpriteBuffer sBuffer, PickingBuffer pBuffer,
Engine2RendererInterface engine){
super(config);
// the usual attributes for a canvas
this.top = top;
panelWidth = width;
panelHeight = height;
// get a rendering surface and a context for this canvas
drawable = GLDrawableFactory.getFactory().getGLDrawable(this, caps, null);
context = drawable.createContext(null);
sStore = store;
this.sBuffer = sBuffer;
this.pBuffer = pBuffer;
this.engine = engine;
inSelectionMode = false;
xCursor = 0;
yCursor = 0;
this.character = null;
this.tile = null;
}
The āmodulesā are not yet fully functional, but i posted them on my page so you could run them.
http://www.cs.tut.fi/~vuori7/Applications/BLGUI/blgui_demo.jnlp
http://www.cs.tut.fi/~vuori7/Applications/BLGAME/blgame_demo.jnlp
The gui launches the whole app, and if you click āhostā, ālaunch defaultā, ālaunchā, it should start the game with one player. But the gamewindow just hangs there.
The game uses a Tester class as the main class, wich populates the game. It runs as itās supposed to.
The program asks for access to the computer, for writing a ā.BloodLetters/config.xmlā file into the users home directory. I can disable this if you do not wish to give it permission.
Any help will be greatly appriciated. If you require any additional information ill be glad to supply it.
āMika Vuoriā