I am trying to create a polygon and translate/rotate it when the mouse button is released.
I am able to do this if I redraw my whole polygon again by using glBegin and glEnd but I am not sure if I really need this as I have already drawn the polygon on the screen once and just want to use the same object and apply rotation/translation to it.
I am putting a snippet below.
if(state == GLUT_UP){
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();
glRotatef(90,0,0,1);
// glTranslatef(50,-50,0);
/*
glBegin(GL_POLYGON);
glVertex2i (-40,40) ; //Specify li ne - se gme nt ge ometry .
glVertex2i (-30 , -40) ;
glVertex2i (0 , 20) ;
glVertex2i (40 , 35) ;
glEnd() ;
*/
glClear(GL_COLOR_BUFFER_BIT);
glPopMatrix();
glutSwapBuffers();
// glutPostRedisplay();
}
Please speak with me: "I'll never put OpenGL drawing calls into event handlers again!"
In a event handler you set some variable according to the event, then issue a redrawing call and in the rendering function you draw according to the content of the variables.
Also OpenGL does not "rememer" what you draw. You send drawing commands, OpenGL does its deed and then forgets about it. The only trace left are the fragments turned to pixels on the framebuffer. But the framebuffer contents are not affected by transformation or any OpenGL state changes. Only drawing affects the framebuffer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With