Opengl Unbind Texture?



    • I have a list of objects;
    • Each object has different amounts of texture;
    • When I make glBindTexture of 2 textures (hardens and speculate) for an object, it may happen that the next object can have only 1 texture (hardens);
    • 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 these cases and try to unlink all the previous textures is appropriate? If so, how? For I have tried to use the glDisable(GL_TEXTURE_2D) function; only it is not showing off.

    inserir a descrição da imagem aqui

    As you can see the speculative texture of the wall was to stop on the glasses that only possesses the diffuse texture. (And no, by coincidence it seems that the glasses are reflecting the scenario, but not that)

    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);
    }
    

    ...



  • Three Alternatives I found and worked:

    First Alternative: Different Shaders

    Use a different shader for objects with speculative and diffuse texture, and another shader for objects with only the diffuse texture.

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

    Obs: Not all real-life materials have significant speculative behavior.

    inserir a descrição da imagem aqui

    Second Alternative: Use Diffuse Texture as Specular

    During the time of binding the textures you can check if the object has some speculative texture, if it does not, vincule the diffuse textures with the name of the speculative textures.

    In this option you will simulate a speculative lighting. It will not result in something realistic but will not generate defects in lighting.

    Obs: As in most speculative textures are obtained from the diffuse, it is possible to convert the diffuse image into gray tones to use as speculation. inserir a descrição da imagem aqui Third Alternative: Change the object

    Using Blender, Maia, 3Ds Max, or any other editor, you can import the object, add a speculative 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 speculative texture.

    Below an example by adding the speculative 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




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2