Alex Rivera | Logout

Rendering to non-power-of-two texture on iPhone

Asked 2011-01-21T14:51:50.953
12

Is it possible to render to texture with OpenGL ES 1.1 on the iPhone (2G and older)? If I bind a texture as a render buffer, it has to be the size of the render buffer, which isn't POT-sized. But OpenGL ES 1.1 requires textures to be POT.

Maybe it can't be done on ES 1.1?

Edit
Report

1 Answer

2

It can be done, all you need to do is get the next power of 2 bigger than the non-POT.

Then generate a framebuffer:

GLuint aFramebuffer;
glGenFramebuffersOES(1, &aFramebuffer);

And a texture:

GLuint aTexturebuffer;
glGenTextures(1, &aTexturebuffer);

Then you do the same texture like things:

glBindTexture(GL_TEXTURE_2D, aTexturebuffer);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glColor4ub(0, 0, 0, 255);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, textureWidth, textureHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);

int area[] = {0.0, 0.0, renderWidth, renderHeight};

glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, area);

glBindFramebufferOES(GL_FRAMEBUFFER_OES, aFramebuffer);
glFramebufferTexture2DOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_TEXTURE_2D, aTexturebuffer, 0);

Here I used the draw_texture extension. textureWidth and textureHeight are the power of 2 bigger, and renderWidth and renderHeight are the the rendere's width and height. Then when you bind to aFramebuffer it will draw to texture.

answered 2011-01-21T15:32:11.030

Your Answer