0

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. 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); 

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);

    [m_context presentRenderbuffer:GL_RENDERBUFFER_OES];
    }
John Qualis
  • 1,663
  • 4
  • 33
  • 52

3 Answers3

0

If you're using GL_*_MIPMAP_* for GL_TEXTURE_[MIN|MAG]_FILTER (watch out for defaults!) make sure you actually provide image data for all mipmap levels.

genpfault
  • 51,148
  • 11
  • 85
  • 139
  • Thanks. But I get the same result if I remove the mipmap code. I dont see anything. – John Qualis Oct 18 '10 at 18:54
  • Included the sample draw code as well. "Dont see anything" implies I donot see the 3D pixel data. Just blank screen where the drawing code is. – John Qualis Oct 19 '10 at 09:27
0

Keep in mind that textures width and height needs to be a power of 2 on iphone/ipad platform. if it isn't you get a blank screen.

Chris
  • 11
  • Only on the older devices. OpenGL ES 2.0 devices can support any size. Exceptions can be added in the rendering code to check for device type and thus infer OpenGL ES version, and adjust accordingly. – M. Ryan Nov 11 '10 at 16:53
0

Why are you using 5 vertices to make up a triangle strip? I guess what you wanted is a square made of 2 triangles, thus your strip needs only 4 vertices.

Also, in your case it would be easier just to initialize a square texture and render it like this (without using vertices):

/* do the glGenTextures() / glTexImage() / glBindTexture() dance here */
int box[] = { nXOffset, nYOffset, nWidth, nHeight };  /* define the part of the texture you're going to render */
glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, box);
glDrawTexfOES(0.0f, 0.0f, 0.0f, nWidth, nHeight); /* rectangle in the screen coordinates, where to render the previously defined part of the texture */
kervich
  • 487
  • 3
  • 13