Wiki

Clone wiki

glxx / UsingMultipleContexts

#include <gl_2_1.h>
#include <gl_3_3_core.h>

GLXXloader gl21, gl33;

on_OpenGL_init()
{
    // Set the first context current.
    ...
    // Create a new GLXXloader handle and bind it as the current loader.
    gl21 = glxxGenLoader();
    glxxBindLoader(gl21);

    if (has_gl_2_1())
        // Does not support OpenGL 2.1  
    if (load_gl_2_1())
        // Can't load OpenGL 2.1

    // Set the second context current.
    ...
    // Create the second GLXXloader handle and bind it
    gl33 = glxxGenLoader();
    glxxBindLoader(gl33);

    if (!has_gl_3_3_core())
        // Does not support OpenGL 3.3 core
    if (!load_gl_3_3_core())
        // Can't load core OpenGL 3.3
}

on_OpenGL_paint() 
{
    // Set the first context current.
    ...
    // Bind the first loader object.
    glxxBindLoader(gl21);  // All gl commands are routed to the gl21 handle
    glClear(GL_COLOR_BUFFER_BIT);
    // ... Draw in the first context ...


    // Set the second context current.
    ...
    // Bind the second loader object
    glxxBindLoader(gl33); // All gl commands are routed to the gl33 handle
    glClear(GL_COLOR_BUFFER_BIT);
    glBlendFuncSeparate(GL_ONE, GL_ZERO, GL_ONE, GL_ONE);
    // ... Draw in the second context ...
} 

Updated