Full of questions lately. Messing around with multiple Graphics contexts, I wrote this:
Code:
public void render(GameContainer container, Graphics gfx)
{
gfx.scale(0.25f, 0.25f);
gfx.setColor(Color.red);
gfx.fillRect(32, 32, 512, 512);
gfx.flush();
Graphics gfx2 = new Graphics(512, 512);
Graphics.setCurrent(gfx2);
gfx2.scale(4f, 4f); //This produces a crash
gfx2.setColor(Color.orange);
gfx2.drawRect(0, 0, 512, 512);
gfx2.fillRect(32, 32, 64, 64);
gfx2.fillRect(512-32, 512-32, 64, 64);
gfx2.flush();
}
and got this:
Code:
Exception in thread "main" org.lwjgl.opengl.OpenGLException: Stack overflow (1283)
at org.lwjgl.opengl.Util.checkGLError(Util.java:54)
at org.lwjgl.opengl.Display.swapBuffers(Display.java:693)
at org.lwjgl.opengl.Display.update(Display.java:712)
at org.newdawn.slick.AppGameContainer.gameLoop(AppGameContainer.java:418)
at org.newdawn.slick.AppGameContainer.start(AppGameContainer.java:318)
at test.GraphicsContext.main(GraphicsContext.java:71)
Why does scaling a second graphics context result in a crash? Also, I'm not completely sure what flush() does -- can anyone explain this to me? setCurrent doesn't seem to do a whole lot either.