gpt4 book ai didi

opengl - 使用 glTexImage2D 时纹理只有蓝色色调

转载 作者:行者123 更新时间:2023-12-01 03:30:58 25 4
gpt4 key购买 nike

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

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就OK了。
可能是什么问题?

最佳答案

您可能想使用 GL_BGR_EXT/GL_BGR format ,而不是 GL_RGB:

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

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

由于您使用的是 NPOT 纹理,请务必检查 GL_ARB_texture_non_power_of_two 或 GL 版本 >= 2.0。

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

关于opengl - 使用 glTexImage2D 时纹理只有蓝色色调,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9296503/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com