Archived

This topic is now archived and is closed to further replies.

Colossus_1

Why redraw the objects in the scene over and over when moving/rotating them ?

Recommended Posts

Hi, all the examples I have seen have in the main loop routine: glBegin glVertex3f glEnd glTranslate glRotate so my question is: why do I have to redraw the objects each time I have to move/rotate them ? Why don''t place them on the scene ONCE with glBegin/glEnd and then moving/roating without redraw them over and over again ? Colossus Mizio, a proxy scanner hunter tool with GUI for Linux http://mizio.sourceforge.net

Share this post


Link to post
Share on other sites
Unless I''ve completely misunderstood...

How on earth would you see the effect of the rotation or translation without drawing the object on the next frame!?

It''s a bit like a good old "flick book" you see the movement on the NEXT page/frame you can''t see it on the current one ;O)

GCoder

Share this post


Link to post
Share on other sites
quote:
Original post by GCoder
How on earth would you see the effect of the rotation or translation without drawing the object on the next frame!?



Mmm, I didn''t know that it was necessary in OpenGL to draw the object to see the effects of rotation/translation ! When I was used to program with Commodore 64, I moved the sprites by setting the X,Y coordinates not making them again.

Colossus

Mizio, a proxy scanner hunter tool with GUI for Linux
http://mizio.sourceforge.net

Share this post


Link to post
Share on other sites
Colossus, your misunderstanding might come from the fact that OpenGL draws things one frame at a time. Nothing remains from a frame to the following one. So if you want an object to appear at a given time, you have to draw it at that given time.

Victor Nicollet, INT13 game programmer

Share this post


Link to post
Share on other sites
OpenGL is a 3D primitive renderer. It does not contain or manage a scene graph. There are some higher level APIs like OpenInventor that add a scene graph on top of OpenGL.

[edited by - mauman on May 20, 2004 5:08:18 AM]

Share this post


Link to post
Share on other sites
quote:
Original post by Colossus_1
quote:
Original post by GCoder
How on earth would you see the effect of the rotation or translation without drawing the object on the next frame!?



Mmm, I didn''t know that it was necessary in OpenGL to draw the object to see the effects of rotation/translation ! When I was used to program with Commodore 64, I moved the sprites by setting the X,Y coordinates not making them again.

Colossus

Mizio, a proxy scanner hunter tool with GUI for Linux
http://mizio.sourceforge.net


When you are translating rotating what you see in 3D is different each frame because of perspective. Even when you moved your sprites you did erase it and draw it in a different position, in OpenGL it is more complicated because it is 3D, you have to project the new rotated and translated vertices into screen space, and it is done each frame. Of course, in case you don''t rotate or translate you can stop redrawing the screen, just don''t do anything.



"C lets you shoot yourself in the foot rather easily. C++ allows you to reuse the bullet!"

Share this post


Link to post
Share on other sites
But when you programmed the sprites on your C64 you didn''t have to worry about the draw routines because it was handled for you.

Have you had a look at "the red book"? it''s one of the open gl reference manuals, easily locatable on the net through google in pdf format, I recommend it as it''s nice and clear and covers pretty much all you need.

Now then, I''ll assume you understand the concept of screen refresh or screen redraw in that you know the screen is redrawn every nth times a second, common timings being 60, 70, 72 ... 120 Hz.

Well rendering in opengl and any other graphics api for that matter relies on the fact that the entire screen is almost certainly going to be redrawn every frame. A frame being either a single redraw at the current refresh rate, or an arbitrary time depending on the speed of you actual code.

Imagine for second that at the end of all you paint your scene by hand on a canvas. First you start with a blank canvas, then you build up a picture in layers of your scene. When you finish the picture, thats the end of the renderin process, or "end of frame" note : the render can be done at any time but it''s usual to have it at the start or end of the program loop, happening once per frame.

Now if you want an object to appear to move accross your canvas, you''ll have to draw it again. The picture you just painted is already there, it''s permenant and you can''t go back as such, so, first you have to know where it''s going...then draw it in the new position. However, if you just take the old picture, and paint the object in it''s new position, it''ll soon get messy as the object will still appear in it''s previous position.

Th answer is to clear the picture completely before you paint it again. In OpenGL you use the glClear() call with various parameters. Next you redraw the entire scene again, with everything in it''s new position/orientation.

In an application or game, this is done many times a second and often it''s linked to the refresh rate of your monitor, although thats not always the case. So just as a movie shows you something like 24 frames per second (FPS) you''re game or application code will actuall be showing you something like 72 FPS or much higher depending on your hardware.

For reference, consoles such as the PS2 and Gamecube update their scenes at (usually) either 30 FPS or 60. 60 being the norm.

I hope that helps, hope it''s not too convoluted an explanation...someone will do better anyhow ;O)

GCoder

Share this post


Link to post
Share on other sites
quote:
Original post by MaulingMonkey
quote:
Original post by ToohrVyk
Nothing remains from a frame to the following one.


Unless you remove that glClear( GL_COLOR_BUFFER_BIT ); flag.


If you are double buffering you''d only have the frame before last to work with and even then the content of the buffer isnt garented to be useable after a swap.
If you are using single buffering then things will just look terrible anyways.

Share this post


Link to post
Share on other sites