SFML community forums

Help => Graphics => Topic started by: Powereleven on May 24, 2018, 01:03:44 am

Title: How do you bind multiple textures to the same shader?
Post by: Powereleven on May 24, 2018, 01:03:44 am
I am aware of
sf::Texture::bind(&texture_here);
but what if my shader requires more than 1 texture?
Title: Re: How do you bind multiple textures to the same shader?
Post by: Laurent on May 24, 2018, 08:12:45 am
It's in the doc.

https://www.sfml-dev.org/documentation/2.5.0/classsf_1_1Shader.php#a7806a29ffbd0ee9251256a9e7265d479
Title: Re: How do you bind multiple textures to the same shader?
Post by: Powereleven on May 24, 2018, 03:10:35 pm
I was aware of that setUniform stuff too. I used them before entering my game loop to set the sampler2Ds.
But when mixing with my custom OpenGL code, the doc says:
sf::Texture t1, t2;
...
sf::Texture::bind(&t1);
// draw OpenGL stuff that use t1...
sf::Texture::bind(&t2);
// draw OpenGL stuff that use t2...
sf::Texture::bind(NULL);
// draw OpenGL stuff that use no texture...
 But what if my OpenGL stuff uses t1 and t2? It seems that t1 is unbinded if I bind t2.
Title: Re: How do you bind multiple textures to the same shader?
Post by: Laurent on May 24, 2018, 03:27:23 pm
Texture::bind cannot make use of multiple texture units, so yes, each call replaces the previous texture. But depending on what your OpenGL code does, this may not be a problem.
Title: Re: How do you bind multiple textures to the same shader?
Post by: Powereleven on May 24, 2018, 03:40:03 pm
For example, I have 2 sampler2D and mix() them in the shader. How do I solve this? ( in sfml standard functions obviously )
Title: Re: How do you bind multiple textures to the same shader?
Post by: Laurent on May 25, 2018, 09:20:29 am
As I said, if it's in a sf::Shader, you can use Shader::setUniform, it will correctly handle multiple texture units.