CurrentContext

Ok, Here is the effect that Iam after and there may be a much better way to do it, so let me know! I want to pop up a splash screen and have it display all of the loading information then bam the game starts in full screen mode. The trouble I am having is that in LWJGL when I creates the display is automatically pops up the window. I remembered hearing someone talk about hacking together a GL context using Pbuffers so I gave that a shot and lit goes through all of the initialization and everything correctly, and then BAM a full screen window pops us, but there is nothing in the window. I believe this to be due to the fact that the Display is not using the context created using the Pbuffer. How can I load the context into the Display, or am I going about this in a completely wrong way?!

ROCK!!! I got it to work!!

Here’s my set up:
I have a Game class, a SplashScreen class and a Loader class. Upon calling the loader class it creates an instance of the SplashScreen class and passes it to the constructor of the Game class. This allows the game class to update the progress bar and the current task display on the splash screen. The trouble I was having was that when I created the display is stomped out the splash screen and was just black throughout the loading, so what I did was create a Pbuffer to get an OpenGL context and then do all of my initialization on that context (except for gluPerspective, it didn’t like that one so I broke off an initViewport() method that does that stuff and I call it later). Then at the last minute I create the display by passing in a PixelFormat that is the same as the one I used to create the Pbuffer and I pass the Pbuffer in as the “shared drawable.” It took a good couple of hours to get it sorted out(maybe I’m just slow!), but now that I have it seems easy!

Anyway, here is some code so you can see what I mean:

Here is my init() method, notice that the last thing I do is create the display!!!


private void init()
{
	try
	 {
		pbuf = new Pbuffer(1, 1, pix, null, null);
		pbuf.makeCurrent();
	} 
	catch (LWJGLException e1)
	 {
		e1.printStackTrace();
	}
	try
	{
		IL.create();
	}
	catch(LWJGLException e)
	{
		e.printStackTrace();
	}
	initGL();
	loadTextures();
	loadModels();
	createDisplay();
	splashScreen.destroy();
}

Then here I create the display by passing in the PixelFormat that I used to create the Pbuffer and the Pbuffer itself. Then I do the initViewport() stuff and since the Pbuffer has done it’s job I can get rid of it!


try
{
	Display.create(pix, pbuf);
	initViewport();
	pbuf.destroy();
	System.out.println("Created OpenGL.");
}
catch (Exception e)
{
	System.err.println("Failed to create OpenGL due to " + e);
	System.exit(1);
}

I am so happy with how things are going! I am getting this stuff sorted finally! Maybe now I can work on making it pretty! :wink:

As it turns out not all states are shared between shared instances (found this out the hard way while playig with textures) so I had to change my code to look like this:


private void init()
{
	try
	{
		pbuf = new Pbuffer(1, 1, pix, null, null);
		pbuf.makeCurrent();
	}
	catch (LWJGLException e1)
	{
		e1.printStackTrace();
	}
	try
	{
		IL.create();
	}
	catch(LWJGLException e)
	{
		e.printStackTrace();
	}
	loadTextures();
	loadModels();
	createDisplay();
	initGL();
	initViewport()
	splashScreen.destroy();
}