Hi,
I’m new to openGL and there are alot of helpful tutorials out there. I have been following the tutorial to create rotating 3D polygon. My question is, how can you use the keyboard to toggle the polygon rotation between different axis during runtime?
I tried to call glRotatef( ) in the keyboard function with different case statements, but that doesn’t seem to work. I might be missing something here.
Suppose the general code is something like this:
void Display (void)
{
glBegin ( GL_Polygon )
//vertices goes here
glEnd();
}
void keyboard ( unsigned char key, int x, int y )
{
switch (key){
case ‘a’:
glRotatef ( 5.0f, 0.0f, 0.0f, 0.1f );
display();
break;
case ‘b’:
glRotatef ( 5.0f, 0.0f, 0.1f, 0.0f );
display();
break;
case ‘c’:
glRotatef ( 5.0f, 0.1f, 0.0f, 0.0f );
display();
break;
}
}
void main ( int argc, char** argv )
{
glutInit();
//other glut window functions goes here
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
glutMainLoop();
}
Any suggestion will be appreciated. Thank You!