开发者

opengl es texture not power of two (iphone)

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 a开发者_如何学运维n 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.


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:

        2/8             6/8 
 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
 ^                               ^
0.0                             1.0

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜