使用glTexImage2D时,纹理只有蓝色调 [英] Texture has only blue hue when using glTexImage2D

查看:302
本文介绍了使用glTexImage2D时,纹理只有蓝色调的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用glTexImage2D显示图像,我使用MFC,Visual C 6.0.
这里的代码:

I'm trying to show image using glTexImage2D, I work with MFC, Visual C 6.0.
Here the code:

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

/* enable 2D texture mapping */
glEnable( GL_TEXTURE_2D );

glTexImage2D(
    GL_TEXTURE_2D, 0, GL_RGB,
    800, 600,
    0, GL_RGB, GL_UNSIGNED_BYTE, BitmapBits);

static float v0[3] = { 0.0, 0.0, 0.0 };
static float v1[3] = { 0.0, 1.0, 0.0 };
static float v2[3] = { 1.0, 1.0, 0.0 };
static float v3[3] = { 1.0, 0.0, 0.0 };

static float t0[2] = { 0.0, 0.0 };
static float t1[2] = { 0.0, 1.0 };
static float t2[2] = { 1.0, 1.0 };
static float t3[2] = { 1.0, 0.0 };

glBegin( GL_QUADS );
    glTexCoord2f(0.0, 0.0);
    glVertex3f(0.0, 0.0, 0.0);
    glTexCoord2f(1.0, 0.0);
    glVertex3f(1.0, 0.0, 0.0);
    glTexCoord2f(1.0, 1.0);
    glVertex3f(1.0, 1.0, 0.0);
    glTexCoord2f(0.0, 1.0);
    glVertex3f(0.0, 1.0, 0.0);
glEnd();

glDisable( GL_TEXTURE_2D );

我只能看到图像的蓝色调.加载的图像BitmapBits正常.
可能是什么问题?

I see only blue hue of the image. The loaded image BitmapBits is OK.
What can be the problem?

推荐答案

您可能想使用 /GL_BGR用于 格式 ,而不是GL_RGB:

You probably want to use GL_BGR_EXT/GL_BGR for format, not GL_RGB:

glTexImage2D(
    GL_TEXTURE_2D, 0, GL_RGB,
    800, 600,
    0, GL_BGR, GL_UNSIGNED_BYTE, BitmapBits);

或者在上传前自己交换字节.

Or swap the bytes yourself before uploading.

由于您使用的是NPOT纹理,因此请确保检查GL_ARB_texture_non_power_of_two或GL版本> = 2.0.

Since you're using NPOT textures make sure to check for GL_ARB_texture_non_power_of_two or GL version >= 2.0.

编辑:在上传之前,请确保您具有glPixelStorei(GL_UNPACK_ALIGNMENT, 1).

Make sure you have glPixelStorei(GL_UNPACK_ALIGNMENT, 1) before upload.

这篇关于使用glTexImage2D时,纹理只有蓝色调的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆