add glad to load OpenGL extensions

This commit is contained in:
2019-07-09 11:07:01 +02:00
parent 81b62d9a27
commit 4cbf0c47b4
20 changed files with 65 additions and 209 deletions

View File

@@ -707,6 +707,22 @@ BOOL UnadjustWindowRectEx(LPRECT prc, DWORD dwStyle, BOOL fMenu, DWORD dwExStyle
return fRc;
}
void _pre_call_callback(const char* name, void* funcptr, int len_args, ...)
{
assert(App::I.is_render_thread());
}
void _post_call_callback(const char* name, void* funcptr, int len_args, ...)
{
GLenum error_code;
error_code = glad_glGetError();
if (error_code != GL_NO_ERROR)
{
LOG("ERROR %d in %s\n", error_code, name);
}
}
int main(int argc, char** argv)
{
WNDCLASS wc;
@@ -814,8 +830,16 @@ int main(int argc, char** argv)
wglMakeCurrent(hDC, hRC);
// Initialize extensions
if (glewInit() != GLEW_OK)
if (!gladLoadGL())
{
LOG("gladLoadGL() failed");
return 0;
}
if (!gladLoadWGL(hDC))
{
LOG("gladLoadWGL() failed");
return 0;
}
LOG("GL version: %s", glGetString(GL_VERSION));
LOG("GL vendor: %s", glGetString(GL_VENDOR));
@@ -825,13 +849,13 @@ int main(int argc, char** argv)
swprintf_s(window_title, L"PanoPainter %s (%s)", g_version_number_w,
str2wstr((char*)glGetString(GL_RENDERER)).c_str());
// If supported create a 3.1 context
if (wglewIsSupported("WGL_ARB_create_context"))
// If supported create a 3.3 context
if (GLAD_WGL_ARB_create_context)
{
int contex_attribs[] =
{
WGL_CONTEXT_MAJOR_VERSION_ARB, 3,
WGL_CONTEXT_MINOR_VERSION_ARB, 1,
WGL_CONTEXT_MINOR_VERSION_ARB, 3,
WGL_CONTEXT_FLAGS_ARB, WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB,
WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_CORE_PROFILE_BIT_ARB,
0
@@ -904,6 +928,11 @@ int main(int argc, char** argv)
App::I.render_thread_start();
App::I.ui_thread_start();
#ifdef _DEBUG
glad_set_pre_callback(_pre_call_callback);
glad_set_post_callback(_post_call_callback);
#endif
LOG("init app");
App::I.init();