C++ Windows 8中的过量空闲-重新招标

C++ Windows 8中的过量空闲-重新招标,c++,opengl,freeglut,C++,Opengl,Freeglut,我正在使用freeglut、windows 8、vs2012和最新的nvidia驱动程序。但是过量空闲函数有一个奇怪的行为。在我调整窗口大小或单击窗口之前,它不会执行任何操作 或者,glut不想重新启动屏幕,即使某些变量发生了变化 #include <iostream> #include <stdlib.h> #include <GL/glut.h> using namespace std; GLfloat rotateQuad = 0; void

我正在使用freeglut、windows 8、vs2012和最新的nvidia驱动程序。但是过量空闲函数有一个奇怪的行为。在我调整窗口大小或单击窗口之前,它不会执行任何操作

或者,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;

}
#包括
#包括
#包括
使用名称空间std;
GLfloat rotateQuad=0;
void initRendering(){
glEnable(GLU深度试验);
}
//调整窗口大小时调用
空心把手尺寸(内宽内高){
//告诉OpenGL如何将坐标转换为像素值
glViewport(0,0,w,h);
}
//绘制三维场景
void drawsecene(){
//清除上次绘制的信息
glClear(GL_颜色_缓冲_位| GL_深度_缓冲_位);
glMatrixMode(GL_MODELVIEW);//切换到绘图透视图
glLoadIdentity();//重置图形透视图
glRotatef(rotateQuad,0,0,1);
glBegin(GL_四边形);//开始四边形坐标
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();//端部四边形坐标
glutSwapBuffers();//将3D场景发送到屏幕
}
无效空闲(){
rotateQuad+=1;
如果(rotateQuad>360)rotateQuad=0;
}
int main(int argc,字符**argv){
//初始化过剩
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_双精度| GLUT_RGB | GLUT_深度);
GLUTINITWindowsSize(400400);//设置窗口大小
//创建窗口
创建窗口(“四边形旋转”);
initRendering();//初始化呈现
glutIdleFunc(空闲);
glutDisplayFunc(绘图场景);
GLUTEFUNC(handleResize);
glutMainLoop();//启动主循环
返回0;
}

你知道哪里出了问题吗?

你的
空闲功能只是更新旋转;它实际上并没有要求GLUT重新绘制,所以在其他东西触发它(例如窗口交互或调整大小)之前,不会进行重新绘制。在空闲函数中调用
glutPostRedisplay
。请参阅:

您的
idle
功能只是更新旋转;它实际上并没有要求GLUT重新绘制,所以在其他东西触发它(例如窗口交互或调整大小)之前,不会进行重新绘制。在空闲函数中调用
glutPostRedisplay
。见: