Advertisement

Question About Initialization

Started by May 25, 2002 08:53 PM
9 comments, last by David91999 22 years, 9 months ago
How do I initialize an OpenGL window with a drawing already on it? That is, I want to be able to draw "moving" objects without having to redraw the unmoving objects over and over.
You''re asking how to not have to redraw everything every frame?

[twitter]warrenm[/twitter]

Advertisement
I''m not sure whether that''s possible. Just thinking about it, if you put an object over a background, it blocks off all the necessary pixels in the background according. But if you move the object, how will those pixels know what to go back too? You''d need to resend the information about the picture, you''d have to redraw it.
_______________________________________Pixelante Game Studios - Fowl Language
I think I need to reword the question. I have some objects on the screen that are supposed to "move". This means that they must be redrawn over and over, and each time they are redrawn, they are shifted over a little bit, making it look like they''re moving. In addition to these "moving" objects, I also have some unmoving objects on the screen. My program would run much more quickly if I didn''t have to redraw the unmoving objects every time I redraw the "moving" objects. Is there any way to do this? I was thinking that maybe I could have the unmoving objects drawn once when the window is originally initialized, and then stay on the window without being redrawn?
It''s not possible if you''re using double-buffering, since the back buffer is discarded each time you "flip" (sometimes it''s not, but it''s not a good idea to assume that it''s still available).

Besides, it''s not usually worth the trouble. Especially when you have multiple "moving" objects.

Basically you need to draw the background, then when you draw a "moving" object, it needs to read what''s under it so that it can put it back again. So, each frame, for each object, you draw the background over the object, thus erasing it, then save the background in the object''s new position, and draw the object.

But think about what would happen is two objects collided. Would the second object to be drawn have bits of the first one in it''s view of the "background"?


codeka.com - Just click it.
If drawing background is expensive, do it once and save the results either in a GDI bitmap or in a GL texture. If you''re using GL for rendering moving objects, it will be much faster to not call anything GDI while GL is rendering.
---visit #directxdev on afternet <- not just for directx, despite the name
Advertisement
Here''s a simple way of asking the question. I have a 2-D program in which a mouse, which moves when the user presses the keyboard arrows, is guided through a maze. Is there any way to have the mouse move through the maze without ever having to redraw the maze?
No.

But, in 2-D, you can do partial screen updates. You mark part of the screen as dirty and only redraw that part.

As the mouse moves around the screen, it will need to be redrawn and any place it has been will also need to be redrawn. The rest of the screen can be left as is. What you will need to do however is load your initial bitmap into both the primary and secondary(back buffer) surfaces. Then only redraw the appropriate parts.

I do not think this is possible in OpenGL.

---
Make it work.
Make it fast.

"Commmmpuuuuterrrr.." --Scotty Star Trek IV:The Voyage Home
"None of us learn in a vacuum; we all stand on the shoulders of giants such as Wirth and Knuth and thousands of others. Lend your shoulders to building the future!" - Michael Abrash[JavaGaming.org][The Java Tutorial][Slick][LWJGL][LWJGL Tutorials for NeHe][LWJGL Wiki][jMonkey Engine]
quote:
Original post by CaptainJester
No.


Well, you can get the bitmap data where you''re about to draw the mouse, save that data elsewhere, and when the mouse moves, first blit the saved data over the mouse to restore the maze and then repeat saving and drawing in the new position.

However, reading from video memory is very slow, and should be avoided at all costs. If you''re using GDI, this algorithm may be even faster than drawing the entire maze, but in GL it will kill performance.

Just save the maze image and render it as background in each frame.
---visit #directxdev on afternet <- not just for directx, despite the name
OK, so how do I "save the maze image and render it as background in each frame"?

This topic is closed to new replies.

Advertisement