Opengl Unbind Texture?

Asked

Viewed 89 times

0

  • I have a list of objects;
  • Each object has different amounts of texture;
  • When I do glBindTexture 2 textures (fuzzy and specular) to an object, it can happen that the next object can have only 1 texture (fuzzy);
  • It turns out that the second texture of the first object ends up being sent to the next object to be rendered, because the second texture is still linked.

Question: Would you like to know how to proceed in such cases and try to unlink all the previous textures is appropriate? If so, how? Because I tried to use the function glDisable(GL_TEXTURE_2D); only it is not unlinking.

inserir a descrição da imagem aqui

As you can see, the specular texture of the wall has ended up in the glasses that only have a fuzzy texture. (And no, by coincidence it seems that the glasses are reflecting the scenery, but that’s not it)

for (Mesh & obj : openglDraw::objs) {

...
if (obj.textureDiffuse.size() != 0) {
    unsigned int i = 0;
    for (unsigned int &j : obj.textureDiffuse) {
        openglUtils::setTexture(programme, i, j);
        openglUtils::setInt(programme, "material.diffmap", i);
        i++;
    }
    for (unsigned int &j : obj.textureSpecular) {
        openglUtils::setTexture(programme, i, j);
        openglUtils::setInt(programme, "material.specmap", i);
        i++;
    }
    ...
    glDisable(GL_TEXTURE_2D);
}

...

1 answer

1


Three Alternatives I Found and Worked:

First Alternative: Different Shaders

Use a different Shader for objects with specular and diffuse texture, and another Shader for objects with only diffuse texture.

Perhaps it is the best alternative if there is no need to create a realistic scene, that is, without the specular texture on some objects. In addition to making graphics processing more robust.

Note: Not all materials in real life have significant speculative behavior.

inserir a descrição da imagem aqui

Second Alternative: Use Fuzzy Texture as Specular

During the binding time of the textures you can check if the object has some specular texture, if not, link the fuzzy textures to the name of the specular textures.

In this option you will simulate a specular illumination. It will not result in something realistic but will not cause defects in illumination.

Note: As in most of the specular textures are obtained from the fuzzy one, it is possible to convert the fuzzy image to grayscale to use as specular. inserir a descrição da imagem aqui Third Alternative: Change the object

Using Blender, Maya, 3ds Max, or any other editor, you can import the object, add a specular texture (reusing the same mapping) and export the edited object

It is the most correct option if you want to ensure that all objects have specular texture.

Below an example adding the specular texture to the object using Blender.

inserir a descrição da imagem aqui

inserir a descrição da imagem aqui

inserir a descrição da imagem aqui

Browser other questions tagged

You are not signed in. Login or sign up in order to post.