Wiki

Clone wiki

glxx / SimpleUsage

Basic Usage


Core Contexts

#include <glxx/gl_3_3_core.h> // Included it before any OpenGL headers (eg. before gl.h)!
// Now we have all OpenGL 3.3 core functionality

on_OpenGL_init()
{
    if (!has_gl_3_3_core()) {
        std::cerr << "Current context does not support OpenGL Core 3.3";
        exit(0);
    }
    if (!load_gl_3_3_core()) {
        std::cerr << "Could not load all core 3.3 functions";
    }
}
// ...
on_OpenGL_paint()
{   
    glClear(GL_COLOR_BUFFER_BIT);
    // glWhateverCommand(...) up to 3.3 (core only)
}



Compatibility contexts

#include <glxx/gl_3_1_compatibility.h>
// Now we have all OpenGL 3.1 compatibility functionality

on_OpenGL_init()
{
    if (!has_gl_3_1_compatibility()) {
        // Current context does not support version 3.1
    }
    if (!load_gl_3_1_compatibility()) {
        // Could not load all version 3.1 functions
    }
}

on_OpenGL_paint()
{
    glClear(GL_COLOR_BUFFER_BIT);
    glMatrixMode(GL_PROJECTION);
    // glWhateverFunction(...); up to OpenGL 3.1
}



Contexts for OpenGL 3.0 and lower

#include <glxx/gl_2_1.h>
// Now we have all OpenGL 2.1 functionality

on_OpenGL_init()
{
    if (!has_gl_2_1()) {
        // Current context does not support version 2.1
    }
    if (!load_gl_2_1()) {
        // Could not load all version 2.1 functions
    }
}

on_OpenGL_paint()
{
    glClear(GL_COLOR_BUFFER_BIT);
    glMatrixMode(GL_PROJECTION);
    // glWhateverFunction(...); up to OpenGL 2.1
}

Updated