交换每个水平对绘制的 OpenGL 像素
我对 OpenGL 有点陌生,但我相当确定我的问题在于所使用的像素格式,或者我的纹理是如何生成的...
我正在使用 16 位 RGB5_A1 像素格式将纹理绘制到平面 2D 四边形上,尽管我在这个阶段没有使用任何阿尔法。我遇到的问题是每对水平像素值都已被交换。
也就是说...如果像素位置应按此顺序(假设 8x2 图像),
0 1 2 3
4 5 6 7
则它们将被绘制为
1 0 3 2
5 4 7 6
Or,从该图像可以更清楚地看出(如下)。 左边是我得到的……右边是我应该得到的。
。
问题是...我最后是怎么得到这个结果的?是不是像素格式有问题?不太可能,因为颜色看起来都是正确的,而且如果归结为字节顺序,我会期望出现各种令人讨厌的情况。非常感谢您的建议。
更新:事实证明问题出在我的源渲染器中。有趣的是,我通过使用 32 位纹理完全避免了这个问题(目前还没有尝试过 24 位)。
I'm somewhat new to OpenGL though I'm fairly sure my problem lies in the pixel format being used, or how my texture is being generated...
I'm drawing a texture onto a flat 2D quad using a 16bit RGB5_A1 pixel format, though I don't make use of any alpha at this stage. The problem I'm having is that each pair of horizontal pixel values have been swapped.
That is... if the pixels positions should be in this order (assume 8x2 image)
0 1 2 3
4 5 6 7
they are instead drawn as
1 0 3 2
5 4 7 6
Or, more clearly from this image (below).
Left is what I get... Right is what I should get.
.
The question is... How have I ended up with this? Is there something wrong with the pixel format? Unlikely since the colours all appear correct, and I would expect all kinds of nasty if it were down to endian-ness. Suggestions greatly appreciated.
Update: Turns out the problem was in my source renderer. Interestingly, I've avoided the problem entirely by using 32-bit textures (haven't tried 24-bit at this point).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这可能是不相关的,并且您已经找到了解决方法,但它可能与 OpenGL 解包对齐有关。您尝试过以下通话吗?指示每个图像行对齐到 1 个字节(默认为 4)。
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
This may be unrelated, and you have found a workaround, but it could be related to OpenGL unpack alignment. Have you tried with the following call ? To instruct the alignment of every image row to 1 byte (default is 4).
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);