A C++ template to get started with OpenGL.
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
apps
cmake
external
shaders
src
.gitignore
.gitmodules
CHANGES.md
CMakeLists.txt
LICENSE
README.md

README.md

OpenGL Bootstrap

A C++ template to get started with OpenGL.

Any GUI toolkit can potentially be hooked up to the core module dedicated to OpenGL.
GLFW and Qt 5 (with or without the QtWidgets module) are both supported out of the box.

Dependencies

CMake 2.8 or higher is required to build the project.

To also build the hooks with Qt, Qt 5 needs to be installed and findable by CMake. The easiest way is to set the the CMAKE_PREFIX_PATH variable as noted in the Compiling and Running section below.

Quick Start

  1. Retrieve the files either by downloading the latest .zip file from github.com/christophercrouzet/opengl-bootstrap or by cloning the git repository using git clone https://github.com/christophercrouzet/opengl-bootstrap.git.
  2. Retrieve the content of the GLFW submodule if required by firing from the root directory git submodule init followed by git submodule update. As with Qt, any reference to GLFW will need otherwise to be removed manually.
  3. The file src/bootstrap/core/common.h can be modified to affect the values used by the GUI toolkits for creating the OpenGL context.
  4. Add any OpenGL code into the src/bootstrap/core/openglrenderer.cpp file as indicated.
  5. Compile and run.

Compiling and Running

The compilation steps go as follows:

$ cd opengl-bootstrap
$ mkdir build
$ cd build
$ cmake .. -DCMAKE_PREFIX_PATH=/path/to/Qt5
$ make

The generated binaries can then be found within the bin directory structure, ie.:

$ ./bin/qt5/basic

Including a GLSL Shader

Two ways are provided to load a shader from a file: dynamically and statically.

In both cases, files containing a single shader should be saved in the shaders folder and must be written using a normal GLSL syntax, ie.:

#version 430 core
void main(void)
{
    const vec4 vertices[3] = vec4[3](
        vec4( 0.25, -0.25, 0.5, 1.0),
        vec4(-0.25, -0.25, 0.5, 1.0),
        vec4( 0.25,  0.25, 0.5, 1.0)
    );
    
    gl_Position = vertices[gl_VertexID];
}

The filename can be anything but must be added to the bootstrap_shaders_files variable from the CMakeLists.txt located in the same folder.

Dynamic Loading

  • in the shaders/CMakeLists.txt file, set the load_shaders_dynamically variable to true.
  • optionally set up a different destination directory for the shader files to be generated by changing the appropriate destination_dir variable.
  • in the C++ file, load the shader by using the bootstrap::core::setShaderSourceFromFile() function located in the src/bootstrap/core/utils.h file.

Example:

GLuint awesomeShader = glCreateShader(GL_VERTEX_SHADER);
setShaderSourceFromFile(awesomeShader, "shaders/awesome.glsl");
glCompileShader(awesomeShader);

Static Loading

  • in the shaders/CMakeLists.txt file, set the load_shaders_dynamically variable to false.
  • in the C++ file, include the shader with a standard include statement such as #include <shaders/awesome.glsl>. By default, this includes a variable named as per the shader file such as static const GLchar *awesomeShaderSource.
  • pass this variable to the glShaderSource() function.

Optionally, the name of the generated shader variable can be changed in the cmake/shaders.cmake file.

Example:

#include <shaders/awesome.glsl>

GLuint awesomeShader = glCreateShader(GL_VERTEX_SHADER);
glShaderSource(awesomeShader, 1, awesomeShaderSource, 0);
glCompileShader(awesomeShader);

Notes

The Qt 5 module provides a class bootstrap::qt5::OpenGLSurface as a lightweight version using only the QtGui module of Qt. The class bootstrap::qt5::Window is provided for when the QtWidgets module is to be used.

The Qt 5 applications basic and widgets respectively serve as examples for the QtGui-only version and the QtWidgets one.

Get the Source

The source code is available from the GitHub project page.

Versioning

Versions numbers will comply with the Sementic Versioning (SemVer) specification and will be written in the form <major>.<minor>.<patch>, where:

  • backwards incompatible API changes increments the major version (and resets the minor and patch versions).
  • backwards compatible API additions/changes increments the minor version (and resets the patch version).
  • bug fixes not affecting the API increments the patch version.

Contributing

Found a bug or got a feature request? Don't keep it for yourself, log a new issue on GitHub.

Author

Christopher Crouzet
christophercrouzet.com