Adding glew as OpenGL initialization in a different scope
This commit is contained in:
parent
b8c9268911
commit
66e43ba333
5 changed files with 60 additions and 19 deletions
33
src/opengl_context.cpp
Normal file
33
src/opengl_context.cpp
Normal 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;
|
||||
}
|
||||
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue