PDA

View Full Version : GL_CONTEXT_FLAG_DEBUG_BIT bit false in Windows Debug context!



KarimIO
07-17-2017, 07:24 AM
Hey guys! I'm trying to use the debug callback feature in OpenGL, and now I have an issue. I created the window using a debug context, and now GL_CONTEXT_FLAGS doesn't contain the GL_CONTEXT_FLAG_DEBUG_BIT bit. I use OpenGL 4.5 and my card is a Nvidia GTX 970. If I skip the check, the debug context seems to work fine.

Any ideas? Here's my window-opengl context creation code:


bool GLGraphicsWrapper::InitializeWindowContext(GLint major, GLint minor, HWND windowHandle) {
static PIXELFORMATDESCRIPTOR pfd = // pfd Tells Windows How We Want Things To Be
{
sizeof(PIXELFORMATDESCRIPTOR), // Size Of This Pixel Format Descriptor
1, // Version Number
PFD_DRAW_TO_WINDOW | // Format Must Support Window
PFD_SUPPORT_OPENGL | // Format Must Support OpenGL
PFD_DOUBLEBUFFER, // Must Support Double Buffering
PFD_TYPE_RGBA, // Request An RGBA Format
32, // Select Our Color Depth
0, 0, 0, 0, 0, 0, // Color Bits Ignored
0, // No Alpha Buffer
0, // Shift Bit Ignored
0, // No Accumulation Buffer
0, 0, 0, 0, // Accumulation Bits Ignored
24, // 24Bit Z-Buffer (Depth Buffer)
0, // No Stencil Buffer
0, // No Auxiliary Buffer
PFD_MAIN_PLANE, // Main Drawing Layer
0, // Reserved
0, 0, 0 // Layer Masks Ignored
};

if (!(hDC = GetDC(windowHandle)))
return false;

unsigned int PixelFormat;
if (!(PixelFormat = ChoosePixelFormat(hDC, &pfd)))
return false;

if (!SetPixelFormat(hDC, PixelFormat, &pfd))
return false;


int attribs[] =
{
WGL_CONTEXT_MAJOR_VERSION_ARB, major,
WGL_CONTEXT_MINOR_VERSION_ARB, minor,
WGL_CONTEXT_FLAGS_ARB,
WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB |
WGL_CONTEXT_DEBUG_BIT_ARB,
WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_CORE_PROFILE_BIT_ARB,
0
};

PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribsARB = NULL;
wglCreateContextAttribsARB = (PFNWGLCREATECONTEXTATTRIBSARBPROC)
gl3wGetProcAddress("wglCreateContextAttribsARB");
if (wglCreateContextAttribsARB != NULL)
hRC = wglCreateContextAttribsARB(hDC, 0, attribs);
if (!(hRC = wglCreateContext(hDC)))
return false;

if (!wglMakeCurrent(hDC, hRC))
return false;

return TRUE;
}


And my debug callback creation code:


GLint flags;
glGetIntegerv(GL_CONTEXT_FLAGS, &flags);
if (flags & GL_CONTEXT_FLAG_DEBUG_BIT) {
glEnable(GL_DEBUG_OUTPUT);
glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS);
glDebugMessageCallback((GLDEBUGPROC)glDebugOutput, nullptr);
glDebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, nullptr, GL_TRUE);
}


In case you're wondering why I need to create the window myself, I'm planning on supporting non-GL systems like Vulkan, DirectX, Metal, and GNM, so a system like GLFW won't cut it.

KarimIO
07-17-2017, 01:18 PM
The actual reason why it isn't working is because wglGetProcAddress("wglCreateContextAttribsARB") returns NULL. I have no idea how to fix that.

Dark Photon
07-17-2017, 07:26 PM
The actual reason why it isn't working is because wglGetProcAddress("wglCreateContextAttribsARB") returns NULL. I have no idea how to fix that.

You must:

1) Create a GL context the old way (wglCreateContext())
2) Bind that GL context with wglMakeCurrent() before
3) Calling wglGetProcAddress().

* Platform_specifics:_Windows#wglGetProcAddress (https://www.khronos.org/opengl/wiki/Platform_specifics:_Windows#wglGetProcAddress) (GL Wiki)

If you don't, wglGetProcAddress() will return NULL. wglGetProcAddress requires an active context.

Once you get the wglCreateContextAttribsARB function pointer, you can delete the old context and create a new context with that function pointer.