我最近将我的电脑升级到 Windows 10 并安装了 Visual Studio 2015。我尝试在 Visual Studio 2015 中编写一个“Hello OpenGL”程序,该项目成功构建,但它已退出并显示代码 1。我得到的只是创建的窗口很快出现又消失。这是我的代码:
#include <GL\glew.h>
#include <GL\freeglut.h>
#include <iostream>
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowSize(800, 600);
glutInitWindowPosition(100, 100);
glutCreateWindow("Hello OpenGL");
glutMainLoopEvent();
return 0;
}
正如我上面提到的,项目构建成功,这是构建结果:
1>------ Build started: Project: HelloGL, Configuration: Debug Win32 ------
1> main.cpp
1> HelloGL.vcxproj -> D:\OpenGL Projects\HelloGL\Debug\HelloGL.exe
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
但是当我按 F5
调试程序时,结果让我气馁:
The thread 0x23d4 has exited with code 1 (0x1).
The thread 0x20b8 has exited with code 1 (0x1).
The thread 0x10d0 has exited with code 1 (0x1).
The program '[7040] HelloGL.exe' has exited with code 1 (0x1).
最佳答案
首先感谢给我回复的小伙伴们。 我已经知道是什么问题了,我需要做的就是为窗口注册一个回调函数,所以运行代码来了:
#include <GL\glew.h>
#include <GL\freeglut.h>
#include <iostream>
// myDisplay
void myDisplay()
{
glClear(GL_COLOR_BUFFER_BIT); // Clear the screen
glFlush();
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(800, 600);
glutInitWindowPosition(100, 100);
glutCreateWindow("Hello OpenGL");
// Register a callback function for the window's repainting event
glutDisplayFunc(myDisplay);
glutMainLoop();
return 0;
}
关于c++ - OpenGL 程序已在 Visual Studio 2015 中以代码 1 退出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31845764/