Opengl Unbind Texture?

0
  • I have a list of objects; Home
  • Each object has different amounts of texture; Home
  • When I make glBindTexture of 2 textures (diffuse and specular) for an object, it may happen that the next object can only have 1 (diffuse) texture; Home
  • It happens 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 previous textures is appropriate? If yes, how? Because I've tried using the glDisable function (GL_TEXTURE_2D); it's just that it's not untying.

Asyoucanseethespeculartextureofthewallhasstoppedattheglassesthatonlyhasthediffusetexture.(Andno,bycoincidenceitlooksliketheglassesarereflectingthescenario,butthat'snotit)

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

...if(obj.textureDiffuse.size()!=0){unsignedinti=0;for(unsignedint&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);
}

...
    
asked by anonymous 30.12.2017 / 20:57

1 answer

0

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 fuzzy texture.

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

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

SecondAlternative:UsingFuzzyTexturetoSpeculate

Duringthebindingtimeofthetexturesyoucancheckiftheobjecthassomespeculartexture,ifitdoesnot,linkthefuzzytextureswiththenameofthespeculartextures.

Inthisoptionyouwillsimulateaspecularillumination.Itwillnotresultinsomethingrealisticbutwillnotleadtodefectsinlighting.

Note:Asmostspeculartexturesareobtainedfromthediffuse,itispossibletoconvertthediffuseimageintoshadesofgraytouseasspecular. ThirdAlternative:Changeobject

UsingBlender,Maya,3DsMax,oranyothereditor,youcanimporttheobject,addaspeculartexture(reusingthesamemapping),andexporttheeditedobject

Thisisthemostcorrectoptionifyouwanttomakesureallobjectsarespeculartexture.

BelowisanexampleofaddingthespeculartexturetotheobjectusingBlender.

    
02.01.2018 / 04:32