Compare commits

...

2 commits

5 changed files with 67 additions and 20 deletions

View file

@ -54,7 +54,12 @@ elseif (${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU")
set(LINKER_OPTIMIZED_OPTIONS ${LINKER_OPTIMIZED_OPTIONS} -fdevirtualize-at-ltrans)
endif ()
add_library(${PROJECT_NAME} SHARED src/window.cpp src/context_window.cpp)
add_library(${PROJECT_NAME} SHARED
src/window.cpp
src/context_window.cpp
src/opengl_context.cpp
include/opengl_context.hpp
)
target_precompile_headers(${PROJECT_NAME} PUBLIC include/window.hpp include/basic_data.hpp include/context_window.hpp)
target_include_directories(${PROJECT_NAME}
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
@ -92,7 +97,13 @@ configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/Config.cmake.in
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/windowGlfwGlLibTargets
)
install(FILES include/window.hpp include/basic_data.hpp DESTINATION include/windowGlfwGlLib)
install(FILES
include/window.hpp
include/basic_data.hpp
include/context_window.hpp
include/opengl_context.hpp
DESTINATION include/windowGlfwGlLib
)
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/windowGlfwGlLibTargetsConfig.cmake"

View file

@ -0,0 +1,16 @@
//
// Created by postaron on 05/01/2026.
//
#ifndef WINDOWGLFWGLLIB_OPENGL_CONTEXT_HPP
#define WINDOWGLFWGLLIB_OPENGL_CONTEXT_HPP
namespace gui {
class Window;
}
namespace opengl {
[[nodiscard]] bool init_glew(const gui::Window &win) noexcept;
}
#endif //WINDOWGLFWGLLIB_OPENGL_CONTEXT_HPP

View file

@ -16,6 +16,8 @@ namespace gui {
public:
using modulesType = std::unordered_map<std::string, data::BasicData *>;
using windowPtr = GLFWwindow *;
static constexpr int default_width{ 1280 };
static constexpr int default_height{ 720 };
private:
static void key_callback(GLFWwindow *window, int key, int scancode, int action, int mods);
@ -32,8 +34,6 @@ namespace gui {
modulesType modules;
bool valid{ false };
explicit Window(const bool debugOpengl,
const GLFWframebuffersizefun framebufferCallback,
GLFWwindow *shared,
@ -76,7 +76,7 @@ namespace gui {
void color_10_bits() noexcept;
bool check_color_depth(int color_depth) noexcept;
[[nodiscard]] bool check_color_depth(int color_depth) noexcept;
void opengl_debug() noexcept;
}

33
src/opengl_context.cpp Normal file
View file

@ -0,0 +1,33 @@
//
// Created by postaron on 05/01/2026.
//
#include <GL/glew.h>
#if defined( _WIN32 )
#include <GL/wglew.h>
#endif
#include "opengl_context.hpp"
#include <iostream>
#include "window.hpp"
bool opengl::init_glew(const gui::Window &win) noexcept {
win.get_context();
if (const GLenum error = glewInit(); error != GLEW_OK) {
if (const auto error_callback = glfwSetErrorCallback(nullptr); error_callback != nullptr) {
error_callback(0, reinterpret_cast<const char *>(glewGetErrorString(error)));
glfwSetErrorCallback(error_callback);
} else {
std::cerr << "Error initializing glew: "
<< reinterpret_cast<const char *>(glewGetErrorString(error))
<< std::endl;
}
return false;
}
return true;
}

View file

@ -19,23 +19,10 @@ namespace gui {
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, debugOpengl ? GLFW_TRUE : GLFW_FALSE);
wwindow = std::unique_ptr<GLFWwindow, decltype(&glfwDestroyWindow)>(
glfwCreateWindow(720, 1280, "Billy Sheet tracker", nullptr, shared),
glfwCreateWindow(1280, 720, "Billy Sheet tracker", nullptr, shared),
glfwDestroyWindow);
if (!wwindow) {
valid = false;
return;
}
glfwMakeContextCurrent(wwindow.get());
glewExperimental = true;
if (const GLenum error = glewInit(); error != GLEW_OK) {
valid = false;
if (const auto error_callback = glfwSetErrorCallback(nullptr); error_callback != nullptr) {
error_callback(0, reinterpret_cast<const char *>(glewGetErrorString(error)));
glfwSetErrorCallback(error_callback);
}
return;
}
valid = true;
glfwSetFramebufferSizeCallback(wwindow.get(),
framebufferCallback != nullptr ? framebufferCallback : internalFramebufferCallback);