1
Graphics / drawing Sprite from RenderTexture
« on: January 06, 2012, 09:19:53 pm »
oh ... thx for the answer. I thought that there is a bug or I am doing somethong wrong
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.
#include <SFML/Graphics.hpp>
int main()
{
sf::RenderWindow window(sf::VideoMode(800, 600), "SFML window");
sf::RenderTexture texture;
texture.Create(800,600);
texture.Clear(sf::Color::Red);
sf::RectangleShape shape(sf::Vector2f(50,50));
shape.SetFillColor(sf::Color::Blue);
shape.SetOrigin(25,25);
shape.SetPosition(400,300);
texture.Draw(shape);
texture.Display();
while (window.IsOpened())
{
sf::Event event;
while (window.PollEvent(event))
if (event.Type == sf::Event::Closed)
window.Close();
window.Clear();
sf::Sprite s(texture.GetTexture());
//s.GetTexture()->CopyToImage().SaveToFile("file.png");
window.Draw(s);
window.Display();
}
return 0;
}
...
if (sf::Shader::IsAvailable())
{
shader.LoadFromFile("default.frag");
std::string texName("tex");
shader.SetTexture(texName, image);
shader.SetCurrentTexture(texName);
}
...
uniform sampler2D tex;
void main(void)
{
vec4 curColor = texture2D(tex, gl_TexCoord[0].xy);
vec4 shadow = vec4(0.5, 0.5, 0.5, 1.0);
if (curColor.r == 0.0f && curColor.g == 0.0f && curColor.b == 1.0f)
gl_FragColor = shadow;
else
gl_FragColor = curColor;
}
#include <SFML/Audio.hpp>
#include <SFML/Graphics.hpp>
int main()
{
sf::RenderWindow window(sf::VideoMode(800, 600), "SFML window");
sf::Shape shape = sf::Shape::Rectangle(400,300,100,100,sf::Color(0,0,255));
sf::Shader shader;
sf::Image image;
if (sf::Shader::IsAvailable())
shader.LoadFromFile("shader.frag");
while (window.IsOpened())
{
sf::Event event;
while (window.PollEvent(event))
{
if (event.Type == sf::Event::Closed)
window.Close();
}
window.Clear(sf::Color(0,0,0));
window.Draw(shape);
if (sf::Shader::IsAvailable())
{
image.CopyScreen(window);
window.Draw(sf::Sprite(image), shader);
}
window.Display();
}
return EXIT_SUCCESS;
}
void main(void)
{
vec4 shadow = vec4(0.5, 0.5, 0.5, 0.5);
if (gl_Color.r == 0.0f && gl_Color.g == 0.0f && gl_Color.b == 1.0f)
gl_FragColor = shadow;
else
gl_FragColor = gl_Color;
}