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

Pages: [1]
1
Graphics / Re: Using a shader with an array of sf:Vertex
« on: June 18, 2013, 04:39:40 am »
Guess I'm out of luck then. Hopefully the workaround won't cause too much of a performance drop - not that I should be worried about it at this point, and by then maybe I would have a clearer idea of what is it that I'm trying to do design wise. Thanks for the help.  :)

2
Graphics / Re: Using a shader with an array of sf:Vertex
« on: June 17, 2013, 04:25:10 pm »
And I thought this was my biggest clue!
shader.loadFromFile("pixelate.frag", sf::Shader::Fragment);
Well in any case, I'm trying to apply the pixelate effect (from the example) to the vertices without using textures.

3
Graphics / Re: Using a shader with an array of sf:Vertex
« on: June 17, 2013, 11:34:01 am »
Sorry about that. I'm just starting to learn glsl and I mentioned earlier that the shader was directly from the sfml examples. The shader used a texture because that was how the example had it and I'm still trying to wrap my head around how each the vertex and fragment shaders get their inputs. At this point, it seems this is a glsl question, and if you don't mind(since it looks somewhat simple), how would this look like in the shader code?

4
Graphics / Re: Using a shader with an array of sf:Vertex
« on: June 17, 2013, 12:11:46 am »
That was random..
shader.setParameter("texture",sf::Shader::CurrentTexture);

That's what I thought he meant, but it doesn't solve my problem either.
Basically, I'm wondering if I can apply the shader to whatever the vertices are drawing - in this case, the quad with interpolated colors. I think this doesn't work because the colors itself doesn't count as a texture which is why I had to draw it to the screen first, then store that whole image as a texture, create a sprite with that texture, then draw that sprite with the shader.

What I'm wondering is if I can apply a shader directly to the vertices without having to use textures. And if not, is there a way to not use the whole screen and just use the vertices as a texture.

5
Graphics / Re: Using a shader with an array of sf:Vertex
« on: June 16, 2013, 10:56:57 pm »
shader.setCurrentTexture("texture");
I'm not sure I understand this. sf::Shader doesn't seem to have that function.

6
Graphics / Using a shader with an array of sf:Vertex
« on: June 16, 2013, 11:30:21 am »
sf::RenderWindow window(sf::VideoMode(800, 600), "Test");

sf::Vertex vertices[] =
{
        sf::Vertex(sf::Vector2f( 0, 0), sf::Color::Blue),
        sf::Vertex(sf::Vector2f(200, 0), sf::Color::Red),
        sf::Vertex(sf::Vector2f(200, 200), sf::Color::Red),
        sf::Vertex(sf::Vector2f( 0, 200), sf::Color::Yellow),
};

sf::Shader shader;

//the example shader from the SDK
shader.loadFromFile("pixelate.frag", sf::Shader::Fragment);
shader.setParameter("pixel_threshold", .01f);

window.draw(vertices, 4, sf::Quads, &shader);

 
I'm probably not understanding something which is why I'm asking this question. Why doesn't this work?
The only thing that happens to the Quad is that it gets turned all black. I'm thinking it has something to do with textures since:
sf::Texture texture;
texture.create(800,600);
window.draw(vertices, 4, sf::Quads);
texture.update(window);
sf::Sprite sprite(texture);
window.draw(sprite, &shader);
 
this workaround works, but is probably bad since it uses the whole window. texture.update is overloaded, but I have no idea how to change a vertex array to an array of pixels or sf::Image (If it's even the correct way to do this).

This is the shader code just in case:
uniform sampler2D texture;
uniform float pixel_threshold;

void main()
{
    float factor = 1.0 / (pixel_threshold + 0.001);
        vec2 pos = floor(gl_TexCoord[0].xy * factor + 0.5) / factor;
        gl_FragColor = texture2D(texture, pos) * gl_Color;     
}
 

Pages: [1]
anything