小编fin*_*lia的帖子

如何将多个纹理传递到单个着色器?

我使用freeglut,GLEW 和魔鬼,以呈现纹理的茶壶使用顶点和片段着色器.这在Ubuntu 14.04上的OpenGL 2.0和GLSL 1.2中都运行良好.

现在,我想将凹凸贴图应用于茶壶.我的讲师显然不会酿造他自己的茶,所以不知道他们应该是顺利的.无论如何,我找到了一个关于老式凹凸贴图的漂亮教程,其中包括一个片段着色器,它开始于:

uniform sampler2D DecalTex; //The texture
uniform sampler2D BumpTex; //The bump-map 
Run Code Online (Sandbox Code Playgroud)

他们没有提到的是如何将两个纹理首先传递给着色器.

以前我

//OpenGL cpp file
glBindTexture(GL_TEXTURE_2D, textureHandle);

//Vertex shader
gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;

//Fragment shader
gl_FragColor = color * texture2D(DecalTex,gl_TexCoord[0].xy);
Run Code Online (Sandbox Code Playgroud)

所以现在我

//OpenGL cpp file
glBindTexture(GL_TEXTURE_2D, textureHandle);
glBindTexture(GL_TEXTURE_2D, bumpHandle);

//Vertex shader
gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
gl_TexCoord[1] = gl_TextureMatrix[1] * gl_MultiTexCoord1;

//Fragment shader
gl_FragColor = color * texture2D(BumpTex,gl_TexCoord[0].xy);
//no bump logic yet, just testing I …
Run Code Online (Sandbox Code Playgroud)

opengl glsl texture-mapping texture2d opengl-2.0

21
推荐指数
1
解决办法
2万
查看次数

标签 统计

glsl ×1

opengl ×1

opengl-2.0 ×1

texture-mapping ×1

texture2d ×1