Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: GL_CONTEXT_FLAG_DEBUG_BIT bit false in Windows Debug context!

  1. #1
    Newbie Newbie
    Join Date
    Aug 2016
    Posts
    3

    GL_CONTEXT_FLAG_DEBUG_BIT bit false in Windows Debug context!

    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:
    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:
    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.

  2. #2
    Newbie Newbie
    Join Date
    Aug 2016
    Posts
    3
    The actual reason why it isn't working is because wglGetProcAddress("wglCreateContextAttribsARB") returns NULL. I have no idea how to fix that.

  3. #3
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    4,087
    Quote Originally Posted by KarimIO View Post
    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 (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.
    Last edited by Dark Photon; 07-17-2017 at 06:32 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •