glfl

glfl is a C++ header-only library for loading openGL API functions into a namespace with snake_case names
and replaces macro constants with constexpr.

Currently supported platforms are windows and linux.

files


  • platform.hpp is for platform related defintions and defining the DummyContext class.
  • core.hpp is where all the core arb opengl functions and constants are defined. It also defines a robust load function and a check_extension function.
  • enums.hpp defines functions that convert important opengl enumeration constants to string constants. This is useful for debugging.

for basic loading you only need platform.hpp and core.hpp

Note

  • When you call load() without a context it will initialize a static DummyContext and it will be made current even after the function returns. It is best to create your own context first then call load().

  • You can create a DummyContext your self. It is defined in platform.hpp. platform.hpp is automatically included when you include core.hpp.

  • To iterate through and check for extensions at runtime you can use the check_extension() function. You can also use the version and extension variables defined in the namespace glfl and set when load() is called, which is way faster but will depend on the context that you used when calling load().

  • Namespaces:

    • glfl – base namespace
    • glfl::GL – includes all GL* namespaces
    • glfl::GL1, glfl::GL2, glfl::GLARB, glfl::GLEXT, … – Specific version and extensions namespaces.
    • glfl::win, glfl::glx – Platform specific namespaces.
  • Macros:

    • GLFL_PLATFORM_WINDOWS, GLFL_PLATFORM_LINUX, GLFL_PLATFORM_API, GLFL_APIENTRY, GLFL_VAR_API, GLFL_CONSTANT
    • GLFL_PLATFORM_HPP, GLFL_CORE_HPP, GLFL_ENUMS_HPP
  • Functions

    • core.hpp: load, check_extension
    • enums.hpp: enum_error, enum_debug_source, enum_message_type, enum_severity

examples

    // load all versions and extensions
    glfl::load(); 
    // load all versions and extensions. reload even if already loaded.
    glfl::load(true); 
    // load versions 1,2,3 and ARB extensions
    glfl::load(false, 
          glfl::VE::GL1
        | glfl::VE::GL2
        | glfl::VE::GL3
        | glfl::VE::GLARB
    );
    // load all versions and ARB extensions
    glfl::load(false, 
          glfl::VE::AllVersions
        | glfl::VE::GLARB
    );
    // load versions 1,2,4 and all extensions
    glfl::load(false, 
          glfl::VE::GL1
        | glfl::VE::GL2
        | glfl::VE::GL4
        | glfl::VE::AllExtensions
    );

    // 
    glfl::load();
    using namespace glfl;
    if(VERSION_1_0)
    {
        printf("%s\n", GL::get_string(GL::VERSION));
    }
    // 
    glfl::load();
    using namespace glfl;
    if(VERSION_1_0)
    {
        using namespace GL;
        printf("%s\n", get_string(VERSION));
    }

    // 
    glfl::load();
    using namespace glfl;
    if(VERSION_1_0)
    {
        auto const * version = GL::get_string(GL::VERSION);
        if(VERSION_3_0)
        {
            int major_version, minor_version;
            while(GL::get_error() != GL::NO_ERROR);
            GL::get_integerv(GL::MAJOR_VERSION, &major_version);
            GL::get_integerv(GL::MINOR_VERSION, &minor_version);
            assert(GL::get_error() == GL::NO_ERROR);
        }
    }
    // 
    glfl::load();
    using namespace glfl;
    if(VERSION_1_0)
    {
        using namespace GL;
        auto const * version = get_string(VERSION);
        if(VERSION_3_0)
        {
            int major_version, minor_version;
            while(get_error() != NO_ERROR);
            get_integerv(MAJOR_VERSION, &major_version);
            get_integerv(MINOR_VERSION, &minor_version);
            assert(get_error() == NO_ERROR);
        }
    }

    glfl::load();
    using namespace glfl::GL;
    printf("error: %s\n", enum_error(get_error()));

GitHub

View Github