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

Pages: [1]
1
Graphics / Can a RenderTexture be resized?
« on: February 22, 2019, 05:14:44 pm »
Hey guys!

I have a dynamic width requirement for a sprite generated from a RenderTexture, but redundant calls to rt.create don't seem to reinitialize it to the new width ( apparently I'm not supposed to do it this way )

Is there a proper way to destroy and recreate a RenderTexture?

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Basically I've created a custom font class that makes a single sprite out of a line of text, but only when the text changes.  If I call create redundantly, I see graphical artifacts at the edge of my sprite, which tells me the texture probably didn't resize.  Hopefully there is a better solution than creating the render texture once to the entire width of the window (since I may have dozens of these objects)

This is what I'm doing when the text changes..

Quote
rt.create( width, height);

rt.clear( sf::Color( 0,0,0,0));

DrawText( pszString, rshader, tint);

rt.display();

textureText = rt.getTexture();
      
spriteText.setTexture( textureText);

Any feedback is appreciated, thank you!!

2
Window / Re: Window resizing?
« on: November 17, 2015, 01:50:43 am »
Perfect, thank you Laurent!  I was having the same problem.

3
Graphics / Re: Problem manipulating gl_FragColor in my fragment shader
« on: November 09, 2015, 06:37:35 pm »
Thank you Laurent!

I did figure out at the end that I needed to acquire the color from the texture with a call to texture2D.   I should not be coding at 4:00 in the morning ;)

4
Graphics / Problem manipulating gl_FragColor in my fragment shader
« on: November 09, 2015, 10:15:14 am »
Hey all, I'm kind of stuck on something.  Any help would be appreciated!

I'm trying to convert a game I wrote in XNA to SFML and I'm having difficulty porting an HLSL pixel shader I wrote over to GLSL.  It should be a simple thing but somehow I'm not getting the desired output.

Basically, I want to render a sprite with transparency, but setting the non-transparent pixels to a passed value so that it might appear solid-color like so :



My sprites load and display correctly under the default shader, but somehow what I'm writing ignores the alpha channel or I am not doing an operation correctly, I don't know.

My shader.frag looks like so:

uniform vec4 indexColor;

void main()
{

        if( gl_FragColor.a > 0.01) // set color to passed value
        {
                gl_FragColor = indexColor;
                gl_FragColor.a = 1.0;
        }
        else // otherwise do not render this pixel
        {
                gl_FragColor = 0;
        }

}

This particular code renders everything transparent, so somehow I'm not evaluating the alpha channel correctly.

My code is calls this once per update:

window.clear( sf::Color( COLOR_BLACK));

shader.setParameter("texture", sf::Shader::CurrentTexture);

Then in my loop, for each sprite I call :

shader.setParameter("indexColor", sf::Color( 1.0f, 0.8f, 0.6f, 1.0f));

window.draw( sprite, &shader);

I do know the shader is loading because I can force it to draw everything a solid color.  Any ideas?  Thanks!

EDIT :

As per usual I may have resolved my own question, sorry!

I got it to work with this shader :

uniform sampler2D texture;

uniform float r;
uniform float g;
uniform float b;

void main()
{
        vec4 pixel = texture2D(texture, gl_TexCoord[0].xy);

   
        if( pixel.a > 0.1)
        {
                pixel.r = r;
                pixel.g = g;
                pixel.b = b;

                pixel.a = 1.0;

                gl_FragColor = pixel;
        }
        else
        {
                gl_FragColor = vec4( 1.0, 1.0, 0.0, 0.0);
        }
}

I'm sure I don't need to pass the RGB individually but it works for now.

Pages: [1]
anything