16
SFML website / Re: Old Threads?
« on: April 12, 2012, 07:50:58 am »
Works perfect! Good Job!
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
I don't know how to translate them to the new forum URLs.
The top-left corner of the view is at (400, 400). Your sprite is at (400, 400). So your sprite is on the top-left corner
view.SetViewport(sf::FloatRect(sprite.GetPosition().x, sprite.GetPosition().y, 64, 64)); // 64 = Width and Height of Sprite
view.SetViewport(sf::FloatRect(0, 0, 64, 64)); // 64 = Width and Height of Sprite
// 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);
void main(void)
{
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
}
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);
}