Um zu verstehen, wie gluPerspective funktioniert, möchte ich seine Parameter (die erste, die der Winkel ist) dynamisch mit den Pfeilen der Tastatur ändern. Hier ist der Code, den ich bisher habe, aber nichts passiert, wenn der linke oder rechte Pfeil gedrückt wird. Meine Fragen sind - Wie kann ich es zum Laufen bringen und ist es ein Problem, wenn der Matrix-Modus in einer Callback-Funktion eingestellt ist?Parameter von gluperspective dynamisch ändern
double angle = 45;
void renderScene(void) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClearColor(0, 1, 1, 1);
glBegin(GL_TRIANGLES);
glVertex3f(-2, -2, -5.0);
glVertex3f(2, 0.0, -5.0);
glVertex3f(0.0, 2, -5.0);
glEnd();
glutSwapBuffers();
}
void keyboard(int c, int x, int y) {
switch (c) {
case GLUT_KEY_LEFT:
angle -= 15;
break;
case GLUT_KEY_RIGHT:
angle += 15;
break;
}
}
void changeSize(int w, int h) {
// Prevent a divide by zero, when window is too short
// (you cant make a window of zero width).
if (h == 0)
h = 1;
float ratio = 1.0* w/h;
// Use the Projection Matrix
glMatrixMode(GL_PROJECTION);
// Reset Matrix
glLoadIdentity();
// Set the viewport to be the entire window
glViewport(0, 0, w, h);
// Set the correct perspective.
gluPerspective(angle, ratio, 1, 1000);
// Get Back to the Modelview
glMatrixMode(GL_MODELVIEW);
}
int main(int argc, char **argv) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowPosition(200, 300);//optional
glutInitWindowSize(800, 600); //optional
glutCreateWindow("OpenGL First Window");
glutDisplayFunc(renderScene);
glutSpecialFunc(keyboard);
glutReshapeFunc(changeSize);
glutMainLoop();
return 0;
}