I am writing a clean tetris implementation. I was rendering in SWT, but I ran into some bugs that the developers don’t plan on fixing, so I moved to LWGL/openGL/SWT. I’m only using SWT for window widgets.
When I was working with SWT (works very similiarly to Java2D) I loaded up all my images, and just told SWT where on the screen to render them.
My program is pretty modularized, keeping seperate logic seperate, so I was able to gut out all the SWT rendering code with no impact on the rest of the game.
Through reading tutorials I’ve set openGL to render in 2d (by removing depth perspective), and I’ve set up the viewport so it “looks” just like a Java2d screen. The origin is in the top left, glvertexi(2, 10) will set a vertex at pixel(2, 10).
The problem I’m having is trying to figure out how to communicate between this game framework and opengl. Essentially I’ve got a bunch of X, Y coordinates of where to render images, but I don’t know the best way to do that. Should I be treating these images as sprites? The only image that really qualifies as a sprite (meaning it moves often) is the currently falling piece. Everything else is pretty static.
Essentially, I’ve built up a bunch of paint() and repaint() functions to render my game, but I don’t know how to translate these to OpenGL. The rendering loop and the game timer loop were the same entity in my SWT implementation, but I’m discovering that with OpenGL I want to keep the two seperate. I’ve got that done logically, but there’s no rendering going on right now.
Here are the two options I’m kicking around. Since I’m not very familiar with OpenGL, I can’t decide which is “better”.
-
Have an Image that represents how the screen currently looks. Work essentially the same behind the scenes. Keep drawing to a bufferImage and swapping it for image when appropriate, and giving my opengl rendering code access to that image, and just haveing it draw that image over and over every loop.
-
Treat everything as sprites, render it that way some how.
I would prefer the first method because it doesn’t require too much changing to my code. I just need to change all my paint functions, make them paint to a defined image’s Graphics object instead of to the Graphics object provided by SWT. My concern is that this won’t be very fast – I’m worried the translation from whatever Image class I am working with to something OpenGL understands would be costly, too costly for 60 times a second.
Any Ideas?
