How to persist embedding game in LWJGL applet frame?

Started by gjtorikian, October 27, 2010, 15:29:07

Previous topic - Next topic

gjtorikian

I'm in the process of adapting a currently executable JAR game file into an applet, as a lesson in creating LWJGL applets.

Right now, everything works as it should, locally. I can launch my HTML page, the LWJGL bootloader starts up, and my game launches. Unfortunately, what ends up happening is that the game launches in a separate Java window, as though I had simply double clicked the jar in the first place. The HTML page stays an unimpressive default white.

The last message the LWJGL bootloader says is "switching applet." I'm assuming at that point it is giving control over to the game. The game makes use of

Display.setLocation(windowX, windowY);

Before continuing to set up the UI and whatnot.

My question is, how can I continue to play the game whilst embedded in the LWJGL applet frame?

kappa


gjtorikian

Thanks very much :) After looking at the GearsApplet.java source I was better able to manage a solution.

Last question (I hope): is there a way to dynamically recreate the Canvas size? I suppose not...I get a crash when setting org.lwjgl.opengl.GL11.glViewport() with a new width and height.

I would guess for this to be possible the applet would have to manipulate the HTML DOM, an area I am totally unfamiliar with.

kappa

don't think you can change the applet size once you set the values as pixels in the applet tag like

<applet codebase="." code="MyClass.class" width="640" height="75">

but if you set it as percentage like

<applet codebase="." code="MyClass.class" width="100%" height="100%">

it will resize according to the html container the applet is in, so you could for example put the applet in a <div> and just resize it to also get the applet to resize.

bobjob

Quote from: gjtorikian on November 02, 2010, 23:44:04
Last question (I hope): is there a way to dynamically recreate the Canvas size? I suppose not...I get a crash when setting org.lwjgl.opengl.GL11.glViewport() with a new width and height.
I got the same bug with older drivers on my Nvidia card. The problem is that glViewport() will still need to be called regardless.
the crash happens on the call to Display.update().

I was tossing up the idea of creating a new canvas to place in the container, set the new canvas as perant and removing the old one, then after validating the container call glViewport() with the containers dimensions.But I havnt tested this as the crash hasnt happend since i installed the new Nvidia drivers.

gjtorikian

Quote from: bobjob on November 03, 2010, 10:34:24
Quote from: gjtorikian on November 02, 2010, 23:44:04
Last question (I hope): is there a way to dynamically recreate the Canvas size? I suppose not...I get a crash when setting org.lwjgl.opengl.GL11.glViewport() with a new width and height.
I was tossing up the idea of creating a new canvas to place in the container, set the new canvas as perant and removing the old one, then after validating the container call glViewport() with the containers dimensions.But I havnt tested this as the crash hasnt happend since i installed the new Nvidia drivers.

I'll try this and see what I get.