Change to Cartesian Coordinates: possible in Java2D or switch to OGL ?

Hello Programmers!

I am going to run tutorials for school kids about “how to make a computer game” - Woo hoo! By getting the kids to add extra units, maps, weapons etc to my existing skeleton 2D game my job is enthuse school kids about maths - coordinate geometry, trigonomentry, etc :-. To make it simple for them the games’ coordinate space needs to be their familiar cartersian coordinate system of positive Y going up and positive X going right.

Unfortunately for me Java2D has an inverted Y-axis with the origin in the top-left of the screen, not the bottom left. I know how to change the coordinate space in theory:

Graphics2D g = //get it somewhere
g.translate(0, 600); //for 800x600
g.scale(1.0, -1.0); //flip around the x-axis so +y is up
//all drawing goes after above transforms

(Courtesy of CaptainJester, http://www.java-gaming.org/forums/index.php?topic=12348.0)

but how can I do the necessary scale(1, -1) while still keeping hardware acceleration?

Currently my game runs at ~40 FPS, but with the above transforms the FPS drops to 1 :’(. This is due to the loss of acceleration when painting my VolatileImage unit sprites to the VolatileImage back-buffer.

What is strange is that non-negative scale operations (such as scale(0.6, 0.6) ) work fine but scale(1, -1) causes the problems.

Q1. Is it impossible to invert the y-axis and keep acceleration with Java2D?

Q2. Can you easily invert the y-axis with JOGL or LWJGL and should I switch to one of these, considering their complexity?

Cheers,
Keith

For what you are trying to accomplish, you can stick the simpler parts of OpenGL. You don’t need to dig into shaders or any advanced stuff. Just stick to polygons and textures. May display lists or VBOs as well. You can set up OpenGl in Ortho mode, which produces an orthgraphic projection instead of a perspective one. This will allow you to easily do a 2D game.

Head on over to http://nehe.gamedev.net/ for tutorials on OpenGL. Tutorial 21 specifically deals with Ortho mode. I would suggest doing them all up to there. Each one builds on the previous lesson. Also the source code has been translated into JOGL and LWJGL, so you can take your pick. (Note: go to bottom of each tutorial page for source code)

Will do.

It’s a pity that Java2D can’t do it, but I suppose JOGL is the way to go for games anyway. Since Sun is backing JOGL i’m inclined to choose that over LWJGL -> good idea or not?

Many thanks Captain,

Keith