Quantcast
Channel: GameDev.net
Viewing all articles
Browse latest Browse all 17825

OpenGL core context creation failed horribly

$
0
0
I have problems getting a core opengl context up and running with pure win32 and glew on my system (NVIDIA GTX 970, x64, Win 10, VC++ 2017). The context gets created successfully, but when i want to initialize glew() i get the following error: Missing GL version Also when i query for glGetString with GL_VERSION, GL_VENDOR, GL_RENDERER it returns null... What is wrong? A normal rendering context works just fine: With the new context this is totally null: Glew is not at fault because even without glew i still get null for any values and not a single opengl call works. They dont crash, but they simply dont work. Even glClear() does not work -.- Here is my code (I dont see any error at all): static void Win32LoadOpenGLExtensions_Internal(const Win32State_Internal &win32State) { globalWGLExtensions.choosePixelFormatArb = (wgl_choose_pixel_format_arb *)wglGetProcAddress("wglChoosePixelFormatARB"); globalWGLExtensions.createContextAttribsArb = (wgl_create_context_attribs_arb *)wglGetProcAddress("wglCreateContextAttribsARB"); globalWGLExtensions.swapIntervalExt = (wgl_swap_interval_ext *)wglGetProcAddress("wglSwapIntervalEXT"); } static bool Win32CreateOpenGL_Internal(Win32State_Internal &win32State, const VideoSettings &videoSettings) { HDC deviceContext = win32State.window.deviceContext; HWND handle = win32State.window.windowHandle; PIXELFORMATDESCRIPTOR pfd = {}; pfd.nSize = sizeof(pfd); pfd.nVersion = 1; pfd.dwFlags = PFD_DOUBLEBUFFER | PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW; pfd.iPixelType = PFD_TYPE_RGBA; pfd.cColorBits = 32; pfd.cDepthBits = 32; pfd.cAlphaBits = 8; pfd.iLayerType = PFD_MAIN_PLANE; int pixelFormat = ChoosePixelFormat(deviceContext, &pfd); if (!pixelFormat) { PushError_Internal("[Win32] Failed choosing RGBA Legacy Pixelformat for Color/Depth/Alpha (%d,%d,%d) and DC '%x'\n", pfd.cColorBits, pfd.cDepthBits, pfd.cAlphaBits, deviceContext); return false; } if (!SetPixelFormat(deviceContext, pixelFormat, &pfd)) { PushError_Internal("[Win32] Failed setting RGBA Pixelformat '%d' for Color/Depth/Alpha (%d,%d,%d and DC '%x')\n", pixelFormat, pfd.cColorBits, pfd.cDepthBits, pfd.cAlphaBits, deviceContext); return false; } HGLRC legacyRenderingContext = wglCreateContext(deviceContext); if (!legacyRenderingContext) { PushError_Internal("[Win32] Failed creating Legacy OpenGL Rendering Context for DC '%x')\n", deviceContext); return false; } if (!wglMakeCurrent(deviceContext, legacyRenderingContext)) { PushError_Internal("[Win32] Failed activating Legacy OpenGL Rendering Context for DC '%x' and RC '%x')\n", deviceContext, legacyRenderingContext); wglDeleteContext(legacyRenderingContext); return false; } Win32LoadOpenGLExtensions_Internal(win32State); HGLRC activeRenderingContext = legacyRenderingContext; if (videoSettings.profile != VideoCompabilityProfile::Legacy) { if (!(videoSettings.majorVersion > 0 && videoSettings.minorVersion >= 0)) { PushError_Internal("[Win32] The specified major version '%llu' and minorVersion '%llu' is invalid!\n", videoSettings.majorVersion, videoSettings.minorVersion); return false; } if (!globalWGLExtensions.choosePixelFormatArb) { PushError_Internal("[Win32] wglChoosePixelFormatARB is not available, please select a different video profile!\n"); return false; } if (!globalWGLExtensions.createContextAttribsArb) { PushError_Internal("[Win32] wglCreateContextAttribsARB is not available, please select a different video profile!\n"); return false; } int contextAttribList[32 + 1] = {}; int contextAttribCount = 0; contextAttribList[contextAttribCount++] = WGL_CONTEXT_MAJOR_VERSION_ARB; contextAttribList[contextAttribCount++] = (int)videoSettings.majorVersion; contextAttribList[contextAttribCount++] = WGL_CONTEXT_MINOR_VERSION_ARB; contextAttribList[contextAttribCount++] = (int)videoSettings.minorVersion; #if 0 contextAttribList[contextAttribCount++] = WGL_CONTEXT_FLAGS_ARB; contextAttribList[contextAttribCount++] = WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB; contextAttribList[contextAttribCount++] = WGL_CONTEXT_PROFILE_MASK_ARB; contextAttribList[contextAttribCount++] = WGL_CONTEXT_CORE_PROFILE_BIT_ARB; #endif contextAttribList[contextAttribCount++] = 0; HGLRC newContext = globalWGLExtensions.createContextAttribsArb(deviceContext, nullptr, contextAttribList); if (newContext) { if (!wglMakeCurrent(deviceContext, newContext)) { PushError_Internal("[Win32] Warning: Failed activating Modern OpenGL Rendering Context for version (%llu.%llu) and DC '%x') -> Fallback to legacy context.\n", videoSettings.majorVersion, videoSettings.minorVersion, deviceContext); wglDeleteContext(newContext); newContext = nullptr; } else { // Destroy legacy rendering context wglMakeCurrent(nullptr, nullptr); wglDeleteContext(legacyRenderingContext); activeRenderingContext = newContext; } } else { PushError_Internal("[Win32] Warning: Failed creating Modern OpenGL Rendering Context for version (%llu.%llu) and DC '%x') -> Fallback to legacy context.\n", videoSettings.majorVersion, videoSettings.minorVersion, deviceContext); } } FPL_ASSERT(activeRenderingContext != nullptr); win32State.opengl.renderingContext = activeRenderingContext; // Set vertical syncronisation if available if (globalWGLExtensions.swapIntervalExt != nullptr) { int swapInterval = videoSettings.isVSync ? 1 : 0; globalWGLExtensions.swapIntervalExt(swapInterval); } return true; }

Viewing all articles
Browse latest Browse all 17825

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>