I was trying to learn how shaders work and found out SFML supports them.. so i made a sample program:
sf::RenderWindow window(sf::VideoMode(1280, 720), "Shaders");
window.setVerticalSyncEnabled(true);
sf::CircleShape circle(30.5f);
circle.setPosition(300.f, 300.f);
circle.setFillColor(sf::Color::Green);
sf::Shader shader;
if(sf::Shader::isAvailable()){
printf("Shaders available");
if (!shader.loadFromFile("fragment_shader.frag",sf::Shader::Fragment))
{
}
}
while (window.isOpen()) {
sf::Event event;
while (window.pollEvent(event)) {
if (event.type == sf::Event::Closed) {
window.close();
}
}
window.clear(sf::Color::Black);
window.draw(circle, &shader);
window.display();
}
This program crashes every time i launch it, but if i change loadFromFile with loadFromMemory ( to wich i now pass the shader saved in a std::string) it works as expected. I have no idea what could cause this and i'm looking for solutions to try out
EDIT: I tried to run the example shader program that comes with sfml. It also crashes when i try to run. I have tried it before and that time it worked so i must have messed something ...
EDIT2: I found a temporary soultion by using loadFromStream() instead of loadFromFile(), minor inconvenience but works well for now.