OK, I recognize that was a bit rush exposition of my problems.
I've ended up with wrong load error handling, on my own.
So, yes, loadFromFile from sf::Shader works perfectly.
Fine but I still can't see the fullscreen sprite-shader because, I guess, using a totally bad vertex shader (it does even load with a TRUE return).
My question:
is this Vertex shader ok with SFML internals in order to render a full screen sprite with a fragment shader as texture? std::string CodiSharedQUADFixe = "void main(void) { gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; }";
sh.loadFromMemory(CodiSharedQUADFixe, sf::Shader::Geometry);
Isolated GLSL :
void main(void) { gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; }
The Sprite-fragment shaded code, a class to render a full screen sized sprite with a fragment-shader texture :
#pragma once
#include <SFML/Graphics.hpp>
#include <list>
#include <iterator>
#include <string>
#include <fstream>
#include <streambuf>
#ifndef FONSFX_H
#define FONSFX_H
#include <SFML/Graphics.hpp>
namespace FonsFX
{
class FonsEfecte
{
private:
sf::Image img;
sf::Texture tex;
bool ShaderGeom_isOk = false;
bool ShaderFrag_isOk = false;
public:
sf::Sprite sprite;
sf::Shader sh;
FonsEfecte(unsigned int Ample, unsigned int Alt) {
img.create(Ample , Alt );
tex.loadFromImage(img);
sprite.setTexture(tex);
//loadFromMemory
//if (sh.loadFromFile("Data/gfx/baseVertex.glsl", sf::Shader::Geometry))
std::string CodiSharedQUADFixe = "void main(void) { gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; }";
if (sh.loadFromMemory(CodiSharedQUADFixe, sf::Shader::Geometry))
ShaderGeom_isOk = true;
if (sh.loadFromFile("Data/gfx/CampDestels.glsl", sf::Shader::Fragment))
ShaderFrag_isOk = true;
}
void UpdateFXvar(std::string FXVarName, sf::Vector2f FXValue)
{
sf::Shader::bind(&sh);
sh.setUniform(FXVarName, FXValue);
}
void UpdateFXvar(std::string FXVarName,float FXValue)
{
sf::Shader::bind(&sh);
sh.setUniform(FXVarName, FXValue);
}
void Render(sf::RenderWindow *window)
{
sf::RenderStates r;
r.shader = &sh;
sf::Shader::bind(&sh);
window->draw(sprite, r);
}
~FonsEfecte() {
}
};
}
#endif
Thanks eXpl0it3r, for the "collaterals" idea. Now I've rebuild a simple alone main() c++, for testing, so now my problems are located in the improper vertex shader, I guess.
#include <SFML/Graphics.hpp>
#include <list>
#include <iterator>
#include <iomanip>
#include <sstream>
#include <string>
#include "FondosFX.h"
int main()
{
sf::RenderWindow window;
window.create(
sf::VideoMode(
640,
480,
32), "PLanet Busters",
sf::Style::None);
window.setVerticalSyncEnabled(true);
window.setFramerateLimit(30);
sf::WindowHandle handle = window.getSystemHandle();
window.setMouseCursorVisible(false);
FonsFX::FonsEfecte *ELFonsDestelsFx;
ELFonsDestelsFx = new FonsFX::FonsEfecte(
window.getSize().x, window.getSize().y);
sf::Clock clock;
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
switch (event.type)
{
case sf::Event::Closed:
window.close();
break;
case sf::Event::KeyPressed:
if (event.key.code == sf::Keyboard::Escape)
{
window.close();
}
}
}
window.clear(sf::Color(180, 180, 180, 255));
ELFonsDestelsFx->UpdateFXvar("time", clock.getElapsedTime().asSeconds());
ELFonsDestelsFx->UpdateFXvar("resolution", sf::Vector2f(window.getSize().x, window.getSize().y));
ELFonsDestelsFx->Render(&window);
window.display();
}
return 0;
}
and the CampDestels.glsl fragment shader file :
uniform float time;
uniform vec2 resolution;
float h(float i){
return fract(pow(3., sqrt(i/2.)));
}
void main(void){
vec2 p=gl_FragCoord.xy*2.-resolution;
float a=floor(degrees(4.+atan(p.y,p.x))*2.)/4.;
float d=pow(2.,-10.*fract(0.1*time*(h(a+.5)*-.1-.1)-h(a)*1000.));
if(abs(length(p)-d*length(resolution)) < d*35.){
gl_FragColor=vec4(d*(h(a+.5)*3.));
}else{
gl_FragColor=vec4(0.);
}
}