open gl animation question
hi,
this is my first major exercise in open gl, so be gentle. i''m writing a program to produce solutions for the rubik''s cube. i just started, so now i''m writing the gui in none other than...open gl. i used nehe''s lesson 5 as a basecode and modified accordingly.
i have a cube class with two of its member functions being:
cube.Twist() and cube.RenderCube(). cube.Twist draws the cube animation being twisted on either the top, bottom, front, back, left, or right face. cube.RenderCube() just draws the cube in whatever the current state is.
my problem may arise from a lack of understanding of animation in open gl. but anyway, the problem is that i can''t seem to draw the cube being twisted, and then draw the cube in its current state. if i have one Twist function in DrawGLScene followed by one RenderCube function right after that, it draws both at the same time. I realize that''s because DrawGLScene loops until the escape key is hit. so i threw in a boolean variable to check when the twisting animation is done so i can just do that once, and then just render the cube in its current state for the duration of the program. problem is that with that variable intact, the twisting animation seems to go too fast for the program, and it''ll just sit in the renderscene() loop. i know it gets to the twist function, it hits the breakpoint.
it just seems that the speed of animation is extremely different if the if(boolean) check is located there.
would anyone know how to slow the twisting animation down or what the issue is? the drawgl function is below
int DrawGLScene(GLvoid)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(0.0f,0.0f,-20.0f);
glRotatef(45.0, 1.0f, 1.0f, 1.0f );
glBegin(GL_LINES);
glVertex3f(0.0f, 0.0f, 0.0f);
glVertex3f(0.0f, 15.0f, 0.0f);
glVertex3f(0.0f, 0.0f, 0.0f);
glVertex3f(15.0f, 0.0f, 0.0f);
glVertex3f(0.0f, 0.0f, 0.0f);
glVertex3f(0.0f, 0.0f, 15.0f);
glEnd();
if( permutations_waiting){
cube.Twist( BOTTOM, CLOCKWISE );
permutations_waiting = FALSE;
} else {
cube.RenderCube();
}
return TRUE;
}
your rendering everything to a single frame {see the WinMain funtcion where you call the Draw method}, that is why you only get the final output, try inserting glFlush() in the twist method or re-work your code so it adjusts the cube once every time the draw function is called.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement