OpenGL程序在Visual Studio 2015中以代码1退出
OpenGL program has exited with code 1 in Visual Studio 2015
我最近把我的电脑升级到Windows 10,并安装了Visual Studio 2015。我尝试在Visual Studio 2015中编写"Hello OpenGL"程序,该项目成功构建,但它已退出代码1。我所得到的只是创建的窗口出现和消失得很快。下面是我的代码:
#include <GLglew.h>
#include <GLfreeglut.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 ProjectsHelloGLDebugHelloGL.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 <GLglew.h>
#include <GLfreeglut.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;
}
将glutMainLoopEvent
改为glutMainLoop
后面的glutMainLoopEvent
是一个特定于FreeGLUT的函数,它允许在一个自定义的写循环中放置GLUT事件调度;因此,它必须从循环中调用,并由您决定何时退出程序。
glutMainLoop
实现自己的主循环,并在最后一个窗口关闭时退出程序。
相关文章:
- 创建LinkedList退出,返回代码为-11(SIGSEGV)
- pclose() 不会给我进程退出代码
- C++逗号分隔的输入数组代码过早退出
- Netbeans 10:错误:链接器命令失败,退出代码为 1(使用 -v 查看调用)
- 链接器命令失败,macOS 上的退出代码为 1(使用 -v 查看调用)
- 为什么我的 c++ 代码在使用堆栈时以退出代码 11 结尾?
- 使用常量字符*时退出代码 139
- 你好世界在 APUE 第 7 章退出,代码为 0
- 程序显示以退出代码 0; 结束
- VSCode C++终端进程已终止,退出代码为:1
- Qt5 [make -snap] 无法正确编译:进程"/usr/bin/snap"代码 1 退出
- 错误MSB3073以代码 8 退出
- 在GDB中:在启动程序中以代码1退出.在GDB之外运行良好
- 如何修复使用代码 2 退出"CL.exe"
- Visual Studio 中 Opencv 的介绍性示例程序以代码 -1 退出.不放心
- 我怎样才能删除它?(进程 4652) 以代码 0 退出
- QtCreator:进程 jom.exe 以代码 3 退出
- 错误 MSB6006:"cmd.exe"使用代码退出
- OpenGL程序在Visual Studio 2015中以代码1退出
- 进程qmake.exe以代码2退出-第一次使用Qt和Qt Creator