0

I have an application where I would like to use an FBO to display an image of a QuickTime movie. I'm totally new to FBOs and only got a little bit of knowledge on OpenGL. I got problems understanding the FBO paradigm with binding textures and stuff and I'm hoping you guys could help.

To get the movie's current image, I'm using

QTVisualContextCopyImageForTime(theContext, NULL, NULL, &currentFrameTex); where currentFrameTex is a CVImageBufferRef.

For setting up the FBO, all I'm doing is:

glGenFramebuffersEXT(1, &idFrameBuf);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, idFrameBuf);

I'm using the following code to draw the image:

// get the texture target (for example, GL_TEXTURE_2D) of the texture
GLint target = CVOpenGLTextureGetTarget(currentFrameTex);
// get the texture target name of the texture
GLint texID = CVOpenGLTextureGetName(currentFrameTex);

// get the texture coordinates for the part of the image that should be displayed
CVOpenGLTextureGetCleanTexCoords(currentFrameTex,
                                 bottomLeft, bottomRight,
                                 topRight, topLeft);
glBindTexture(target, texID);
glTexParameteri(target, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(target, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

glTexImage2D(target, 0, GL_RGBA8, 256, 256, 0, GL_BGRA, GL_UNSIGNED_BYTE, NULL);
glFramebufferTexture2D(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, target, texID, 0);

I'm just getting a black image and I don't know what I'm doing wrong. More information can be provided if necessary. Thanks in advance!

guitarflow
  • 2,930
  • 25
  • 38

1 Answers1

1

Please see http://www.opengl.org/wiki/Framebuffer_Object . FBO allows you to render graphics to offscreen buffer and then process it. Your code overwrites the texture provided by currentFrameTex, which does not make much sense. Once you call glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, idFrameBuf) with non zero idFrameBuf then all graphics is drawn to this FBO and nothing to the screen.

Maf
  • 491
  • 3
  • 5
  • Hey Maf, thanks for your answer. Where am I overwriting something? What would I need to do to have the texture drawn correctly? I already read that article but I'm missing something. Thanks a lot! – guitarflow Feb 16 '13 at 22:24
  • You do not need FBO to render your texture. Render it directly to the screen. – Maf Feb 17 '13 at 07:40
  • 1
    CVOpenGLTextureGetName(currentFrameTex) returns texture that already contains your image. Calling glTexImage2D with this texture bound reallocates this texture with a new content and new dimension so you loose your movie frame. When you attach this new texture to FBO (glFramebufferTexture2D) you are effectively drawing to this texture (via FBO). If you really need FBO then either create a new texture (glGenTextures) and attach it to FBO or use render buffer (glRenderbufferStorage​). – Maf Feb 17 '13 at 07:48
  • This will be used in conjunction with external video hardware. The hardware will read info from the FBO using glReadPixels later. What would I need to do to attach the texture to the FBO? I'm so sorry, I just don't understand the paradigm behind it. – guitarflow Feb 17 '13 at 20:52
  • 1
    FBO is just a way how to draw things to non visible memory, either texture or render buffer. For your case I'd recommend to create a render buffer (http://www.opengl.org/wiki/Renderbuffer_Object) then FBO and then attach the RB to FBO (`glFramebufferRenderbuffer`​). Do this once at app init. Once you draw a QT texture to FBO you will be able to glReadPixels from this FBO and copy to your HW. – Maf Feb 17 '13 at 21:13