GithubHelp home page GithubHelp logo

coollibs / glpp Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 210 KB

A thin wrapper around OpenGL for C++17

License: Boost Software License 1.0

CMake 2.66% C++ 97.34%
cplusplus cpp17 modern-cpp opengl opengl-framework

glpp's Introduction

GL++

A thin wrapper around OpenGL for C++17 with no dependencies. This library was inspired by Vulkan.hpp, the C++ wrapper for Vulkan.

Including

To add this library to your project, simply add these two lines to your CMakeLists.txt:

add_subdirectory(path/to/glpp)
target_link_libraries(${PROJECT_NAME} PRIVATE glpp::glpp)

Then include it as:

#include <glpp/glpp.hpp>

Unique resources

All OpenGL object handles (or ids) are wrapped in a UniqueXxx type that handles automatic destruction. These types are similar to a std::unique_ptr: they can't be copied but can be moved.

Stronger types

We define an enum class for each group of OpenGL constants that belong together:

namespace glpp {
enum class Interpolation : GLint {
    NearestNeighbour = GL_NEAREST,
    Linear           = GL_LINEAR,
};
}

We also provide a wrapper for each OpenGL function with stronger typing and error checking:

namespace glpp {
void set_minification_filter(const UniqueTexture& texture, Interpolation interpolation) const
{
    internal::assert_is_bound(GL_TEXTURE_BINDING_2D, *texture,
                              "You must bind the texture before setting its minification filter");
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, raw(interpolation));
    glpp_check_errors();
}
}

glpp_check_errors()

glpp_check_errors() will detect errors generated by OpenGL (even if you don't have access to the modern debugging feature added in OpenGL 4.3):

glUseProgram(0);
glpp_check_errors(); // Will detect that we just tried to use an invalid program id and will call the error callback with an error message of "GL_INVALID_OPERATION"

You can provide you own callback that will be called when an error is detected:

glpp::set_error_callback([](std::string&& error_message) {
    throw std::runtime_error{error_message};
});

If you do not provide a callback, by default glpp logs to std::cerr.

To enable error checking you need to define GLPP_SHOULD_CHECK_ERRORS from your CMake. If you wanted to enable error checking only in debug mode you would do:

target_compile_definitions(glpp PRIVATE $<$<CONFIG:Debug>:GLPP_SHOULD_CHECK_ERRORS>)

and if you wanted error checking even in release:

target_compile_definitions(glpp PRIVATE GLPP_SHOULD_CHECK_ERRORS)

CMake

Here is a typical example of how you would add glpp to your projects:

# ---Add glpp---
add_subdirectory(third-party/glpp)
target_compile_definitions(glpp PRIVATE $<$<CONFIG:Debug>:GLPP_SHOULD_CHECK_ERRORS>) # Enable error checking only in debug mode
target_link_libraries(my_project PUBLIC glpp::glpp)
# ------

glpp's People

Contributors

badbois avatar julesfouchy avatar

Watchers

 avatar

glpp's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.