File gl_utils.hpp

namespace controls
namespace utils

Functions

SDL_Window *create_sdl2_gl_window(const char *title, int width, int height, Uint32 additional_flags = 0, SDL_GLContext *gl_context = nullptr)

Creates an SDL2 window with OpenGL context.

Parameters:
  • title – The title of the window.

  • width – The width of the window.

  • height – The height of the window.

  • additional_flags – Additional flags for the SDL window.

  • gl_context[out] Pointer to an SDL_GLContext to store the created context.

Throws:

std::runtime_error – if there is an error during window or context creation.

Returns:

Pointer to the created SDL_Window.

void print_program_log(GLuint program)

Prints the log of a GLSL program.

Parameters:

program – The OpenGL program ID.

void print_shader_log(GLuint shader)

Prints the log of a GLSL shader.

Parameters:

shader – The OpenGL shader ID.

void gl_debug_callback(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *message, const void *userParam)

Callback function for OpenGL debug messages.

Parameters:
  • source – The source of the debug message.

  • type – The type of the debug message.

  • id – The ID of the debug message.

  • severity – The severity of the debug message.

  • length – The length of the debug message.

  • message – The debug message string.

  • userParam – User-defined parameter.

GLuint compile_shader(const char *vertex_source, const char *fragment_source)

JIT compiles the various shader codes together into a single shader program.

Parameters:
  • vertex_source – vertex shader code.

  • fragment_source – fragment shader code

Throws:

std::runtime_error – if there is an error during shader compilation or program linking.

Returns:

the compound shader program ID to be used.

void make_gl_current_or_except(SDL_Window *window, SDL_GLContext gl_context)

Makes the OpenGL context current for the specified window or throws an exception.

Parameters:
  • window – The SDL window.

  • gl_context – The OpenGL context.

Throws:

std::runtime_error – if there is an error making the context current.

void sync_gl_and_unbind_context(SDL_Window *window)

Synchronizes with the OpenGL commands and unbinds the context from the current thread.

Parameters:

window – The SDL window.

struct GLObj
#include <gl_utils.hpp>

Stores the names of the vao, vbo, ebo. Once the names are generated by gen_gl_path(), they can be used as identifiers for other OpenGL functions.

Public Members

GLuint vao

Vertex Array Object. Specifies how the VBO is laid out, e.g. how big is a vertex.

GLuint vbo

Vertex Buffer Object. Contiguous block of memory where all the vertices’ information is stored.

GLuint ebo

Element Buffer Object. Memory that contains triples of indices into the VBO, representing triangles.