From fbb394e92f933daf8c4a1f3194723e8f908715ca Mon Sep 17 00:00:00 2001 From: Bruno Van de Velde Date: Mon, 20 May 2024 10:40:47 +0200 Subject: [PATCH] sf::Shader no longer has default constructor in SFML3 --- tests/Texture.cpp | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/tests/Texture.cpp b/tests/Texture.cpp index d3062db12..b6e42518b 100644 --- a/tests/Texture.cpp +++ b/tests/Texture.cpp @@ -258,26 +258,38 @@ TEST_CASE("[Texture]") tgui::Texture texture{"resources/Texture6.png"}; REQUIRE(!texture.getShader()); +#if SFML_VERSION_MAJOR < 3 sf::Shader shader; texture.setShader(&shader); REQUIRE(texture.getShader() == &shader); texture.setShader(nullptr); REQUIRE(!texture.getShader()); +#endif SECTION("Draw") { - (void)shader.loadFromMemory(R"( + const char* vertexShaderStr = R"( void main() { gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0; gl_FrontColor = gl_Color; - })", R"( + })"; + const char* fragmentShaderStr = R"( uniform sampler2D texture; void main() { gl_FragColor = gl_Color * texture2D(texture, gl_TexCoord[0].xy) * vec4(0.7, 1.0, 0.0, 1.0); - })"); + })"; + +#if SFML_VERSION_MAJOR >= 3 + auto shader = sf::Shader::loadFromMemory(vertexShaderStr, fragmentShaderStr); + REQUIRE(shader); + texture.setShader(&shader.value()); + REQUIRE(texture.getShader() == &shader.value()); +#else + (void)shader.loadFromMemory(vertexShaderStr, fragmentShaderStr); texture.setShader(&shader); +#endif auto widget = CustomWidgetWithSFMLShader::create(); widget->sprite.setTexture(texture);