我想了解这个旧代码,并使用着色器将其翻译为最新版本的OpenGL:
if (channel == Alpha) {
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
} else {
// replicate color into alpha
if (GL_ARB_texture_env_dot3) {
switch (channel) {
case Red:
glColor3f(1.0, 0.5, 0.5);
break;
case Green:
glColor3f(0.5, 1.0, 0.5);
break;
case Blue:
glColor3f(0.5, 0.5, 1.0);
break;
default:
// should not happen!
assert(0);
}
} else {
// should not happen!
assert(0);
}
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_DOT3_RGBA_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_EXT, GL_PRIMARY_COLOR);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB_EXT, GL_SRC_COLOR);
}
<draw models>
我的想法发生了什么:
if channe = Alpha
just replace alpha
else
// no idea why used glColor3f
looks like it makes one of the colors 100% bright
and then in magical 6 glTexEnvi lines it transforms to alpha
答案 0 :(得分:3)
它设置了一个普通的贴图纹理。通道开关定义“正常”矢量指向哪个轴并相应地设置颜色;今天你要使用制服。
纹理不仅仅是一个alpha通道的情况下纹理环境的等式设置,看起来像下面的片段着色器
uniform vec3 primary_direction; // instead of primary color
uniform sampler… tex;
in vec2 tex_coord;
void main()
{
gl_FragColor = vec4( dot(primary_direction, texture(tex, tex_coord)), 1);
}