0
\$\begingroup\$

I try enable debug system in OpenGL with helps debug output in OpenGL version >= 4.3. My code:

void GLAPIENTRY glDebugOutput(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar* message, const void* userParam)
{

}

int main()
{
    glfwInit();
    GLFWwindow* window = glfwCreateWindow(800, 600, "TestGL", nullptr, nullptr);
    glfwMakeContextCurrent(window);
    glfwSetKeyCallback(window, key_callback);
    glewExperimental = GL_TRUE;
    glewInit();
    int width, height;
    glfwGetFramebufferSize(window, &width, &height);
    glViewport(0, 0, width, height);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 4);
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
    glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);

    std::cout << glGetString(GL_VERSION) << std::endl;
#if defined(DEBUG) | defined(_DEBUG)
    glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GL_TRUE);
    GLint flags;
    glGetIntegerv(GL_CONTEXT_FLAGS, &flags);
    if (flags & GL_CONTEXT_FLAG_DEBUG_BIT)
    {
        glEnable(GL_DEBUG_OUTPUT);
        glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS);
        glDebugMessageCallback(glDebugOutput, nullptr);
        glDebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, nullptr, GL_TRUE);
    }
    else
        std::cout << "Debug for OpenGL not supported by your system!" << std::endl;
#endif

   ...... // etc
}

My output from console:

4.5.0 - Build 24.20.100.6286
Debug for OpenGL not supported by your system!

I don’t understand why the debugging tools do not work, because the OpenGL version matches the necessary one. Thanks.

\$\endgroup\$
1
  • \$\begingroup\$ First give the hints, then create the window. \$\endgroup\$
    – user136710
    Commented Mar 14, 2020 at 22:35

1 Answer 1

2
\$\begingroup\$

You create a window with default hints and context. See glfw documentation.

Solution: first give the hints, then create the window.

 glfwInit();
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 4);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);
glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GL_TRUE);
GLFWwindow* window = glfwCreateWindow(800, 600, "TestGL", NULL, NULL);
glfwMakeContextCurrent(window);
// init glew
GLint flags;
glGetIntegerv(GL_CONTEXT_FLAGS, &flags);
if (flags & GL_CONTEXT_FLAG_DEBUG_BIT)
{
    glEnable(GL_DEBUG_OUTPUT);
    glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS);
    glDebugMessageCallback(glDebugOutput, NULL);
    glDebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, NULL, GL_TRUE);
    puts( "Debug" );
}
else
    puts( "Debug for OpenGL not supported by your system!" );
\$\endgroup\$
1
  • \$\begingroup\$ Thanks. I found this info, but you are ahead of me :) \$\endgroup\$
    – Range
    Commented Mar 14, 2020 at 22:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .