feat: add RAII window class with OpenGL 4.1 context

- Add cbt::window class in cbt/ directory with RAII lifecycle
- Add setup_opengl and info_opengl for glad init and GL info
- Add Q key to quit the application
- Update CMakeLists.txt with glfw3 and glad dependencies
- Update AGENTS.md with snake_case naming and shell conventions
This commit is contained in:
2026-05-05 21:50:50 +02:00
parent f13eb491d9
commit 47d01f57c0
7 changed files with 296 additions and 19 deletions
+68
View File
@@ -0,0 +1,68 @@
# ==============================================================================
# Find glad
# ==============================================================================
# This module fetches the glad OpenGL loader library.
#
# Targets provided:
# glad::glad - The glad library target
#
# Variables set:
# glad_FOUND - TRUE if glad is available
# glad_LIBRARIES - The glad library target (glad::glad)
# glad_INCLUDE_DIR - Include directories for glad
# glad_VERSION - Version of glad (commit hash or tag)
# ==============================================================================
if (DEFINED _FINDGLAD_INCLUDED)
return()
endif()
set(_FINDGLAD_INCLUDED TRUE)
# Use the version passed to find_package(), or default to commit hash
if (DEFINED glad_FIND_VERSION AND NOT glad_FIND_VERSION STREQUAL "")
set(GLAD_VERSION "${glad_FIND_VERSION}")
else()
set(GLAD_VERSION "f4759d7c5143c0a23391ab05caaf43052cefdd65")
endif()
message(STATUS "Fetching glad ${GLAD_VERSION}")
include(FetchContent)
find_program(GIT_EXECUTABLE git)
if (GIT_EXECUTABLE)
set(GLAD_FETCH_METHOD "GIT")
else()
message(FATAL_ERROR "Fetch with zip not supported.")
endif()
if (GLAD_FETCH_METHOD STREQUAL "GIT")
FetchContent_Declare(
glad
GIT_REPOSITORY https://github.com/mononerv/glad.git
GIT_TAG ${GLAD_VERSION}
)
endif()
FetchContent_MakeAvailable(glad)
if (NOT TARGET glad::glad)
if (TARGET glad)
add_library(glad::glad ALIAS glad)
else()
message(FATAL_ERROR "Could not fetch glad; no target glad or glad::glad available")
endif()
endif()
set(glad_FOUND TRUE)
set(glad_LIBRARIES glad::glad)
set(glad_VERSION "${GLAD_VERSION}")
get_target_property(_glad_inc glad::glad INTERFACE_INCLUDE_DIRECTORIES)
set(glad_INCLUDE_DIR "${_glad_inc}")
# Mark glad includes as SYSTEM to suppress warnings from its headers
if (_glad_inc AND TARGET glad)
set_target_properties(glad PROPERTIES
INTERFACE_SYSTEM_INCLUDE_DIRECTORIES "${_glad_inc}"
)
endif()
+81
View File
@@ -0,0 +1,81 @@
# ==============================================================================
# Find GLFW
# ==============================================================================
# This module fetches the GLFW library for window/input handling.
#
# Targets provided:
# glfw::glfw - The GLFW library target
# glfw - The GLFW library target (non-namespaced)
#
# Variables set:
# GLFW_FOUND - TRUE if GLFW is available
# GLFW_LIBRARIES - The GLFW library target (glfw::glfw)
# GLFW_INCLUDE_DIR - Include directories for GLFW
# GLFW_VERSION - Version of GLFW (if available)
# ==============================================================================
if (DEFINED _FINDGLFW_INCLUDED)
return()
endif()
set(_FINDGLFW_INCLUDED TRUE)
# Use the version passed to find_package(), or default to 3.4
if (DEFINED GLFW_FIND_VERSION AND NOT GLFW_FIND_VERSION STREQUAL "")
set(GLFW_VERSION "${GLFW_FIND_VERSION}")
else()
set(GLFW_VERSION "3.4")
endif()
message(STATUS "Fetching GLFW ${GLFW_VERSION}")
include(FetchContent)
find_program(GIT_EXECUTABLE git)
if (GIT_EXECUTABLE)
set(GLFW_FETCH_METHOD "GIT")
else()
message(FATAL_ERROR "Fetch with zip not supported.")
endif()
if (GLFW_FETCH_METHOD STREQUAL "GIT")
# Disable GLFW extras to keep builds lightweight.
set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
set(GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE)
set(GLFW_BUILD_DOCS OFF CACHE BOOL "" FORCE)
set(GLFW_INSTALL OFF CACHE BOOL "" FORCE)
# Environment issue where a cross-compilation script
# set(GLFW_BUILD_WAYLAND OFF CACHE BOOL "" FORCE)
FetchContent_Declare(
glfw
GIT_REPOSITORY https://github.com/glfw/glfw.git
GIT_TAG ${GLFW_VERSION}
)
endif()
set(_glfw_suppress_prev ${CMAKE_SUPPRESS_DEVELOPER_WARNINGS})
set(CMAKE_SUPPRESS_DEVELOPER_WARNINGS TRUE CACHE INTERNAL "")
FetchContent_MakeAvailable(glfw)
set(CMAKE_SUPPRESS_DEVELOPER_WARNINGS ${_glfw_suppress_prev} CACHE INTERNAL "")
if (NOT TARGET glfw::glfw)
if (TARGET glfw)
add_library(glfw::glfw ALIAS glfw)
else()
message(FATAL_ERROR "Could not fetch GLFW; no target glfw or glfw::glfw available")
endif()
endif()
set(GLFW_FOUND TRUE)
set(GLFW_LIBRARIES glfw::glfw)
get_target_property(_glfw_inc glfw::glfw INTERFACE_INCLUDE_DIRECTORIES)
set(GLFW_INCLUDE_DIR "${_glfw_inc}")
# Mark GLFW includes as SYSTEM to suppress warnings from its headers
if (_glfw_inc AND TARGET glfw)
set_target_properties(glfw PROPERTIES
INTERFACE_SYSTEM_INCLUDE_DIRECTORIES "${_glfw_inc}"
)
endif()
set(GLFW_LICENSE_FILE "${glfw_SOURCE_DIR}/LICENSE.md" CACHE FILEPATH "Path to GLFW license file")