Skip to main content
GameDev.net gamedev.net
🔒 Locked

Sphere movement

Started by Chuffy_345 Mar 10, 2004 at 8:05 AM 5 replies 600+ views
Original Post
Chuffy_345
Chuffy_345
Hi guys I’ve got a translation problem in my OpenGL code(programming in windows). Basically I’ve created a sphere in a method called renderScene doing the usual pushMatrix create sphere object translate create sphere pop matrix. In another method called move which is called on a key stoke I’ve setup a while loop which for example is from 0.0001 to 1 do with an increment of 0.0001. After each pass I want to translate my sphere by these small increases. The problem is I can’t just update the x,y,z co-ordinates I used in the glTranslate because I have to call renderScene to make this happen. The problem with calling renderScene is that it will create a new sphere on top of the current sphere(snake effect), where as I want to just move the old sphere. What I really need is to be able to get a handle on my sphere object which will then allow me to call glTranslate from my move method. The problem is I don’t know if you can or how to get a handle on a sphere object. It’s hard to explain the problem so if anything’s not clear let me know. Cheers and I hope someone can help.
ACAC
ACAC
I think i know what you mean, You need to clear the back buffer, previous frames arent being cleared so your getting the snake effect.

I believe this is what you have to call, before you render your scene.

glClear(GL_COLOR_BUFFER_BIT);

( altho im not an ogl coder =) )

Regards
Ash.
Chuffy_345
Chuffy_345
This is what i originally tried but because there are lots of translations going on i get this really bad flicker effect. Anyway of stopping this?

rileyriley
rileyriley
You need to turn on "double buffering" - I''m not sure how to do it in OpenGL off of the top of my head, but google or the forum search button should know~

HTH,
Riley
--Riley
dmikesell
dmikesell
Do this before you draw each frame:

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

And when you create your PIXELFORMATDESCRIPTOR structure used in choosing and setting a pixel format, the 3rd parm needs to be something like this:

PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER

--
Dave Mikesell Software
bzroom
bzroom
How are you creating your window? If in glut then its just a parameter u pass in when u create the window. If your creating it with the win32 there is a pixel format i think it is. It has flags for stencil butters double buffering depth buffers, this is where u set that up at.

Then you clear your scene as already said, this clears the "back" buffer, or buffer 2, currently the screen is drawing buffer 1, u draw your scene into buffer 2 and call swap (again, another win32 code or in glut its automatic. This tells the screen to draw buffer 2 and your back buffer to switch to buffer 1, so u can clear and draw on it.

I hope i didnt over go into detail if you already figured out wut your doing.
Chuffy_345
Chuffy_345
Thats great guys, thanks a lot!! :-))

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.