hello_imgui icon indicating copy to clipboard operation
hello_imgui copied to clipboard

glDebugMessageCallback not working

Open cone-forest opened this issue 11 months ago • 3 comments
trafficstars

Hi there!

I've been implementing simple 2D graphics editor using OpenGL and encountered a problem when using glDebugMessageCallback. On linux calling glDebugMessageCallback causes linker errors since GLAD lib is located both in ImmVision and HelloImGui. On windows calling glDebugMessageCallback causes segfault since glDebugMessageCallback is nullptr.

It is called in PostInit callback. Everything else OpenGL-related works fine, only the glDebugMessageCallback causes troubles. Is there a convenient way of enabling it?

The code can be found here: https://github.com/2b1g1c/my-paint/blob/core/rnd/src/app/app.cpp

cone-forest avatar Nov 26 '24 21:11 cone-forest

On linux calling glDebugMessageCallback causes linker errors since GLAD lib is located both in ImmVision and HelloImGui.

This is solved with this commit which changes the way glad is build (and now built only once. My bad!):

See

pthom avatar Dec 02 '24 14:12 pthom

Please please, when submitting issues, do include a minimal reproducible example. I had to do it for you in this case:

#include "imgui.h"
#include "hello_imgui/hello_imgui.h"
#include "immapp/immapp.h"
#include "hello_imgui/hello_imgui_include_opengl.h"

void glDebugOutput(
    std::uint32_t source, std::uint32_t type,
    std::uint32_t id, std::uint32_t severity,
    int length, const char *message,
    const void *userparam);

void gui()
{
    ImGui::Text("Hello, world!");
}


int main(int, char **)
{
    ImmApp::AddOnsParams addonsParams;
    HelloImGui::RunnerParams _runner_params;

    _runner_params.fpsIdling.enableIdling = false; // disable idling so that the shader runs at full speed
    _runner_params.appWindowParams.windowGeometry.size = {4000, 2000};
    _runner_params.appWindowParams.windowTitle = "CGSGFOREVER";
    // Do not create a default ImGui window, so that the shader occupies the whole display
    _runner_params.imGuiWindowParams.defaultImGuiWindowType = HelloImGui::DefaultImGuiWindowType::NoDefaultWindow;
    // PostInit is called after the ImGui context is created, and after OpenGL is initialized
    _runner_params.callbacks.PostInit = [&]() {
        glEnable(GL_SCISSOR_TEST);
        glClearColor(1, 1, 1, 1);
        glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS);
        glDebugMessageCallback(glDebugOutput, NULL);
    };
    _runner_params.callbacks.ShowGui = [&]() { gui(); }; // ShowGui is called every frame, and is used to display the ImGui widgets

    addonsParams.withMarkdown = true;

    ImmApp::Run(_runner_params, addonsParams);
}


// Disable sprintf warnings on MSVC, clang, and GCC
#pragma warning(disable : 4996)
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#pragma clang diagnostic ignored "-Wdeprecated-declarations"

void glDebugOutput(std::uint32_t source, std::uint32_t type,
                            std::uint32_t id, std::uint32_t severity,
                            int length, const char *message,
                            const void *userparam)
{
    int len = 0;
    static char Buf[10'000];

    len += sprintf(Buf + len, "Debug message (%i) %s\n", id, message);
    switch (source)
    {
        case GL_DEBUG_SOURCE_API:
            len += sprintf(Buf + len, "Source: API\n");
            break;
        case GL_DEBUG_SOURCE_WINDOW_SYSTEM:
            len += sprintf(Buf + len, "Source: Window System\n");
            break;
        case GL_DEBUG_SOURCE_SHADER_COMPILER:
            len += sprintf(Buf + len, "Source: Shader Compiler\n");
            break;
        case GL_DEBUG_SOURCE_THIRD_PARTY:
            len += sprintf(Buf + len, "Source: Third Party\n");
            break;
        case GL_DEBUG_SOURCE_APPLICATION:
            len += sprintf(Buf + len, "Source: Application");
            break;
        case GL_DEBUG_SOURCE_OTHER:
            len += sprintf(Buf + len, "Source: Other");
            break;
    }
    len += sprintf(Buf + len, "\n");

    switch (type)
    {
        case GL_DEBUG_TYPE_ERROR:
            len += sprintf(Buf + len, "Type: Error");
            break;
        case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR:
            len += sprintf(Buf + len, "Type: Deprecated Behaviour");
            break;
        case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR:
            len += sprintf(Buf + len, "Type: Undefined Behaviour");
            break;
        case GL_DEBUG_TYPE_PORTABILITY:
            len += sprintf(Buf + len, "Type: Portability");
            break;
        case GL_DEBUG_TYPE_PERFORMANCE:
            len += sprintf(Buf + len, "Type: Performance");
            break;
        case GL_DEBUG_TYPE_MARKER:
            len += sprintf(Buf + len, "Type: Marker");
            break;
        case GL_DEBUG_TYPE_PUSH_GROUP:
            len += sprintf(Buf + len, "Type: Push Group");
            break;
        case GL_DEBUG_TYPE_POP_GROUP:
            len += sprintf(Buf + len, "Type: Pop Group");
            break;
        case GL_DEBUG_TYPE_OTHER:
            len += sprintf(Buf + len, "Type: Other");
            break;
    }
    len += sprintf(Buf + len, "\n");

    switch (severity)
    {
        case GL_DEBUG_SEVERITY_HIGH:
            len += sprintf(Buf + len, "Severity: high");
            break;
        case GL_DEBUG_SEVERITY_MEDIUM:
            len += sprintf(Buf + len, "Severity: medium");
            break;
        case GL_DEBUG_SEVERITY_LOW:
            len += sprintf(Buf + len, "Severity: low");
            break;
        case GL_DEBUG_SEVERITY_NOTIFICATION:
            len += sprintf(Buf + len, "Severity: notification");
            break;
    }
    len += sprintf(Buf + len, "\n\n");

    std::cout << Buf;
}

pthom avatar Dec 02 '24 15:12 pthom

Concerning your issue where glDebugMessageCallback is not available, you may have to regenerate the glad bindings: https://glad.dav1d.de/

.. and activate the required debug extension and place them in hello_imgui/external/OpenGL_Loaders/glad

pthom avatar Dec 02 '24 15:12 pthom

Closing for lack of activity

pthom avatar Jun 24 '25 20:06 pthom