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

Pages: [1]
1
Graphics / Mixing shaders
« on: January 05, 2011, 03:57:30 pm »
If nothing can be done, I can actually put all the effects in one shader file, but I guess it should be possible to re-draw objects to RenderImages several times but with different shaders.

Here is the minimal code (I hope):
Code: [Select]

#include <SFML/Graphics.hpp>
#include <iostream>

std::string pixelate = "uniform sampler2D texture;\
uniform vec2 mouse;\
\
void main()\
{\
float factor = 5 + 100 * length(mouse);\
vec2 pos = floor(gl_TexCoord[0].xy * factor + 0.5) / factor;\
\
gl_FragColor = texture2D(texture, pos) * gl_Color; \
}\
";

std::string colorize = "\
uniform sampler2D texture;\
uniform vec3 color;\
\
void main()\
{\
vec4 pixel = texture2D(texture, gl_TexCoord[0].xy) * gl_Color;\
float gray = pixel.r * 0.39 + pixel.g * 0.50 + pixel.b * 0.11;\
\
gl_FragColor = vec4(gray * color, 1.0) * 0.6 + pixel * 0.4;\
gl_FragColor.a = pixel.a;\
}\
";

int main()
{
sf::RenderWindow window(sf::VideoMode(800, 600), "SFML Shader");

// Load a background image to display
    sf::Shape Circle = sf::Shape::Circle(400, 300, 100, sf::Color::White);

    sf::Shader shaders[2];
    shaders[0].LoadFromMemory(pixelate.c_str());
    shaders[1].LoadFromMemory(colorize.c_str());

    shaders[0].SetTexture("texture", sf::Shader::CurrentTexture);
    shaders[1].SetTexture("texture", sf::Shader::CurrentTexture);
    shaders[1].SetParameter("color", 1.f, 1.f, 1.f);

    sf::RenderImage rim, buffer;
    rim.Create(800, 600);
    buffer.Create(800, 600);

    sf::RenderImage *front = &rim;
    sf::RenderImage *back = &buffer;

    // Start the game loop
    while (window.IsOpened())
    {
        // Process events
        sf::Event event;
        while (window.GetEvent(event))
        {
            // Close window : exit
            if (event.Type == sf::Event::Closed)
                window.Close();
        }

        shaders[1].SetParameter("color", (1.0f / window.GetInput().GetMouseX()) * 800.0f, 1.0f, 1.0f);
shaders[0].SetParameter("mouse", (float)window.GetInput().GetMouseX() / static_cast<float>(window.GetWidth()), (float)window.GetInput().GetMouseY() / static_cast<float>(window.GetHeight()));

        window.Clear();

back->Clear();
        back->Draw(Circle);
        back->Display();

for ( int i = 0; i < 2; i++)
{
front->Clear();
front->Draw(sf::Sprite(back->GetImage()), shaders[i]);
front->Display();

std::swap(front, back);
}

sf::Sprite test(back->GetImage());

        window.Draw(test);

        // Finally, display the rendered frame on screen
        window.Display();
    }
}



The last shader's parameter is not updated (?) Actually this looks like a different problem.

2
Graphics / Mixing shaders
« on: January 05, 2011, 01:05:09 pm »
Hello,

I have come upon a problem with applying several shaders to an image.
What I'm currently doing is I'm drawing all the necessary stuff to a RenderImage, and then I keep copying it to image, and drawing again with a different shader.

The main loop code:
Code: [Select]

window.Clear();

rim.Clear();
rim.Draw(background);
rim.Display();

RenderToImage(rim);
sf::Sprite test(rim.GetImage());
window.Draw(test);


RenderToImage function:
Code: [Select]

void CEffectManager::RenderToImage(sf::RenderImage &_renderimage)
{
std::list<CBaseEffect*>::iterator it = m_Effects.begin();

for ( ; it != m_Effects.end(); it++)
{
m_CopyImage = _renderimage.GetImage();

_renderimage.Clear();
_renderimage.Draw(sf::Sprite(m_CopyImage), *(*it));

_renderimage.Display();
}
}


The problem is only one shader will apply. Each of the shaders work.
I tried searching the forums but couldn't find any solution (or maybe I searched too little?). What might be wrong?

Thanks in advance

3
Graphics / Program crashes when LMB is pressed
« on: October 09, 2010, 03:04:35 pm »
I guess the problem is here:

Code: [Select]
CBullet bullet(SPRPlayer.GetPosition().x, SPRPlayer.GetPosition().y, SPRPlayer.GetRotation());
         CLKShoot.Reset();
      }


The bullet is being pushed back to your list/vector, but it's destroyed - goes out of scope.

Try doing something like

Code: [Select]
CBullet *bullet = new CBullet(SPRPlayer.GetPosition().x, SPRPlayer.GetPosition().y, SPRPlayer.GetRotation());

don't forget about deleting it somewhere later.

4
Graphics / [solved] sf::Shape::Line SetPointPosition problem
« on: November 22, 2009, 02:46:11 pm »
Thanks for claryfying:) The problem is now solved.

5
Graphics / [solved] sf::Shape::Line SetPointPosition problem
« on: November 22, 2009, 01:38:37 pm »
Hello!:) I am quite new to SFML, I've been working with it for a few weeks already, and I must say it is a great library, thank you Laurent.

However, I couldn't find a solution to this problem:
Code: [Select]
sf::Shape Line = sf::Shape::Line(100, 100, 100, 200, 1, sf::Color::White);
Line.SetPointPosition(0, sf::Vector2f(100, 100));
Line.SetPointPosition(1, sf::Vector2f(100, 400));


Setting the points of a line doesn't work as supposed, or maybe I'm just doing it wrong?

Pages: [1]
anything