dul*_*ulq 7 c++ opengl visual-studio-2015
我最近将我的电脑升级到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;
}
Run Code Online (Sandbox Code Playgroud)
正如我上面提到的,项目成功构建,这是建筑物重建:
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 ==========
Run Code Online (Sandbox Code Playgroud)
但是当我按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).
Run Code Online (Sandbox Code Playgroud)
首先,感谢那些给我回复的人.我已经弄清楚问题是什么,我需要做的就是为窗口注册一个回调函数,所以这里出现了正在运行的代码:
#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;
}
Run Code Online (Sandbox Code Playgroud)
调用glutMainLoop而不是glutMainLoopEvent.
后者glutMainLoopEvent是 FreeGLUT 特定函数,允许将 GLUT 事件调度放置在自定义编写的循环中;因此,必须从循环内调用它,并由您决定何时退出程序。
glutMainLoop实现自己的主循环,并在最后一个窗口关闭时退出程序。
| 归档时间: |
|
| 查看次数: |
3204 次 |
| 最近记录: |