Slick Forums

TWL Integration Issue Using Image.getGraphics()
Page 1 of 1

Author:  Tebriel [ Fri Jan 13, 2012 12:22 am ]
Post subject:  TWL Integration Issue Using Image.getGraphics()

Matthias and I have been trying to track down what seems to be a bug in the thread posted below. I'm hoping somebody can help take a look and maybe help figure out what's going on.

"...somehow getGraphics() leaves a wrong GL_VIEWPORT size active at the time the LWJGLRenderer is syncing it's display size (eg at creation time, can manually sync later - eg for resizing support)."


Author:  davedes [ Sat May 12, 2012 9:20 pm ]
Post subject:  Re: TWL Integration Issue Using Image.getGraphics()

Image.getGraphics() will bind an FBO, i.e. glViewport will be set to that FBO's size. You need to call flush() after calling getGraphics to ensure that the FBO is no longer bound, and that the viewport is reset to the screen's dimensions. That should probably fix your problems with TWL.

In my opinion, getGraphics should ideally just return a value without binding any FBOs. However, because of the way Slick uses FBOs and multiple graphics contexts, this would mean you'd need to do the following:
g = img.getGraphics();
Graphics.setCurrent(g); //<-- needed to ensure the following line works
myImg.draw(0, 0); //<-- because we aren't using Graphics.drawImage, there is no predraw/postdraw
g.flush(); //<-- flushes/unbinds the FBO

In other words, a proper fix would lead to a lot of errors. Hopefully when it comes time to a significant Slick refactoring (if that ever happens), we can resolve this so that getGraphics isn't so ugly. :)

Author:  kylearan [ Wed Dec 12, 2012 3:27 pm ]
Post subject:  Re: TWL Integration Issue Using Image.getGraphics()


I have encountered a similar problem (or I guess it's the same problem in a different guise). TWL rendering breaks after calling Image.createOffscreenImage(); for more details look here: (I found this thread only afterwards.)

Calling getGraphics().flush() afterwards indeed solves the problem. I just report this so that others with similar problems can see this.

Since I have no idea how OpenGL works exactly (that's why I decided to use Slick and TWL in the first place), I can only hope that this won't have any side effects. Or will calling getGraphics() after the createOffscreenImage lead to memory leaks again?


Author:  davedes [ Wed Dec 12, 2012 8:30 pm ]
Post subject:  Re: TWL Integration Issue Using Image.getGraphics()

createOffscreenImage will not lead to a leak; you can then call getGraphics without any extra textures being allocated.

flush() is necessary after you're done with the offscreen image, regardless of whether you are using TWL. :)

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group