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 - addel

Pages: [1] 2
1
Graphics / Re: Use multiple shaders on same sprite?
« on: June 30, 2013, 11:32:23 pm »
From other languages vector is used to store 2 values like a xy point but in C++ it is used as a array? Also i don't understand how i fill it with shaders as you don't give a example and looking at the tutorials i can only see shaders being applied by window.draw().

I also don't understand what is happening with the "sf::RenderTexture* front = &image1;" part but as a guess it looks like the RenderTexture's are being duplicated with a new name? I have not yet learned what the * or & symbols are doing and i am also not sure what the point of renaming it is either. Then there is the for loop on a 2 point thing to swap and combine them but what if the stack was more than 2 shaders?

So i don't really understand it. I tried to add in the missing parts to the code but am getting errors.

// Create a Texture
sf::Texture Texture001;
if (!Texture001.loadFromFile("assets/background.jpg")) { return EXIT_FAILURE; }
sf::Sprite Sprite001(Texture001); // Create a Sprite from the Texture

std::vector<sf::Shader> shaders; // we assume it is already filled

sf::RenderTexture image1;
sf::RenderTexture image2;

// Draw sprite into RenderTexture????
image1.draw(Sprite001);
image2.draw(Sprite001);

sf::RenderTexture* front = &image1;
sf::RenderTexture* back = &image2;

// draw the initial scene into "back"

// Apply Fragment Shader
if (sf::Shader::isAvailable()) {
    // Create the shader
    sf::Shader shader;

    // Load Fragment shader
    if (shader.loadFromFile("assets/pixelate.frag", sf::Shader::Fragment)){
        float x = static_cast<float>(sf::Mouse::getPosition(window).x) / window.getSize().x;
        shader.setParameter("pixel_threshold", x/10);
        // Draw shader in to back????
        window.draw(back, &shader);
    }
}

for (std::vector<sf::Shader>::iterator it = shaders.begin(); it != shaders.end(); ++it) {
    // draw "back" into "front"
    front->clear();
    front->draw(sf::Sprite(back->getTexture()), &*it);
    front->display();

    // swap front and back buffers
    std::swap(back, front);
}

// Apply Fragment Shader
if (sf::Shader::isAvailable()) {
    // Create the shader
    sf::Shader shader2;

    // Load Fragment shader
    if (shader2.loadFromFile("assets/blur.frag", sf::Shader::Fragment)){
        float x = static_cast<float>(sf::Mouse::getPosition(window).x) / window.getSize().x;
        shader2.setParameter("blur_radius", x* 0.01f);
        // Draw 2nd shader in to back????
        window.draw(back, &shader2);
    }
}

2
Graphics / Re: Use multiple shaders on same sprite?
« on: June 30, 2013, 12:58:42 am »
It gives the same NonCopyable error unfortunately. I am also confused as to how you apply the shaders with this method, in that code globalShaders is no doubt a array of shader which i am not sure how to make but i don't know.

I am just a C++ noob having started only last week but i am surprised nobody has done shader stacking already as it seems like a very useful thing. I know i could make a single fragment shader with both the pixelate and blur packed together but that is not very efficient, a stack of shaders would be much better but right now i am totally stuck with this. :(

3
Graphics / Re: Use multiple shaders on same sprite?
« on: June 29, 2013, 10:40:22 pm »
I don't understand how to port the C# to C++ code or link the sf::RenderTexture with my original code. In that code it looks like back would be the sprite but i don't know what globalShaders is? Maybe like a shader array?

Could someone post a very simple code if possible please.

I try this in codeblocks but get a error about NonCopyable whatever that means.

sf::RenderTexture image1;
sf::RenderTexture image2;

sf::RenderTexture front = image1;
sf::RenderTexture back = image2;

if (sf::Shader::isAvailable()) {
foreach (sf::Shader shader in globalShaders) {
    // draw "back" into "front"
    front.Clear();
    front.Draw(new Sprite(back.Image), shader);
    front.Display();

    // swap front and back buffers
    sf::RenderTexture temp = front;
    front = back;
    back = temp;
}
}

4
Graphics / Re: Use multiple shaders on same sprite?
« on: June 29, 2013, 10:21:43 pm »
The two solutions are very different, so what do you want exactly? Apply effects separately and blend the results, or apply one effect after the other?

I want to apply them one effect after the other.

5
Graphics / Re: Use multiple shaders on same sprite?
« on: June 29, 2013, 08:07:13 pm »
That sounds great but how do you use them in this way? I cannot find much information about blend modes.

It seems like i need sf::Blend::Add yet i have no idea how to use that with Sprite. I always thought a blend mode with add means the graphics get lighter though so i am kind of confused by what you mean.

Does anyone have a simple code example if possible?

6
Graphics / Re: Use multiple shaders on same sprite?
« on: June 29, 2013, 06:07:24 pm »
I still haven't found a solution yet. According to the shader tutorial you apply the shader with the "window.draw(Sprite001, &shader);" part however it seems to overwrite the last shader when you use that multiple times. Hopefully there is a alternative to using draw or a way to use many shaders in a single draw?

Maybe this old post will help you : http://en.sfml-dev.org/forums/index.php?topic=4799.0

Thanks but the code Laurent posted is not recognizing "RenderImage" which i guess must be something from SFML1 however i am currently using SFML2 so that code does not seem to work for me. I am not familiar with V1 or the differences between the versions so i have no idea how to update the code but it looks as if it probably works for V1 projects.

What I find it that you are missing is probably a proper blend mode. Though it depends on the effect you want. Do you want to blur only the result from the first draw call with the first shader? Or is the blur shader somehow independent of the result of the first shader?

Edit: Since you have only the default blend mode, the previous data will be overwritten, what you would need to do is either use a blend mode that will preserve the old data and apply the new data. Or you render the sprite to a render texture first, and then use that texture as input for the second texture.

I am not sure how to do this do you have a simple example if possible? i have not tested blend modes just yet. I was only using blur and pixelate as a test really but it could be any shaders and more than just 2 like i had in my code.

Usually when i code i start with simple examples like here and once they are working build them into a bigger project and expand on them. Basically my goal here however is just to be able to stack any amount shaders on the same image.

7
Graphics / Use multiple shaders on same sprite?
« on: June 28, 2013, 11:00:52 pm »
I am having a problem when i try to apply 2 different fragment shaders to the same sprite. What currently happens is it just uses the second filter only rather than both of them.

        // Apply Fragment Shader
        if (sf::Shader::isAvailable()) {
            // Create the shader
            sf::Shader shader;
            sf::Shader shader2;

            // Load Fragment shader
            if (shader.loadFromFile("assets/pixelate.frag", sf::Shader::Fragment)){
                float x = static_cast<float>(sf::Mouse::getPosition(window).x) / window.getSize().x;
                shader.setParameter("pixel_threshold", x/10);
                window.draw(Sprite001, &shader);
            }

            // Load Fragment shader
            if (shader2.loadFromFile("assets/blur.frag", sf::Shader::Fragment)){
                float x = static_cast<float>(sf::Mouse::getPosition(window).x) / window.getSize().x;
                shader2.setParameter("blur_radius", x* 0.008f);
                window.draw(Sprite001, &shader2);
            }
        }

Is it possible to stack/use multiple GLSL shaders?

8
General / Re: Change Rotation Point?
« on: June 28, 2013, 07:58:54 pm »
Thanks FRex :D

9
General / Change Rotation Point?
« on: June 28, 2013, 07:37:20 pm »
I am trying to rotate a sf::Sprite however it rotates using the top left point of the sprite however i need to rotate using the center point.

How can i change the rotation point of a sprite?

10
General / Re: Questions After Reading Tutorials
« on: June 20, 2013, 08:03:17 pm »
Thanks for the help Laurent, this answers everything i had been wondering recently. SFML and the community here is great :D

11
General / Questions After Reading Tutorials
« on: June 20, 2013, 07:26:25 pm »
Hi, i have been learning C++ and SFML and have been wondering a few things.

1) In the event tutorials the code
sf::Event event;
gets placed inside of the
while (window.isOpen()) {
loop but wouldn't this mean is is created many times? I would have expected it to get added after the RenderWindow was made at the top.

2) Also in the examples it uses sf:: but can this be removed with a "using namespace" so something like
sf::Text text("Hi", font);
would then be
Text text("Hi", font);
When i have used this with some simple examples for std:: i think doing that made the code seem simpler. Does it remain in the examples to help avoid name conflicts or something?

3) I notice that with C++ i can't just combine a string and int ("Hello" + 123 etc) which is simple with many other programming languages, i figured out the solution by using ostringstream however it then made what is normally a 1 line of code into about 4 instead.

For example i was originally expecting this type of code to work -

// Mouse wheel moved
        if (event.type == sf::Event::MouseWheelMoved) {
            text.setString("Mouse wheel moved" + event.mouseWheel.delta);
        }

but it seems to instead cut off letters like it's a substring.

So i fix it with -

if (event.type == sf::Event::MouseWheelMoved) {
            ostringstream d; d << event.mouseWheel.delta;
            text.setString("Mouse wheel moved " + d.str());
        }

So for more complex things you then need to use more code. I looked in the string class reference but didn't notice anything, does SMFL have any simple way/function to do this?

Thanks

12
General / Re: Screen flickering on other computer
« on: June 17, 2013, 01:56:16 pm »
I have fixed it, i forgot that since it's a loop i only need to use this code -

window.clear();
window.draw(text);

once at the end. So i removed those lines from each event and there is no more flickering on my other computer now. Thanks

13
General / Re: Screen flickering on other computer
« on: June 17, 2013, 01:45:15 pm »
Edit - I have fixed it now :D

14
General / Re: Screen flickering on other computer
« on: June 17, 2013, 12:39:52 pm »
I updated my code and thought maybe to make a update function instead of using the same commands also but i am getting errors as my C++ skills are poor currently. I am planning to learn C++ code by using SFML. :)

Here was my failed function code -

    void update (string status) {
        window.clear();
        text.setString(status);
        window.draw(text);
    }
 

which gives me warnings like "error: a function-definition is not allowed here before '{' token"

Do you have a example of the correct code format if possible?

15
General / Re: Screen flickering on other computer
« on: June 17, 2013, 11:38:48 am »
Unfortunately using

window.setVerticalSyncEnabled(true);

does not seem to fix the flickering problem :(

I placed the line of code under

sf::RenderWindow window(sf::VideoMode(640, 480), "SFML App");

Pages: [1] 2