Summary
glfwInit()
returns 0
, GLFW_NO_ERROR
but after hand,
when calling glfwCreateWindow
, My error callback prints out “GLFW_NOT_INITIALIZED
” error with error message “The GLFW library is not initialized
”
- Engine
- Graphics
- Private
- OpenGlTest.cpp
- Public
- OpenGlTest.h
- Private
- Graphics
- Samples
- Main.cpp
// OpenGlTest.h
#pragma once
...
void GlfwErrorCallback(int error, const char* message);
void GlfwErrorInterpretor(int error);
int GlfwTestMain(int argc, char* argv[]);
GLuint LoadShaders(ShaderInfo* shaders);
// OpenGlTest.cpp
#include "OpenGlTest.h"
void GlfwErrorCallback(int error, const char* message)
{
GlfwErrorInterpretor(error);
LOGE(eLogChannel::GRAPHICS, std::cout, message);
}
void GlfwErrorInterpretor(int error)
{
...
LOGEF(eLogChannel::GRAPHICS, std::cout, "error code: %x, error message: %s", error, errorMessage);
...
}
int GlfwTestMain(int argc, char* argv[])
{
int errorCode = glfwInit();
GlfwErrorInterpretor(errorCode);
if (errorCode == GLFW_NOT_INITIALIZED)
{
return -1;
}
glfwSetErrorCallback(GlfwErrorCallback);
GLFWwindow* window = glfwCreateWindow(640, 480, "MyTitle", nullptr, nullptr); // Error Occurs Here
if (window == nullptr)
{
LOGE(eLogChannel::GRAPHICS, std::cout, "GLFWwindow creation failed");
glfwTerminate();
return -1;
}
...
glfwDestroyWindow(window);
glfwTerminate();
return 0;
}
...
// Main.cpp
...
int main(int argc, char* argv[])
{
return GlfwTestMain(argc, argv);
}
...
# CMakeLists.txt in Graphics Folder
if (UNIX)
set(GLFW_BUILD_DOCS OFF CACHE BOOL "" FORCE)
set(GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE)
set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
find_package(glfw3 3.3 REQUIRED)
set(OpenGL_GL_PREFERENCE "GLVND")
find_package(OpenGL REQUIRED)
target_link_libraries(Graphics PUBLIC OpenGL::GL)
target_link_libraries(Graphics PUBLIC glfw)
target_link_libraries(Graphics PUBLIC Gl3w)
target_link_libraries(Graphics PUBLIC ${CMAKE_DL_LIBS})
endif (UNIX)
Platform Information
OS: Ubuntu 20.04.2LTS
VGA: Mesa Intel UHD Graphics 620 (WHL GT2)