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

Pages: [1]
1
Graphics / Re: Transparencies with VertexArray tilemaps
« on: December 05, 2012, 04:46:47 am »
Thanks Cire!  I think I have a solid enough understanding to incorporate this into my map!

2
Graphics / Re: Transparencies with VertexArray tilemaps
« on: December 05, 2012, 02:39:20 am »
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 :P 

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 :)

3
Graphics / Re: Transparencies with VertexArray tilemaps
« on: December 02, 2012, 08:42:08 am »
Thanks for the quick response!

I will get to messing around with both of these options :)

4
Graphics / Transparencies with VertexArray tilemaps
« on: December 02, 2012, 08:14:38 am »
Hello, I have searched the forums for an answer to my question, along with delving through the documentation, and have not figured this out, so I decided to finally post it to see some responses!

I am currently in the process of creating my Map class out of a vector of Layers (Which are just fancy wrappers for VertexArrays and their relative Textures.)  I would like to be able to change transparencies of Layers and I am not quite sure how I would do this.  Is there a way to set a transparency of a texture? 

I noticed that I could possibly use Texture::update( const Uint8 * pixels ), but then would I have to traverse every pixel of texture to change its alpha level?

The other option I am trying to figure out, is with the RenderWindow draw call for the vertex array, and sending it a RenderState, although I am not seeing anything specific about sending an alpha value this way.

Any input on this would be greatly appreciated!

Thanks,
Saeyne


Pages: [1]