Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: RGB texture  (Read 6071 times)

0 Members and 1 Guest are viewing this topic.

roccio

  • Jr. Member
  • **
  • Posts: 64
    • View Profile
    • Email
RGB texture
« on: November 04, 2015, 09:01:58 am »
Hello, I need to create (and update) a RGB texture, without alpha channel.
How can I do this?

Thank you

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: RGB texture
« Reply #1 on: November 04, 2015, 09:06:45 am »
Use an alpha of 255, or put whatever you want in the alpha channel and disable alpha blending.
Laurent Gomila - SFML developer

roccio

  • Jr. Member
  • **
  • Posts: 64
    • View Profile
    • Email
Re: RGB texture
« Reply #2 on: November 04, 2015, 09:13:41 am »
Thanks Laurent,
But I need the maximum speed I can get. So looping the buffer every frame to add an apha value is not a good solution.
I would like to create a function just like the Texture::create, but specifying the format. I know that I can not extend the Texture class, as it uses private members and functions that are needed for the correct texture creation

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: RGB texture
« Reply #3 on: November 04, 2015, 09:45:11 am »
Then you can try
http://en.sfml-dev.org/forums/index.php?topic=19290.0
... and replace GL_BGRA with GL_RGB.

If you really need the internal texture format to be GL_RGB, then you can try the same kind of hack after calling texture.create, but this time with glTexImage2D.
« Last Edit: November 04, 2015, 09:46:48 am by Laurent »
Laurent Gomila - SFML developer

roccio

  • Jr. Member
  • **
  • Posts: 64
    • View Profile
    • Email
Re: RGB texture
« Reply #4 on: November 04, 2015, 09:48:58 am »
I will try this solution, but the problem is with the real texture size. I will make some test...

roccio

  • Jr. Member
  • **
  • Posts: 64
    • View Profile
    • Email
Re: RGB texture
« Reply #5 on: November 05, 2015, 10:31:40 am »
I was thinking to use RenderStates fragment shader.
What I have is a sf::Texture and a Rectangle shape to render.

I will try something like this:

const char* frag = "sampler2D texture; void main(void) {vec4 color=texture2D(texture, gl_TexCoord[0].st); gl_FragColor = vec4(color.rgb, 1.0); }"

....

sf::Shader shader;
shader.loadFromMemory(frag, sf::Shader::Fragment);

...

// draw function
sf::RenderStates state;
state.texture = m_shape.getTexture();
state.shader = &shader;
window.draw(m_shape, state);


Is this a good solution? At my first try it doen't work..
« Last Edit: November 05, 2015, 10:44:32 am by roccio »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: RGB texture
« Reply #6 on: November 05, 2015, 10:51:26 am »
Your code is missing a shader.setParameter("texture", sf::Shader::CurrentTexture).

But here you only deal with drawing, I don't see how this could solve your issue, which is about creating and updating a RGB texture.
Laurent Gomila - SFML developer

roccio

  • Jr. Member
  • **
  • Posts: 64
    • View Profile
    • Email
Re: RGB texture
« Reply #7 on: November 05, 2015, 10:55:33 am »
You are right, but I've seen that the crreation is good, and so is the update. The only thing is that in update the alpha channel is set to 0. So my only problem is restricted to drawing.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: RGB texture
« Reply #8 on: November 05, 2015, 11:33:58 am »
Quote
the crreation is good, and so is the update
So how do you create and update the texture? Do you use the tricks I mentioned?

Quote
The only thing is that in update the alpha channel is set to 0
Like I said, in this case you can simply disable alpha-blending so that the alpha channel is ignored.
Laurent Gomila - SFML developer

roccio

  • Jr. Member
  • **
  • Posts: 64
    • View Profile
    • Email
Re: RGB texture
« Reply #9 on: November 05, 2015, 01:40:01 pm »
I use your default functions to create and update the texture. I can not disable alpha blending becouse I want the black parts ot if to be transparent.

oomek

  • Jr. Member
  • **
  • Posts: 90
    • View Profile
    • Email
Re: RGB texture
« Reply #10 on: October 20, 2020, 02:45:28 am »
I'm also currently trying to find a way to display yuv video frames in SFML. Being able to create grayscale textures woud help a lot.

 

anything