Skip to content

Commit

Permalink
sf::Shader no longer has default constructor in SFML3
Browse files Browse the repository at this point in the history
  • Loading branch information
texus committed May 20, 2024
1 parent 6dfde46 commit fbb394e
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions tests/Texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit fbb394e

Please sign in to comment.