【发布时间】:2020-01-16 02:18:29
【问题描述】:
我今天刚开始使用 OpenGL,并关注 a tutorial 在 Visual Studio 2010 中设置 OpenGL 项目。 但是当我运行代码时,我得到一个窗口打开得非常快,闪烁和消失。这正常吗?
#include <GL\glew.h>
#include <GL\freeglut.h>
#include <iostream>
using namespace std;
//Window Resized, this function get called "glutReshapedFunc" in main
void changeViewport(int w, int h) {
glViewport(0, 0, w, h);
}
//Here s a function that gets Called time Windows need to the redraw.
//Its the "paint" method for our program, and its setup from the glutDisplayFunc in main
void render() {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glutSwapBuffers();
}
int main(int argc, char** argv) {
//Initialize GLUT
glutInit(&argc, argv);
//Setup some Memory Buffer for our Display
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGBA|GLUT_DEPTH);
//Setup Window Size
glutInitWindowSize(800,600);
//Create Window with Title
glutCreateWindow("GL_HelloWorld");
//Bind two functions (above) respond when necessary
glutReshapeFunc(changeViewport);
glutDisplayFunc(render);
//Very important! this initialize the entry points in the OpenGL driver so we can
//Call all the functions in the API
GLenum err = glewInit();
if (GLEW_OK != err) {
fprintf(stderr, "GLEW error");
return 1;
}
}
【问题讨论】: