how to rotate a single triangle that drawn on the screen managed to rotate everything on the screen. the code below rotates all the drawings i just want to rotate one drawing.
void SpecialKeys(int key, int x, int y)
{
if(key == GLUT_KEY_UP)
glRotatef(10,0.0,0.0,1.0);
if(key == GLUT_KEY_DOWN)
glRotatef(10,0.0,0.0,-1.0);
// Refresh the Window
glutPostRedisplay();
}
In the input handler set variables, apply transformations in the drawing function.
OpenGL is not a scene graph. This means that you’re not building some scene representation in OpenGL, that you could alter later. OpenGL is a drawing API. It gives you the digital equivalent of pencils, brushes, collages to draw on a canvas provided by the operating system.
This also means, that when you change something in the scene, you redraw the things from scratch.
Due to this working of OpenGL is makes no sense to do matrix manipulations, or actually any kind of OpenGL operation at all in a input event handler. It simply doesn’t work that way.
Update
Minimal GLUT user interaction code sample (OpenGL-1.1):
On Github