PDA

View Full Version : animation problem



vhn2000
02-20-2005, 08:38 PM
I got a program which will redraw the scence, so basically what I have on the screen will be erased and updated with the current screen. Is there a way where I only can erase part of the screen?
My application contains some moving figures, so the screen redraws everytiem the user clicks. But there are part of the screen which I need to stay the same and probably updated as the user clicks.


void display(void)
{

glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();
glTranslated(0,-30,0);
glBegin(GL_LINE_LOOP);
for (int i=0; i < 360; i++)
{
float degInRad = i*DEG2RAD;
glVertex2f(cos(degInRad)*3,sin(degInRad)*3);
}
glEnd();

//glTranslated(0,30,0);

glColor3f(1,1,1);
glRotated(spin,0,0,1);
glTranslated(0,15,0);

glBegin(GL_LINE_LOOP);
for (int i=0; i < 360; i++)
{
float degInRad = i*DEG2RAD;
glVertex2f(cos(degInRad)*3,sin(degInRad)*15);
}
glEnd();
glTranslated(0,13.5,0);
glRotated(alpha1,0,0,1);
glTranslated(0,10,0);
glBegin(GL_LINE_LOOP);
for (int i=0; i < 360; i++)
{
float degInRad = i*DEG2RAD;
glVertex2f(cos(degInRad)*3,sin(degInRad)*10);
}
glEnd();
glPopMatrix();


glutSwapBuffers();
}

dvm
02-21-2005, 04:23 AM
No, you can't just update some part of the screen. Since you're using a 3D "world" you update the world. If you need something to stay on screen, I'd suggest creating an obect that will hold the coordinates and draws itself (something like Object.draw() ;) You could have a boolean variable to test if the object needs to be drawn or not.

vhn2000
02-21-2005, 03:46 PM
How can I get the current system coordinate so that the next time I enter the draw function, I can draw it where it were supposed to be.

Overmind
02-22-2005, 01:23 AM
You should know that yourself. After all, you have drawn it the first time. Whatever coordinates it was drawn at the first time, just store them somewhere and use them when drawing the second time...

Omaha
02-22-2005, 05:44 AM
Are we talking about the same OpenGL here? Yes, yes you can just update part of the screen. Read about the scissor test. You could even go as far as to change your viewport, but that would require some matrix shenanigans. The point is, YES there IS a way to do it.

Then you can draw your scene, change your scissor rectangle to your dirty rectangle, and rerender that part. Depending on your setup though, you might be very likely to lose the speedup you're trying to gain by redrawing a smaller part of the screen with the added logic of the test, even though the scissor test is pretty trivial. So who knows, you might be sitting pretty.

But yes, it _is_ possible.