LWJGL Forum

Programming => Lightweight Java Gaming Library => Topic started by: amoeba on August 24, 2007, 08:56:04

Title: Texture problem after changing resolution
Post by: amoeba on August 24, 2007, 08:56:04
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?
Title: Re: Texture problem after changing resolution
Post by: princec on August 24, 2007, 09:36:26
Broken drivers. Not your fault.

Cas :)
Title: Re: Texture problem after changing resolution
Post by: amoeba on August 24, 2007, 10:04:11
I'll give it a test on my other machine then, thanks.
Title: Re: Texture problem after changing resolution
Post by: amoeba on August 24, 2007, 20:32:51
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?
Title: Re: Texture problem after changing resolution
Post by: elias on August 24, 2007, 21:23:44
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
Title: Re: Texture problem after changing resolution
Post by: amoeba on August 25, 2007, 10:38:03
Even keeping the BPP the same causes the texture corruption problem. Textures are corrupted even if I load them AFTER switching the resolution.
Title: Re: Texture problem after changing resolution
Post by: amoeba on November 07, 2007, 21:33:01
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.
Title: Re: Texture problem after changing resolution
Post by: amoeba on November 07, 2007, 22:01:55
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);
  }
Title: Re: Texture problem after changing resolution
Post by: amoeba on November 07, 2007, 22:31:00
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....?