Question

I have a program that loads in a background texture, then loads in a model with some materials that may have textures assigned (the loading works fine).

When rendering, it first binds the background texture and renders the background using it's own render calls etc.

Then it renders the models (which involves binding the model textures when a specific material is being rendered, and so on).

Problem: The background shows up fine, but the model is not textured. It is a uniform light brown colour.

Do I need to use multiple texture units?

More info: I'm in the process of converting this program from using the fixed function pipeline to using shaders. Currently the background is rendered the old way, but I'm using shaders to render the model. The reason I'm confused is that if I render the model using the fixed pipeline the textures show up fine, but as soon as I use my shader program then it comes up uniformly brown.

I am setting glUniform1i(texture_sampler_uniform_location, 0); after loading the shaders.

Was it helpful?

Solution

after loading the shader s

I think that's your problem right there. Uniform values are individual per shader, so you have to specify them for each shader program. The way you formulated your question hints, that you're setting the uniform value only once, expecting it to be shared among all shaders.

Also uniform brown color indicates, that there's no proper texture coordinate applied. How does your vertex and fragment shader code look like, and how do you supply texture coordinates?

OTHER TIPS

If you want to use multiple textures, then you need to use glActiveTexture(GLenum texture) as well.

Basically you initialize your shader like you already do, though you need to do it per texture handle.

glUniform1i(texture1_sampler_uniform_location, 0);
glUniform1i(texture2_sampler_uniform_location, 1);

Then when you want to render and use the texture, you do the following.

glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, texture1_handle);

glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, texture2_handle);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top