opengl es纹理不是二的幂(iphone)
我想在 openGL 中将尺寸为 200px(宽)x 80px(高)的纹理绘制到一个矩形(宽 200px,高 80px)。 由于 openGL ES 1.1 中的纹理必须为 2 次幂,因此我想加载尺寸为 256px x 128px 的图像,其中包含左上角的原始 200px x 80px 图像,其余部分留空。 如何使用 glTexSubImage2D 从 256px x 128px 纹理中获取感兴趣的部分? 我不知道如何使用最后一个参数(即像素)正确提供该函数。
此外,我读到我必须以某种方式使用 glPixelStorei?
有人可以向我提供一段示例代码吗? 我一直在努力解决这个问题,但我就是不明白。
顺便说一句,我也尝试不使用glTexSubImage2D,而是在0...1之间调整TextureCoords,但这也不起作用。
I want to draw a texture of the dimensions 200px (width) x 80px (height) to a rectangle in openGL (which is 200px wide and 80px height).
As textures in openGL ES 1.1 has to be of power two I want to load an image with the dimensions of 256px x 128px that contains my original 200px x 80px image in the upper left corner, the rest is left blank.
How do I use glTexSubImage2D to get that part of interest from the 256px x 128px texture?
I don't know how to provide that function correctly with the last argument, which is pixels.
Furthermore, I read that I have to somehow use glPixelStorei?
Could anybody please provide my with a snippet of sample code, please?
I've been working really hard to figure this out, but I just don't get it.
BTW, I also tried not to use glTexSubImage2D, but to adjust the TextureCoords between 0...1, but that didn't work eiter.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您将不可避免地必须为纹理坐标选择 0…1 的子范围。 glTexSubImage2D 仅(重新)定义纹理的一部分,同时保留总尺寸不变。
计算正确的子范围值有点不直观:假设您的总纹理为 8 像素宽,像素 3…6 具有实际内容,则纹理坐标图如下所示:
因此要使用的纹理坐标为:
(t0 - 1) /N … (t1)/N ; t0、t1、N(以像素为单位)。
如果您想在参数 tau 的 0…1 范围内处理子纹理,则公式为
w := t1 - t0
u = (t0 - 1)/N + w * tau
You will inevitably have to select a subrange from 0…1 for the texture coordinates. glTexSubImage2D only (re-)defines a portion of the texture, while leaving the total dimensions as they were.
Calculating the proper subrange values is a bit nonintuitve: Say your total texture is 8 pixels wide, with the pixels 3…6 having actual content, then the texture coordinates map like following:
So the texture coordinates to use are:
(t0 - 1)/N … (t1)/N ; t0, t1, N in pixels.
If you want to address your subtexture in the range 0…1 on parameter tau the formula is
w := t1 - t0
u = (t0 - 1)/N + w * tau