Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

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.


Messages - sormo

Pages: [1]
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

2
Graphics / drawing Sprite from RenderTexture
« on: January 06, 2012, 07:18:09 pm »
I have strange behaviour while drawing sprite made from RenderTexture. I just create a RenderTexture with red background, draw a blue rectangle in the center and then I draw it on the RenderWindow.
Window is red, like a sprite is being drawn but blue rectangle is missing.
When I check the sprite saving it to a file, the blue rectangle is there.
I don't understand why is this happening that only red color of background is being drawn on the window.
btw I have onboard intel graphic card.
Code: [Select]

#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;
}

3
Graphics / Question about shader sfml2
« on: July 11, 2011, 12:29:00 pm »
Thank you for reply. With those modifications it works:

Code: [Select]

...
    if (sf::Shader::IsAvailable())
    {
        shader.LoadFromFile("default.frag");
        std::string texName("tex");
        shader.SetTexture(texName, image);
        shader.SetCurrentTexture(texName);
    }
...

shader:
Code: [Select]

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;
}

4
Window / RenderTarget::Clear segmentation fault
« on: July 01, 2011, 12:06:24 pm »
You are right. My mistake. :oops: I have changed libraries but did not updated include files.  It's working now.

5
Window / RenderTarget::Clear segmentation fault
« on: June 30, 2011, 08:45:45 am »
Hello,
I am using sfml2 for some time. Yesterday I have decided to build new libraries from snapshot with number f9435eb. I have used cmake to generate codeblocks project and build static libraries (codeblocks mingw). After rebuild of my project with new libraries application crashes with segmentation fault in RenderTarget::Clear when trying to call pure virtual method Activate() on line 59. I have tried tutorial project and it crashes also. sf::RenderWindow is instantiated on stack, but when it goes into Clear it crashes.  :(
Looks like my libraries are not build correctly, but I don't know why. I have build previous libraries same way and they work.
Does anyone know where can be the problem?

6
Graphics / Question about shader sfml2
« on: June 26, 2011, 12:31:21 pm »
Hello,
I have question about using fragment shader in sfml 2. I am trying to apply shader to whole screen and replace one particular color with different one.
This is my code:
Code: [Select]

#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;
}

Here is my fragment shader:
Code: [Select]

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;
}

When I do not apply shader, screen is black with blue square, but when I paint screen with shader, all pixels are white. There are no error messages on console so looks like shader is compiled succesfully. For some reason rgb values of gl_Color is set to 1. Can someone please tell me what am I doing wrong?

Pages: [1]