Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenGL program has exited with code 1 in Visual Studio 2015

I recently upgraded my pc to Windows 10 and installed Visual Studio 2015. I try to write a "Hello OpenGL" program in Visual Studio 2015, the project gets built successfully, but it has exited with code 1. All I get is that the created window appeared and disappeared very soon. Here goes my code:

#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;
}

As I mentioned above, the project gets built successfully, here is the building reuslt:

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 ==========

But when I press F5 to debug the program, it discouraged me with the result:

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).
like image 925
dulq Avatar asked Aug 06 '15 02:08

dulq


1 Answers

First of all, thanks to the guys who gave me a reply. I've figured out what is the problem, All I need to do is to register a callback function for the window, so here comes the running code:

#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;
}
like image 81
dulq Avatar answered Sep 23 '22 01:09

dulq