BareGL is a fast, simple, permissive (MIT licensed), cross-platform OpenGL 4.5+ wrapper written in C++20.
It aims to reduce the boilerplate code required to get your modern OpenGL application up and running while enforcing concepts like RAII and making it significantly easier to create buffers, allocate memory, upload data to the GPU, and update the underlying OpenGL state.
// Creating an OpenGL context
baregl::Backend backend;
backend.Init(true);
// Creating a vertex buffer
baregl::Buffer vb;
vb.Allocate(sizeof(vertices), baregl::types::EAccessSpecifier::STATIC_DRAW);
vb.Upload(vertices);
// Creating an index buffer
baregl::Buffer ib;
ib.Allocate(sizeof(indices), baregl::types::EAccessSpecifier::STATIC_DRAW);
ib.Upload(indices);
// Defining a vertex layout
baregl::VertexArray va;
va.SetLayout(
std::to_array<baregl::data::VertexAttribute>({
{ baregl::types::EDataType::FLOAT, 3 },
{ baregl::types::EDataType::FLOAT, 2 }
}), vb, ib
);
// Loading and compiling shaders
baregl::ShaderStage vs(baregl::types::EShaderType::VERTEX);
vs.Upload(vertexShaderCode);
const auto vsCompilationResult = vs.Compile();
assert(vsCompilationResult.success);
baregl::ShaderStage fs(baregl::types::EShaderType::FRAGMENT);
fs.Upload(fragmentShaderCode);
const auto fsCompilationResult = fs.Compile();
assert(fsCompilationResult.success);
// Creating a shader program
baregl::ShaderProgram program;
program.Attach(vs);
program.Attach(fs);
const auto shaderLinkingResult = program.Link();
assert(shaderLinkingResult.success);
// Drawing
backend.SetViewport(0, 0, width, height);
backend.Clear(true, true, true);
program.Bind();
va.Bind();
backend.DrawElements(baregl::types::EPrimitiveMode::TRIANGLES, 3);
va.Unbind();
program.Unbind();
- OpenGL Core 4.5+ (Windows & Linux)
- Modern C++20 code
- Fully documented public headers
- Zero dependencies on OpenGL headers required outside of BareGL (no GL headers are included in public headers)
- Direct State Access (DSA)
- Low overhead
- Easy integration with either Premake5 or CMake
BareGL (library) | Examples |
---|---|
glad (included in sources) | glfw & glm (included as submodules) |
BareGL can be added to your project using either Premake5 or CMake. You'll find both a premake5.lua
file and a CMakeLists.txt
file for the build system of your choice.
Important
Example projects use glfw and glm, which are included as submodules.
Submodules can be initialized directly when cloning by using the --recurse-submodules
argument, or after the repository has been cloned using the git submodule init
command.
You can generate project files for examples using Premake5 from the examples/
folder. On Windows, you can generate these project files by running the gen_examples.bat
script.
Once generated, you'll find the baregl-examples
project files in the examples/
folder.
All contributions to BareGL are welcome — whether it's reporting bugs, suggesting new features, or submitting code improvements.
Feel free to open issues or submit pull requests (PRs) for review. Every bit of help makes a difference!
For more information on contributing, check out CONTRIBUTING.md.
By contributing, you agree that your contributions will be licensed under the MIT License.
BareGL is licensed under the MIT License.
You are free to use, modify, and distribute this project with proper attribution. See the license file for more details.