0

I'm trying to draw some OpenGL graphics over the video from camera. I've modified Apple's GLCameraRipple sample with code that draws a couple of textured triangles. This code works well in my another OpenGL project (but without GLKit). Unfortunately, it only works here that way: when my app starts I see screen filled with ClearColor with my textured triangles on it (but no video), and in a moment the screen turns to black and I don't see anything. Could you explain me what's the problem is?

- (void)glkView:(GLKView *)view drawInRect:(CGRect)rect
{

glClearColor(0.5, 0.0, 0.0, 0.3);
glClear(GL_COLOR_BUFFER_BIT);

glUseProgram(_program);

glUniform1i(uniforms[UNIFORM_Y], 0);
glUniform1i(uniforms[UNIFORM_UV], 1);


if (_ripple)
{
    glDrawElements(GL_TRIANGLE_STRIP, [_ripple getIndexCount], GL_UNSIGNED_SHORT, 0);
}

[self drawAnimations];

}


- (void) drawAnimations{

// Use shader program.
glUseProgram(_texturingProgram);

GLfloat modelviewProj[16];
[self MakeMatrix:modelviewProj 
         OriginX:100.0 
         OriginY:100.0 
           Width:200.0 
          Height:200.0
        Rotation:0.0];

// update uniform values
glUniformMatrix4fv(texturing_uniforms[TEXTURING_UNIFORM_MODEL_VIEW_PROJECTION_MATRIX], 1, GL_FALSE, modelviewProj);

glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, _animationTexture);
glUniform1i(texturing_uniforms[TEXTURING_UNIFORM_TEXTURE], 0);


glVertexAttribPointer(TEXTURING_ATTRIB_VERTEX,3, GL_FLOAT, GL_FALSE, sizeof(vertexDataTextured), &plain[0].vertex);
glEnableVertexAttribArray(TEXTURING_ATTRIB_VERTEX);

glVertexAttribPointer(TEXTURING_ATTRIB_TEX_COORDS, 2, GL_FLOAT, GL_FALSE, sizeof(vertexDataTextured), &plain[0].texCoord);
glEnableVertexAttribArray(TEXTURING_ATTRIB_TEX_COORDS);

glDrawArrays(GL_TRIANGLES, 0, 6);

if (![self validateProgram:_texturingProgram]) {

    NSLog(@"Failed to validate program: (%d)", _texturingProgram);
}
}
Seify
  • 312
  • 2
  • 10

1 Answers1

0

You could place a transparent UIView containing your Open GL drawing layer over another UIView containing the camera preview image layer.

hotpaw2
  • 70,107
  • 14
  • 90
  • 153
  • Well, I'm not sure it's a best approach in my case. It would be slower, takes more memory and I will not be able to use the same buffers – Seify May 06 '12 at 19:56