views:

258

answers:

1

i need draw a counter onto a OpenGL view. here is my source code for the video frame display

 cgl_ctx = CGLContextObj ( [[self openGLContext]  CGLContextObj]);

        glEnable(GL_TEXTURE_RECTANGLE_ARB);
        glGenTextures(1, &_surfaceTexture);
            glDisable(GL_TEXTURE_RECTANGLE_ARB);
    GLint swapInt = 1;//100;//1;
        [[self openGLContext] setValues:&swapInt forParameter:NSOpenGLCPSwapInterval]; 

    [[self openGLContext] makeCurrentContext];//make the current opengl the priority

    glMatrixMode(GL_TEXTURE);


    glGenTextures(1, &_surfaceTexture);
    glBindTexture(GL_TEXTURE_2D, _surfaceTexture);
    glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP_SGIS, GL_TRUE);

glTexImage2D(
                                 GL_TEXTURE_2D,
                                 0,
                                 GL_RGBA,
                                 displayWidth,//960,//1920,
                                 displayHeight,//540,//1080,
                                 0,
                                 GL_BGRA,//GL_YCBCR_422_APPLE,//GL_RGB,//GL_APPLE_ycbcr_422,
                                 GL_UNSIGNED_BYTE,//GL_BYTE,//GL_UNSIGNED_BYTE,//GL_UNSIGNED_SHORT_8_8_REV_APPLE,
                                 IOSurfaceGetBaseAddress(videoBuffer->ioSurfaceDataBuffer[bufferCounter].RGBDest ));

glBegin(GL_QUADS);
                    glTexCoord2f(0.0, 0.0);
                    glVertex3f(-1.0, -1.0, 0.0);
                    glTexCoord2f(1.0, 0.0);
                    glVertex3f(1.0, -1.0, 0.0);
                    glTexCoord2f(1.0, 1.0);
                    glVertex3f(1.0, 1.0, 0.0);
                    glTexCoord2f(0.0, 1.0);
                    glVertex3f(-1.0, 1.0, 0.0);
                    glEnd();
                    glFlush();  
                    threadTracking ("view 11\n");
                    printf("view 2.2) videoBuffer->ioSurfaceDataBuffer[bufferCounter].played  %d\n",videoBuffer->ioSurfaceDataBuffer[bufferCounter].played);

                    [[self openGLContext] flushBuffer]; 
A: 

I got the source from another video player that displays video information, here is what i added to add text directly the displayed frame with openGL.

char frameNumberBuffer[256];
CGColorSpaceRef frameCounterColorSpace;
CGContextRef frameCounterCglCtx;
frameCounterColorSpace = CGColorSpaceCreateWithName(kCGColorSpaceSRGB);

frameCounterCglCtx = CGBitmapContextCreate( IOSurfaceGetBaseAddress (videoBuffer->ioSurfaceDataBuffer[bufferCounter].RGBDest),
                                                              displayWidth, displayHeight, 8, IOSurfaceGetBytesPerRow(videoBuffer->ioSurfaceDataBuffer[bufferCounter].RGBDest),
                                                              frameCounterColorSpace, kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host);


CGContextSelectFont(frameCounterCglCtx, "Helvetica", 72.0, kCGEncodingMacRoman);
snprintf(frameNumberBuffer,256,"Frame Counter:  %d",playCounter);

CGContextSetRGBFillColor(frameCounterCglCtx, 1.0f, 0.0f, 0.0f, 1.0f);
CGContextShowTextAtPoint(frameCounterCglCtx, 100.0f, 100.0f, frameNumberBuffer, strlen(frameNumberBuffer));         

snprintf(frameNumberBuffer,256,"Buffer Counter:  %d",bufferCounter);

CGContextSetRGBFillColor(frameCounterCglCtx, 0.0f, 0.0f, 1.0f, 1.0f);
CGContextShowTextAtPoint(frameCounterCglCtx, 100.0f, 200.0f, frameNumberBuffer, strlen(frameNumberBuffer));         

where the IOSurfaceGetBaseAddress (videoBuffer->ioSurfaceDataBuffer[bufferCounter].RGBDest) returns the data pointer to my original frame data which was stored on an IOSurface

ReachConnection