c++ - OpenGL 程序已在 Visual Studio 2015 中以代码 1 退出

标签 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;
}

正如我上面提到的,项目构建成功,这是构建结果:

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/

相关文章:

c - 在 Visual Studio 中用 C 初始化结构内部的数组

c++ - 正在分配指针的测试类析构函数?

c++ - 基于物理的渲染结果看起来不正确

c++ - 将 Freetype 字形渲染到 OpenGL (3.3+) 纹理会导致重复纹理和伪影

node.js - Visual Studio 2015 - Node.js 的多个实例

visual-studio - Visual Studio 2015 完全离线分发

c++ - LOBYTE(nValue) 和 LOBYTE(LOWORD(nValue)) 区别?

c++ - 条件赋值

c++ - 使用运算符重载添加分数

在没有 XCode 的情况下使用 CGL/NSOpenGL 在 OSX 上使用 OpenGL 的 C++ 代码?