Draw into Fullscreen GL Context
Ok this is a little tricky. I'm detecting when an application goes into fullscreen mode (captures the display) and then i need to draw occasionally some stuff into the captured displays context for notification purposes (like Growl notifications, but has to work in fullscreen mode too).
Is there any开发者_JS百科 way to modify another apps GL/CG context (For example Fraps on Windows does inject the FPS counter into OGL apps)? The shielding window overlay method unfortunately doesn't work when a display is captured. Any ideas?
The GLFullscreen sample application shows the old way and the 10.6+ way of creating fullscreen windows (and contexts). The new way is just a screen-sized window above most other things, while the old way is a special fullscreen mode that doesn't let anything else draw above it, with CGL. So if the application is using the new, simplified mechanism it may make a difference. I'm guessing you can't with the old way but might be able to with the new way.
You can in fact draw over the screen with plain OpenGL and the Quartz Display Services. There are some drawbacks tough that i don't know how to work around.
The
CGLSetFullScreen
is deprecated andCGLSetFullScreenOnDisplay
won't work with captured displays.The drawing flickers because the other GL context interferes with this one
.
CGOpenGLDisplayMask displayMask = CGDisplayIDToOpenGLDisplayMask(displayId);
CGLPixelFormatAttribute attribs[] = {
kCGLPFAFullScreen,
kCGLPFADisplayMask,
displayMask,
0
};
// Create gl context
GLint numPixelFormats;
CGLPixelFormatObj pixelFormatObj;
CGLChoosePixelFormat(attribs, &pixelFormatObj, &numPixelFormats);
CGLCreateContext(pixelFormatObj, NULL, &glContext);
CGLDestroyPixelFormat(pixelFormatObj);
CGLSetCurrentContext(glContext);
CGLSetFullScreen(glContext);
do {
glLoadIdentity();
glBegin(GL_TRIANGLES);
glColor3f(1.0f, 0.0f, 0.0f);
glVertex3f(0.0f, 1.0f, 0.0f);
glColor3f(0.0f, 1.0f, 0.0f);
glVertex3f(-1.0f, -1.0f, 0.0f);
glColor3f(0.0f, 0.0f, 1.0f);
glVertex3f(1.0f, -1.0f, 0.0f);
glEnd();
glFlush();
} while (!invalid);
精彩评论