I am developing a game engine as a personal project and encountering issues with logging to the console using spdlog
. I’ve implemented OpenGL for rendering and managed to draw a basic triangle. However, I’m struggling to log information such as the OpenGL vendor.
I’m using Visual Studio 2022. Here is the relevant part of my OpenGLContext
class that sets up the OpenGL context using GLFW and GLAD:
namespace Nova {
OpenGLContext::OpenGLContext(GLFWwindow* windowHandle)
: m_WindowHandle(windowHandle)
{
NA_CORE_ASSERT(windowHandle, "Window handle is null!");
}
void OpenGLContext::Init()
{
glfwMakeContextCurrent(m_WindowHandle);
int status = gladLoadGLLoader((GLADloadproc)glfwGetProcAddress);
NA_CORE_ASSERT(status, "Failed to initialize Glad!");
NA_CORE_INFO("OpenGL Info:");
NA_CORE_INFO(" Vendor: {0}", glGetString(GL_VENDOR)); // Error here
// Additional info logging
}
void OpenGLContext::SwapBuffers()
{
glfwSwapBuffers(m_WindowHandle);
}
}
The NA_CORE_INFO macro expands to: #define NA_CORE_INFO(…) ::Nova::Log::GetCoreLogger()->info(_VA_ARGS_)
When I try to log the vendor information using glGetString(GL_VENDOR), I get a C2338 static_assert failed: ‘Formatting of non-void pointers is disallowed’. I understand that glGetString returns a const GLubyte*, but I’m not sure how to format this properly for logging with spdlog.
I tried converting the const GLubyte*
to std::string
, but I’m still encountering issues. Here’s what I’ve tried:
NA_CORE_INFO(” Vendor: {}”, reinterpret_cast<const char*>(glGetString(GL_VENDOR)));
Could someone explain the correct way to handle this and log OpenGL strings? Any help would be greatly appreciated!