How can I pass multiple textures to a single shader?

前端 未结 2 819
我寻月下人不归
我寻月下人不归 2020-12-13 06:44

I am using freeglut, GLEW and DevIL to render a textured teapot using a vertex and fragment shader. This is all working fine in OpenGL 2.0 and GLSL 1.2 on Ubuntu 14.04.

2条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-13 07:27

    instead of using:

    glUniform1i(decalTexLocation, 0);
    glUniform1i(bumpTexLocation,  1);
    

    in your code, you can have:

    layout(binding=0) uniform sampler2D DecalTex;  
    // The texture  (we'll bind to texture unit 0)
    layout(binding=1)uniform sampler2D BumpTex;   
    // The bump-map (we'll bind to texture unit 1)
    

    in your shader. That also mean you don't have to query for the location.

提交回复
热议问题