Hi, I’m new to JOGL. I have drawn a map that I want to use as a background(will change from user input, handled already). I want to draw shapes over top of it that will move and be added/removed. How would I do this?
Let me be a bit more specific. I want to add/remove the shapes without having to redraw everything. Can I draw on different layers? I looked into the depth buffer but couldn’t find anything specific enough. Can anyone help?
Heh. It’s OpenGL. Redrawing everything all the time is the usual way to do it, because it’s usually necessary anyways and because dirty rectangles just doesn’t work if page flipping is used.
So what you have to do is disabling the depth buffer and each frame:
-do the logic
-clear the buffer (IF you don’t cover everything anyways)
-draw the background
-draw the sprites
-draw the hud
-repeat
It’s easy and it’s also damn fast. Really.
If you can play nice first person shooters… your graphics card will just laught at that little stuff it has to draw.
Maybe I’m going about things all wrong. It draws fast but still takes about 2 seconds to draw the entire map. The map data is being read from the hard drive everytime it is drawn. Reason being that there is about 1 Gig of map data. Is there a specific data structure that works better for openGL. Sorry if these seem like stupid questions. I also am going to have about 500 boxes that will have to move at any given time. The boxes represent vehicles that may be updated at any given time so anytime one moves the refresh rate would have to be lightening fast. I’d rather not see a flicker. Any help is appreciated.
You can render the map to a texture (using a pbuffer) and reuse that texture for each frame. Drawing a single full screen texture is virtually instantanious.
ps:
You can read 1 gig of map data from harddrive in 2 seconds!? Where do You buy computers?
If your background changes when the user(player) moves, it should be called a terrain i think.
With a huge quantity of data, you will have to make use some algorithm to reduce the number of polygons drawn. Then you should be able to put them into a VBO and draw it fast!
Is there a way to remember an area of screen, draw a box, and redraw the remembered area when the box moves?
Yes, you can do it. Draw in a pBuffer, and then copy it as a texture. You can apply the texture to a moving object next.
Shouldn’t I be able to use repaint(x, y, widht, height)? Everytime I try using repaint it redraws the entire screen. Any way to make it just redraw that rectangle?