加载纹理时缺少像素? [英] Missing Pixel When Loading Texture?

查看:82
本文介绍了加载纹理时缺少像素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试加载3x10图像,每个像素"仅使用1个字节.该像素是单个Alpha.

I am trying to load a 3x10 image, using only 1 byte per "pixel". This pixel is a single alpha.

当我按以下方式加载图像时,由于某些原因,每个第四个像素都将被丢弃.没有opengl错误,我没有2种硬件的支持.

When i load the image as follows, every fourth pixel is discarded for some reason. No opengl errors, I have non-power of 2 hardware support.

因此,如果我有以下像素缓冲区:{0,1,2,3,4,5,6,7,7,9,10},则图像将如下所示:

So if i have the following pixel buffer: { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }, the image will look like this:

0 1 2
4 5 6
8 9 10
...

纹理加载代码:

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA8, 3, 10, 0, GL_ALPHA, GL_UNSIGNED_BYTE, pixels);

我不太确定发生了什么,我很困惑.有什么可能导致这种行为?我也有最新的opengl驱动程序...

I'm not really sure what is happening, I am stumped. Is there anything that can be causing such behavior? I have the latest opengl drivers as well...

推荐答案

GL_UNPACK_ALIGNMENT像素存储值控制传递给glTexImage2D()的纹理数据的行对齐.默认值为4.

The GL_UNPACK_ALIGNMENT pixel storage value controls row alignment of the texture data passed to glTexImage2D(). The default value is 4.

由于您的数据每行3个字节,因此将四舍五入到4的下一个倍数,即4.因此,使用默认值,glTexImage2D()将每行读取4个字节.

Since your data has 3 bytes per row, this will be rounded up to the next multiple of 4, which is 4. So with the default value, glTexImage2D() will read 4 bytes per row.

要执行此操作,必须将行对齐值更改为1:

To make this work, the row alignment value has to be changed to 1:

glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

这篇关于加载纹理时缺少像素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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