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

Author Topic: testing opengl/sfml application  (Read 734 times)

0 Members and 1 Guest are viewing this topic.


  • Newbie
  • *
  • Posts: 2
    • View Profile
testing opengl/sfml application
« on: August 30, 2023, 10:26:47 am »
Hi folks,

I created a template project to develop OpenGL applications. I do window management with SFML/Window.

Let's say I created a "Shader" class, and there is function like "loadFromFile" similar to that of SFML and if this function loads shaders correctly it also calls function to compile shaders.

What approach should I take when I want to test the functions of this shader class?

We know that in order for any OpenGL commands to work, a context must be current. SFML's window class does this for us.

Do I need to create context like below for tests with opengl calls? Or how should I set up a structure for more isolated test codes?

    sf::ContextSettings settings;
    settings.depthBits = 24;
    settings.stencilBits = 8;
    settings.majorVersion = 3;
    settings.minorVersion = 3;

    sf::Window window(sf::VideoMode(800, 600), "OpenGL Context", sf::Style::None, settings);

    Shader shader;

    CHECK(shader.loadFromFile("vertex.glsl", "fragment.glsl") == true);


  • Hero Member
  • *****
  • Posts: 3372
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: testing opengl/sfml application
« Reply #1 on: August 30, 2023, 03:39:22 pm »
The calls should be fine if the context version can use those calls.

But... you should check that the window is actually being created in the required version. If it fails to make the requested version, it'll fall back to a default.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
 *Hapaxia Links*


  • SFML Team
  • Hero Member
  • *****
  • Posts: 10930
    • View Profile
    • development blog
    • Email
Re: testing opengl/sfml application
« Reply #2 on: August 31, 2023, 03:29:15 pm »
You additionally need to run it on a system that can handle OpenGL either through a proper driver or something like Mesa software renderer.
You can see our test suite: https://github.com/SFML/SFML/blob/master/test/Graphics/Shader.test.cpp#L172

Why are you trying to write tests for SFML? :D
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
Dev Blog: https://duerrenberger.dev/blog/