PDA

View Full Version : Rotate polygon



03-11-2003, 12:18 PM
Hi, I'm new to learning openGL and have a problem.

I'v drawn a basic polygon and am trying to rotate it (around an axis). It rotates just fine but when it does there are 2 polygons.

There is one polygon which is stable and the other rotates.

I want to know how I can blank out the stationary polygon.......any help with this would be great.


I'm rotating it with the code below: which is in my display method

gl.glPushMatrix();
gl.glRotated(Rot, 0,0,1);
DrawPoly();
gl.glPopMatrix();

Rot++;

and have defined Rot in my Render canvas class

cosmicGirl
03-11-2003, 12:33 PM
you should be using glutPostRedisplay()in your drawScene function. glutPostredisplay reshreshes the screeen each time the scene is drawn.

nexusone
03-11-2003, 12:55 PM
The drawing code looks correct, but are you clearing the matrix and screen each time you draw the the polygon?

void my_loop( void )
{
rot++
Draw_scene()
}

void Draw_scene(void)
{
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //Clear the screen

glMatrixMode (GL_PROJECTION); // Tell opengl that we are doing project matrix work
glLoadIdentity(); // Clear the matrix
glOrtho(-8.0, 8.0, -8.0, 8.0, 0.0, 30.0); // Setup an Ortho view
glMatrixMode(GL_MODELVIEW); // Tell opengl that we are doing model matrix work. (drawing)
glLoadIdentity(); // Clear the model matrix

// Draw Polygon
glPushMatrix()
glRotatef(.....)
Draw_polygon()
glPopMatrix()

// if drawing done flush or if double buffering used
// swap here, else return
}

Are you using opengl under what languge Java, V basic, other?



[This message has been edited by nexusone (edited 03-11-2003).]

03-11-2003, 01:38 PM
I'm using Java,
I'v tried as you'v said but I'm still getting the stationary polygon. I'm a bit unsure about how to refresh the buffers http://www.opengl.org/discussion_boards/ubb/frown.gif

Thanks for your help

03-11-2003, 01:45 PM
Yay it works, i just wasn't calling the method from the right place!!

Thanks very much for your help http://www.opengl.org/discussion_boards/ubb/cool.gif