PDA

View Full Version : glTexSubImage in opengl es 1.1



John Qualis
10-18-2010, 11:10 AM
I am sending an opengl 3D scene across an IP link to my iPhone app built using SDK 4.1. I render the 3D scene first using FBO, read it with glReadPixels and send it to the iphone app. If I convert the pixel data received by the app to UIImage, I see it is displayed correctly. But when I use the same data in glTexSubImage2D using opengl es 1.1 (on iPhone 3G), I don't see anything. Any ideas what could be going wrong? I am using glTexSubImage2D since glDrawPixels is not supported in opengl es 1.1. Any examples/tutorials to solve this problem? Appreciate any help.

Thanks in advance.


Code -

- (id) initWithFrame: (CGRect) frame
{
.....
api = kEAGLRenderingAPIOpenGLES1;
m_context = [[EAGLContext alloc] initWithAPI:api];

glGenFramebuffersOES(1, &m_frameBuffer);
glBindFramebufferOES(GL_FRAMEBUFFER_OES, m_frameBuffer);
glGenRenderbuffersOES(1, &m_colorRenderbuffer);
glBindRenderbufferOES(GL_RENDERBUFFER_OES, m_colorRenderbuffer);

glGenTextures(1, &m_tex);
glTexImage2D(GL_TEXTURE_2D, 0, GL_BGRA, width, height, 0, GL_BGRA, GL_UNSIGNED_BYTE, NULL);
....
}

- (void) drawView: (CADisplayLink*) displayLink
{
glBindTexture(GL_TEXTURE_2D, m_tex);
glTexSubImage2D(GL_TEXTURE_2D, 0,0,0,
WIDTH, HEIGHT,
GL_BGRA,
//GL_RGBA,
GL_UNSIGNED_BYTE,
m_pixelData);

[m_context presentRenderbuffer:GL_RENDERBUFFER_OES];
}

ZbuffeR
10-18-2010, 01:19 PM
Missing mipmaps ?
I don't know GL ES, but it is a common mistake, fogetting to set mipmaps make your texture invalid.

EDIT: where is your drawing code ?
You have to draw 2 triangles (a quad) to see the content of the texture.

John Qualis
10-19-2010, 02:24 AM
Missing mipmaps ?
I don't know GL ES, but it is a common mistake, fogetting to set mipmaps make your texture invalid.

I am using the following code during initialization -

glGenTextures(1, &m_tex[0]);
glBindTexture(GL_TEXTURE_2D, m_tex[0]);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_BGRA, WIDTH, HEIGHT, 0, GL_BGRA, GL_UNSIGNED_BYTE, NULL);
glBindTexture(GL_TEXTURE_2D, 0);

EDIT: where is your drawing code ?
You have to draw 2 triangles (a quad) to see the content of the texture.

Here's the drawing code -


const GLfloat quadVertices[] = {
-1.0f, -1.0f, 0.0f,
-1.0f, 1.0f, 0.0f,
1.0f, 1.0f, 0.0f,
1.0f, -1.0f, 0.0f,
-1.0f, -1.0f, 0.0f
};

// Sets up an array of values for the texture coordinates.
const GLfloat quadTexcoords[] = {
0.0f, 0.0f,
0.0f, 1.0f,
1.0f, 1.0f,
1.0f, 0.0f,
0.0f, 0.0f
};
glVertexPointer(3, GL_FLOAT, 0, quadVertices);
glEnableClientState(GL_VERTEX_ARRAY);
glTexCoordPointer(2, GL_FLOAT, 0, quadTexcoords);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glBindFramebufferOES(GL_FRAMEBUFFER_OES, m_frameBuffer);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 5);
glBindRenderbufferOES(GL_RENDERBUFFER_OES, m_colorRenderbuffer);

John Qualis
10-19-2010, 01:14 PM
Solved. it was an ur-elated issue. Thanks for the response.