Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
file 98 lines (76 sloc) 1.95 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
/* OpenGL example code - Skeleton
*
* Skeleton code that all the other examples are based on
*
* Autor: Jakob Progsch
*/
 
/* index
* line 34: glfw initialization
* line 56: glew initialization
* line 68: main loop
* line 92: cleanup
*/

#include <GL3/gl3w.h>
#include <GL/glfw.h>

#include <iostream>

bool running;

// window close callback function
int closedWindow()
{
    running = false;
    return GL_TRUE;
}

int main()
{
    int width = 640;
    int height = 480;
    
    if(glfwInit() == GL_FALSE)
    {
        std::cerr << "failed to init GLFW" << std::endl;
        return 1;
    }

    // select opengl version
    glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
    glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3);
    glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 3);
 
    // create a window
    if(glfwOpenWindow(width, height, 0, 0, 0, 8, 24, 8, GLFW_WINDOW) == GL_FALSE)
    {
        std::cerr << "failed to open window" << std::endl;
        glfwTerminate();
        return 1;
    }
    
    // setup windows close callback
    glfwSetWindowCloseCallback(closedWindow);

    
    
    if (gl3wInit())
    {
        std::cerr << "failed to init GL3W" << std::endl;
        glfwCloseWindow();
        glfwTerminate();
        return 1;
    }
    
    // creation and initialization of stuff goes here

    running = true;
    while(running)
    {
        // terminate on escape
        if(glfwGetKey(GLFW_KEY_ESC))
        {
            running = false;
        }
        
        // drawing etc goes here
        // ...
       
        // check for errors
        GLenum error = glGetError();
        if(error != GL_NO_ERROR)
        {
            std::cerr << gluErrorString(error);
            running = false;
        }
        
        // finally swap buffers
        glfwSwapBuffers();
    }


    glfwCloseWindow();
    glfwTerminate();
    return 0;
}

Something went wrong with that request. Please try again.