Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: How to create a window with debugging context?  (Read 954 times)

0 Members and 1 Guest are viewing this topic.

Eugene

  • Newbie
  • *
  • Posts: 6
    • View Profile
How to create a window with debugging context?
« on: March 17, 2025, 01:47:26 pm »
When using the GLFW library, for example, a debug context can be created with a single call:

glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GL_TRUE);

This is necessary for glDebugMessageCallback to work correctly (I use OpenGL version 4.6 (core profile) without plugging in the sfml-graphics module, defining the sf::ContextSettings myself).
Callback does not work for error level messages, although with GLFW everything works. I suspect that this is due to extensions that need to be plugged in independently (namely GL_KHR_debug). How do I do this correctly? It is very convenient to work with SFML, I would not like to go back to GLFW because of such trifles.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11173
    • View Profile
    • development blog
    • Email
Re: How to create a window with debugging context?
« Reply #1 on: March 17, 2025, 03:06:39 pm »
You set it the same way you would set the core context.

For example like this (untested code):
auto context = sf::ContextSettings{0, 0, 0, 4, 6, sf::ContextSettings::Attribute::Core | sf::ContextSettings::Attribute::Debug, false};
Official FAQ: https://www.sfml-dev.org/faq/
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Eugene

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: How to create a window with debugging context?
« Reply #2 on: March 17, 2025, 07:04:31 pm »
Thank you for your reply.
No, that didn't solve the problem. Example: with GLFW, activating the debug context, and calling glUseProgram(0); (turning off the shaders altogether), I get debug output about it as an error. With SFML - only warnings not related to this error at all (buffers state and so on).

I set sf::ContextSettings like this:
    sf::ContextSettings settings;
    settings.majorVersion = 4;
    settings.minorVersion = 6;
    settings.depthBits = 24;
    settings.stencilBits = 8;
    settings.antialiasingLevel = 4;
    settings.attributeFlags = sf::ContextSettings::Core | sf::ContextSettings::Debug;
« Last Edit: March 17, 2025, 07:06:26 pm by Eugene »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11173
    • View Profile
    • development blog
    • Email
Re: How to create a window with debugging context?
« Reply #3 on: March 17, 2025, 07:15:41 pm »
SFML already wraps all internal OpenGL calls in glGetError and consumes them. I don't know what takes priority with the callback, but it might cause unwanted conflicts.

See also: https://github.com/SFML/SFML/blob/master/src/SFML/Graphics/GLCheck.cpp
Official FAQ: https://www.sfml-dev.org/faq/
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Eugene

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: How to create a window with debugging context?
« Reply #4 on: March 18, 2025, 06:08:41 am »
I don't use the sfml-graphics module, I don't even compile it. My CMakeLists.txt:

...
set(SFML_BUILD_GRAPHICS OFF CACHE BOOL "" FORCE)
set(SFML_BUILD_AUDIO OFF CACHE BOOL "" FORCE)
set(SFML_BUILD_NETWORK OFF CACHE BOOL "" FORCE)
...

I also use glad to initialize OpenGL functions on my own. I am probably missing checking and initializing some OpenGL extension

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11173
    • View Profile
    • development blog
    • Email
Re: How to create a window with debugging context?
« Reply #5 on: March 18, 2025, 11:29:39 am »
The fact that you're getting warnings means, that the debug context is active.

glUseProgram(0) alone shouldn't necessarily trigger an error.

Can you post your GLFW and SFML code?
Official FAQ: https://www.sfml-dev.org/faq/
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Eugene

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: How to create a window with debugging context?
« Reply #6 on: March 18, 2025, 04:41:47 pm »
I found the problem :).
It was that in a project with SFML I use advanced shaders that access transform matrices from GL_UNIFORM_BUFFER.
In the GLFW project, on the other hand, I was using shaders where the matrices were sent directly to the shader program every iteration of the game loop by calling glUniformMatrix4fv.
It was calling this function with the shaders disabled that caused the debug callback to trigger and I would get error messages.
Thank you for your help!

 

anything