我正在使用 glBindFragDataLocationIndexed() 并在片段着色器中编写两种颜色。以下是我的代码:
glBindFragDataLocationIndexed(shader_data.psId, 0, 0, "Frag_Out_Color0");
glBindFragDataLocationIndexed(shader_data.psId, 0, 1, "Frag_Out_Color1");
glActiveTexture ( GL_TEXTURE0 );
LoadTexture(texture1);
glBindTexture ( GL_TEXTURE_2D, tex_id1);
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA,width, height, 0, GL_RGBA,GL_UNSIGNED_BYTE, texture1_data);
glActiveTexture ( GL_TEXTURE1 );
LoadTexture(texture2);
glBindTexture ( GL_TEXTURE_2D, tex_id2);
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA,width, height, 0, GL_RGBA,GL_UNSIGNED_BYTE, texture2_data);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_COLOR, GL_SRC1_COLOR);
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
片段着色器是:
#version 150
in vec2 texcoord;
uniform sampler2D basetexture1;
uniform sampler2D basetexture2;
out vec4 Frag_Out_Color0;
out vec4 Frag_Out_Color1;
void main(void)
{
Frag_Out_Color0 = texture2D(basetexture1, texcoord);
Frag_Out_Color1 = texture2D(basetexture2, texcoord);
}
OGL3.3 规范说:
Data written to the first of these outputs becomes the first source
color input to the blender (corresponding to SRC_COLOR and SRC_ALPHA). Data
written to the second of these outputs generates the second source color input to
the blender (corresponding to SRC1_COLOR and SRC1_ALPHA).
我已将 GL_SRC_COLOR、GL_SRC1_COLOR 作为输入传递给 glBlendFunc()。我不确定结果是否正确。请查找附件图片。此外,如果我通过 GL_ONE,GL_ONE ,则仅渲染第一个纹理,根本没有第二个纹理的迹象。如何验证我的其余代码是否正常(并且混合是否正确完成)?
以下分别是纹理 1、纹理 2 和结果。