Hello,
I have some problem with implementing shaders and showing these on the Application Window, I'm loading the Shader with this piece of Code:
// The Image Object
sf::Image img;
// Create an Image with the Size of the Window
img.Create(App.GetWidth() + 1, App.GetHeight() + 1);
// The Texture Object
sf::Texture tex;
// Load the Image
tex.LoadFromImage(img);
// The Sprite Object
sf::Sprite sprite;
// Set the Texture
sprite.SetTexture(tex);
// The Shader
sf::Shader sh;
// Load the Shader Files
sh.LoadFromFile("shader.vert", "shader.frag");
// Renderstates Object
sf::RenderStates r;
// Set active Shader
r.Shader = &sh;
// ...
App.Draw(sprite, r);
The Vertex Shader looks like this:
void main(void)
{
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
}
And the Frament Shader looks like this:
uniform float time;
//uniform vec2 mouse;
uniform vec2 resolution;
void main(void)
{
const float stars = 512.0;
const float depth = 512.0;
const float skew = 16.0;
float gradient = 0.0;
float speed = 128.0 * time; //negate to reverse
vec2 pos = (((gl_FragCoord.xy / resolution.xy)) - 0.5) * skew;
vec2 pos_center = pos - vec2(0.5);
for (float i = 1.0; i < stars; i++)
{
//i * i will get a typical starfield effect
float x = sin(i) * 256.0;
float y = cos(i) * 256.0;
float z = mod(i - speed, depth);
vec2 blob_coord = vec2(x, y) / z;
float fade = (depth - z) / 512.0;
gradient += ((fade / depth) / pow(length(pos_center - blob_coord), 1.8));
}
float r = abs(sin(time * 1.13));
float g = abs(sin(time * 2.23));
float b = abs(sin(time * 3.33));
gl_FragColor = vec4(gradient * r, gradient * g, gradient * b, 1.0);
}
I tooked the Frament Shader Code from this Site:
http://glsl.heroku.com/e#1885.0First I thought the Problem is that the Code is for GLSL ES but it seems like the Vertex and Fragment Shader are linked and installed on the GPU sucessfully... and the Problem is that I don't see anything on the Application Window... only a Blackscreen...
I really read all references about GLSL that I found on google, but it seems like that this references all shows the same Shaders as Example that are very complicated and more specially for 3D Stuff and not suitable for beginners.
So I looked for a Site with shaders and found this live Shader Sandbox Site, tooked the Shader and dissassembled the code to understand whats going on, and it works on this Browser Sandbox, but in the SFML Window the Blackscreen stoped me...
I hope you can help me
Thanks in advance!