Ok, so I am looking into fragment shaders, and I *think* I understand the idea behind it, but I am having difficulty with putting it all together. As in, I am having difficulty figuring out the draw call.
Also, I am unsure if I am even doing the shader correctly, I have no experience with GLSL aside from some research yesterday and today.
What I am trying to do (incorrectly) is, create my vertex array and draw it with a transparency fragment shader.
I have my vertex array drawn like this:
sf::RenderWindow rw;
sf::VertexArray vertexArray;
sf::Texture texture;
//fill in the vertex array
//load the texture
rw.draw(vertexArray, texture);
Now, so far with a fragment shader, this is all I have:
sf::RenderWindow rw;
sf::VertexArray vertexArray;
sf::Texture texture;
sf::Shader transparencyShader;
//fill in the vertex array
//load the texture
//assign our shader
float transparency = 0.5;
transparencyShader.setParameter("color", sf::Color(1.0, 1.0, 1.0, transparency));
//now draw, but how do I add the shader in?
//rw.draw(vertexArray, texture);
Looking through the documentation and other posts, I am under the impression that I would have to draw the vertex array and its texture to a RenderTexture, then hold the shader in a RenderState, and then call draw on the render window with the RenderTexture and RenderState as arguments. However, I am not having much luck with this. The error I am running into is that its not finding a draw call that takes these arguments. However, I feel the problem is more of my understanding of how they all fit together, and then it breaks due to me telling it to behave in ways it doesn't understand
Am I on the right track with this? Also, is it correct for me to just make an sf::Shader and use setParameter() to create my fragment shader, or is it necessary to create it first from GLSL?
Thanks!
Edit:
Found a great example (
http://en.sfml-dev.org/forums/index.php?topic=9767.msg66818#msg66818) and I now have a shader "working", just not as I intended. I suppose it makes sense, based on my shader, just need to read and learn more on GLSL to figure out how to maintain the color (255, 255, 255, transparency?)
const char* fragShaderCode = "void main() { gl_FragColor = vec4(0,0,0,0.1);}";
sf::Shader transparencyShader;
transparencyShader.loadFromMemory(fragShaderCode, sf::Shader::Fragment);
sf::RenderStates renderState;
renderState.shader = transparencyShader;
Edit 2: Yeah, I think I have the shader working, just need to find the right way to make a shader that can apply a transparency