0

I use the openGL ES 1.0. After decoding stream data, it is changed to RGBA bits. And then I transfer RGBA bytes to 'renderer' method with parameter.
the renderer method is called by each frame routines. Because RGBA bytes are changed every times.

But it doesn't draw any picture frames. Just the white rectangle and background gray color are displayed. What is the problem?

[initialize]

- (id <ESRenderer>) init 
{
    if (self = [super init])
    {
        context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES1];
        if (!context || ![EAGLContext setCurrentContext:context])
        {
            [self release];
             return nil;
        }

        // Create default framebuffer object. The backing will be allocated for the current layer in -resizeFromLayer
         glGenFramebuffersOES(1, &defaultFramebuffer);
         glGenRenderbuffersOES(1, &colorRenderbuffer);

         glBindFramebufferOES(GL_FRAMEBUFFER_OES, defaultFramebuffer);
         glBindRenderbufferOES(GL_RENDERBUFFER_OES, colorRenderbuffer);

         glEnable(GL_TEXTURE_2D);
         glGenTextures(1, &frameTexture);
         glBindTexture(GL_TEXTURE_2D, frameTexture);

         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

         glFramebufferTexture2DOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_TEXTURE_2D, frameTexture, 0);
         glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_RENDERBUFFER_OES, colorRenderbuffer);
    }
     return self;
}

[Renderer method. It is called by outside per each frames]

static const GLfloat verticesForGL_TRIANGLE_STRIP[] = {
    -0.8, 0.8, 0.0,          //v1
    0.0, 1.0,               //UV1

    -0.8, -0.8, 0.0,          //v2
    0.0, 0.0,               //UV2

    0.8, 0.8, 0.0,          //v3
    1.0, 1.0,               //UV3

    0.8, -0.8, 0.0,          //v4
    1.0, 0.0,               //UV4
};

- (void)render:(uint8_t*)data
{
     if ([EAGLContext currentContext] != context)
        [EAGLContext setCurrentContext:context];

     glClearColor(0.4f, 0.4f, 0.4f, 1.0f);
     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

     glViewport(0, 0, backingWidth, backingHeight);

     glMatrixMode(GL_PROJECTION);
     glLoadIdentity();

     glOrthof(-1.1f, 1.1f, -1.1f, 1.1f, -2.0f, 2.0f);

     glMatrixMode(GL_MODELVIEW);
     glLoadIdentity();
     glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1280, 1024, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);

     glEnable(GL_TEXTURE_2D);
     glBindTexture(GL_TEXTURE_2D, frameTexture);

     glEnableClientState(GL_VERTEX_ARRAY);
     glEnableClientState(GL_TEXTURE_COORD_ARRAY);

     glVertexPointer(3, GL_FLOAT, sizeof(GLfloat)*5, verticesForGL_TRIANGLE_STRIP);
     glTexCoordPointer(2, GL_FLOAT, sizeof(GLfloat)*5, &verticesForGL_TRIANGLE_STRIP[0]+3);

     glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);

     glDisable(GL_TEXTURE_2D);
     glDisableClientState(GL_VERTEX_ARRAY);
     glDisableClientState(GL_TEXTURE_COORD_ARRAY);

     [context presentRenderbuffer:GL_RENDERBUFFER_OES];
 }
Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982

2 Answers2

0

Seems to me you are attempting to load a non-power-of-two texture. This is not supported on all iOS devices on openGl es 1.0/1.1. You can check if the devices supports such extension

bool npot = strstr(extensions, "GL_APPLE_texture_2D_limited_npot") != 0;
if (! npot)
   NSLog("Non power of two textures not supported.");

Also, try loading a power of two square texture and see if that works.

fsaint
  • 8,759
  • 3
  • 36
  • 48
0

Oh I've solved just now.

I added this line below the glTexImage2D function. (sorry, I'm a beginner about openGL. It seems to make a link frameBuffer with texture.)

glFramebufferTexture2DOES(GL_FRAMEBUFFER_OES, GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL_OES, GL_TEXTURE_2D, frameTexture, 0);

I use the iPhone5(armv7s). It is enough to decode and resize the 1280x1024 30fps pictures. but rendering need to change from using CPU to GPU. So, now I can make a better performance. (23fps -> 30fps)

thanks.