int gladLoadWGL(HDC hdc) { if(open_gl()) { gladLoadWGLLoader((GLADloadproc)get_proc, hdc); close_gl(); return 1; } return 0; }
int gladLoadWGL(HDC hdc) { int status = 0; if(open_gl()) { status = gladLoadWGLLoader((GLADloadproc)get_proc, hdc); close_gl(); } return status; }
std::unique_ptr<os::OpenGLContext> MFCGraphicsOperations::createOpenGLContext(os::Viewport* port, const os::OpenGLContextAttributes& ctx) { auto mfcView = reinterpret_cast<MFCViewport*>(port); auto temp_ctx = wglCreateContext(mfcView->getHDC()); if (!temp_ctx) { mprintf(("Unable to create fake context for OpenGL W32!\n")); return nullptr; } if (!wglMakeCurrent(mfcView->getHDC(), temp_ctx)) { mprintf(("Unable to make current thread for OpenGL W32!\n")); if (!wglDeleteContext(temp_ctx)) { mprintf(("Failed to delete render context!")); } return nullptr; } if (!gladLoadWGLLoader(gladWGLLoader, mfcView->getHDC())) { mprintf(("Failed to load WGL functions!\n")); wglMakeCurrent(nullptr, nullptr); if (!wglDeleteContext(temp_ctx)) { mprintf(("Failed to delete render context!")); } return nullptr; } if (!GLAD_WGL_ARB_create_context) { // No support for 3.x if (ctx.major_version >= 3) { mprintf(("Can't create requested OpenGL context!\n")); wglMakeCurrent(nullptr, nullptr); if (!wglDeleteContext(temp_ctx)) { mprintf(("Failed to delete fake context!")); } return nullptr; } // Major version is low enough -> just use the fake context return std::unique_ptr<os::OpenGLContext>(new MFCOpenGLContext(temp_ctx)); } SCP_vector<int> attrib_list; attrib_list.push_back(WGL_CONTEXT_MAJOR_VERSION_ARB); attrib_list.push_back(ctx.major_version); attrib_list.push_back(WGL_CONTEXT_MINOR_VERSION_ARB); attrib_list.push_back(ctx.minor_version); if (GLAD_WGL_ARB_create_context_profile) { attrib_list.push_back(WGL_CONTEXT_PROFILE_MASK_ARB); attrib_list.push_back(ctx.profile == os::OpenGLProfile::Core ? WGL_CONTEXT_CORE_PROFILE_BIT_ARB : WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB); } int flags = 0; if (ctx.flags[os::OpenGLContextFlags::Debug]) { flags |= WGL_CONTEXT_DEBUG_BIT_ARB; } if (ctx.flags[os::OpenGLContextFlags::ForwardCompatible]) { flags |= WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB; } if (flags != 0) { attrib_list.push_back(WGL_CONTEXT_FLAGS_ARB); attrib_list.push_back(flags); } attrib_list.push_back(0); auto attrib_ctx = wglCreateContextAttribsARB(mfcView->getHDC(), nullptr, attrib_list.data()); // We don't need the fake context anymore wglMakeCurrent(nullptr, nullptr); if (!wglDeleteContext(temp_ctx)) { mprintf(("Failed to delete fakse context!")); } if (attrib_ctx == nullptr) { mprintf(("Failed to create OpenGL context!\n")); return nullptr; } if (!wglMakeCurrent(mfcView->getHDC(), attrib_ctx)) { mprintf(("Unable to make current thread for OpenGL W32!\n")); if (!wglDeleteContext(attrib_ctx)) { mprintf(("Failed to delete render context!")); } return nullptr; } if (!gladLoadWGLLoader(gladWGLLoader, mfcView->getHDC())) { mprintf(("Failed to load WGL functions!\n")); wglMakeCurrent(nullptr, nullptr); if (!wglDeleteContext(temp_ctx)) { mprintf(("Failed to delete render context!")); } return nullptr; } return std::unique_ptr<os::OpenGLContext>(new MFCOpenGLContext(attrib_ctx)); }