2010-03-09 121 views
0

我需要在OpenGL視圖上繪製一個計數器。這是我的視頻幀顯示的源代碼。在OpenGL視圖中繪製文本

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

回答

0

我從另一個顯示視頻信息的視頻播放器獲得了源代碼,這裏是我添加的用於直接在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));   

其中IOSurfaceGetBaseAddress(videoBuffer-> ioSurfaceDataBuffer [bufferCounter] .RGBDest)返回數據指針向其中存儲在一個IOSurface

我的原始幀數據