SFML community forums

Help => Window => Topic started by: najdorf on August 30, 2023, 10:26:47 am

Title: testing opengl/sfml application
Post by: najdorf 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?

TEST_CASE("Shader")
{
    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);
}
Title: Re: testing opengl/sfml application
Post by: Hapax 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.
Title: Re: testing opengl/sfml application
Post by: eXpl0it3r 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