I am trying to get resolution switching working;
private void createWindow(int w, int h, int bpp) throws Exception
{
Display.destroy();
Display.setFullscreen(fullscreen);
DisplayMode d[] = Display.getAvailableDisplayModes();
for (int i = 0; i < d.length; i++)
{
if (d[i].getWidth() == w
&& d[i].getHeight() == h
&& d[i].getBitsPerPixel() == bpp)
{
displayMode = d[i];
break;
}
}
Display.setDisplayMode(displayMode);
Display.setTitle(windowTitle);
//Display.create();
Display.create( new PixelFormat(32, 0, 24, 8, 0) ); // 32 bit colour, 24 bit depth, 8 bit stencil
Display.setVSyncEnabled(true);
}
, but when I change resolution the textures seem to be messed up. Does anyone have some example code, or can point out my mistake please?
Broken drivers. Not your fault.
Cas :)
I'll give it a test on my other machine then, thanks.
Tested on my other machine, and it does the same thing. 2 completely different machines/gfx cards - so I think maybe it is the code?
You can't change the bitdepth without corruption with most windows drivers, afaik. You can only (semi)-safely change the size and refresh rate of the display. If you need to change the bpp, do a complete Display.destroy()/Display.create() cycle (which means reloading GL state, like textures and display lists).
- elias
Even keeping the BPP the same causes the texture corruption problem. Textures are corrupted even if I load them AFTER switching the resolution.
I still cant get resolution change working, could anyone give me a copy of their display creation code please?
When I change resolution I seem to lose textures.
Thanks to MatthiasM on IRC for helping me with this. The fix is to use a Pbuffer to store the Drawable and then reuse when the Display is re-created;
private void createWindow(int w, int h, int bpp) throws Exception
{
Pbuffer pbuf = new Pbuffer( w, h, new PixelFormat(bpp, 0, 24, 8, 0), Display.getDrawable());
Display.destroy();
DisplayMode d[] = Display.getAvailableDisplayModes();
for (int i = 0; i < d.length; i++)
{
if (d.getWidth() == w && d.getHeight() == h && d.getBitsPerPixel() == bpp)
{
displayMode = d;
break;
}
}
int width = Display.getDisplayMode().getWidth();
Display.setDisplayMode(displayMode);
Display.setFullscreen(FULLSCREEN);
Display.setTitle(TITLE);
Display.create(new PixelFormat(bpp, 0, 24, 8, 0), pbuf);
Display.setVSyncEnabled(true);
Display.setLocation((width - displayMode.getWidth()) / 2, 0);
}
Not sure if the pbuffer pixelformat should be the current displays pixelformat, or the new one.
Using the new pixelformat gives a invalid pixelformat error, whereas using;
Pbuffer pbuf = new Pbuffer( w, h, new PixelFormat(Display.getDisplayMode().getBitsPerPixel(), 0, 24, 8, 0), Display.getDrawable());
, seems to work but I'm not sure if this causes a problem with the textures being in the wrong colour depth....?