我正在使用 freeglut、windows 8、vs2012 和最新的 nvidia 驱动程序。但是 glut idle 函数有一个奇怪的行为。在我调整窗口大小或单击窗口之前,它什么也不做。
或者不知何故 glut 不想重新渲染屏幕,即使某些变量已经改变。
#include <iostream>
#include <stdlib.h>
#include <GL/glut.h>
using namespace std;
GLfloat rotateQuad = 0;
void initRendering() {
glEnable(GL_DEPTH_TEST);
}
//Called when the window is resized
void handleResize(int w, int h) {
//Tell OpenGL how to convert from coordinates to pixel values
glViewport(0, 0, w, h);
}
//Draws the 3D scene
void drawScene() {
//Clear information from last draw
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW); //Switch to the drawing perspective
glLoadIdentity(); //Reset the drawing perspective
glRotatef(rotateQuad,0,0,1);
glBegin(GL_QUADS); //Begin quadrilateral coordinates
glVertex3f(-0.5f, -0.5f, 0.0f);
glVertex3f(0.5f, -0.5f, 0.0f);
glVertex3f(0.5f, 0.5f, 0.0f);
glVertex3f(-0.5f, 0.5f, 0.0f);
glEnd(); //End quadrilateral coordinates
glutSwapBuffers(); //Send the 3D scene to the screen
}
void idle(){
rotateQuad+=1;
if(rotateQuad > 360) rotateQuad=0;
}
int main(int argc, char** argv) {
//Initialize GLUT
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(400, 400); //Set the window size
//Create the window
glutCreateWindow("Quad Rotate");
initRendering(); //Initialize rendering
glutIdleFunc(idle);
glutDisplayFunc(drawScene);
glutReshapeFunc(handleResize);
glutMainLoop(); //Start the main loop
return 0;
}
任何想法出了什么问题?