这是片元着色器的代码。
in vec2 TexCoord;
uniform sampler2D texture1;
out vec4 OutColor;
void main()
{
OutColor = texture( texture1 , TexCoord);
}
当传递任何GL_RED
格式的纹理时,灰度图像会输出为红色。
我可以通过在着色器中使用红色参数来解决这个问题,但是是否可能将GL_RED图像作为GL_RGBA图像发送到着色器?
unsigned char* image = SOIL_load_image(file, &width, &height, &channels , SOIL_LOAD_AUTO);
// Set The Internal Format
if (channels == 4)
{
texture.Internal_Format = gammaCorrect ? GL_SRGB_ALPHA : GL_RGBA;
texture.Image_Format = gammaCorrect ? GL_SRGB_ALPHA : GL_RGBA;
}
else if(channels == 3)
{
texture.Internal_Format = gammaCorrect ? GL_SRGB : GL_RGB;
texture.Image_Format = gammaCorrect ? GL_SRGB : GL_RGB;
}
else if (channels == 1)
{
texture.Internal_Format = GL_RED;
texture.Image_Format = GL_RED;
}