bool DisplayResOSX::SwitchToVideoMode(int width, int height, double refreshrate) { CGDirectDisplayID d = GetOSXDisplay(MythDisplay::GetWindowID()); CFDictionaryRef dispMode = NULL; boolean_t match = 0; // find mode that matches the desired size if (refreshrate) dispMode = CGDisplayBestModeForParametersAndRefreshRate( d, 32, width, height, (CGRefreshRate)((short)refreshrate), &match); if (!match) dispMode = CGDisplayBestModeForParameters(d, 32, width, height, &match); if (!match) dispMode = CGDisplayBestModeForParameters(d, 16, width, height, &match); if (!match) return false; // switch mode and return success CGDisplayCapture(d); CGDisplayConfigRef cfg; CGBeginDisplayConfiguration(&cfg); CGConfigureDisplayFadeEffect(cfg, 0.3f, 0.5f, 0, 0, 0); CGConfigureDisplayMode(cfg, d, dispMode); CGError err = CGCompleteDisplayConfiguration(cfg, kCGConfigureForAppOnly); CGDisplayRelease(d); return (err == kCGErrorSuccess); }
static void *gfx_ctx_cgl_init(void *video_driver) { CGError err; gfx_ctx_cgl_data_t *cgl = (gfx_ctx_cgl_data_t*)calloc(1, sizeof(gfx_ctx_cgl_data_t)); if (!cgl) goto error; cgl->displayID = CGMainDisplayID(); err = CGDisplayCapture(cgl->displayID); if (err != kCGErrorSuccess) goto error; cgl->glCtx = gfx_ctx_cgl_init_create(); if (!cgl->glCtx) goto error; attach_gl_context_to_window(cgl->glCtx, CGShieldingWindowID(cgl->displayID), &cgl->width, &cgl->height); printf("size:%dx%d\n", cgl->width, cgl->height); CGLSetCurrentContext(cgl->glCtx); return cgl; error: gfx_ctx_cgl_destroy(cgl); return NULL; }
static void setup_screen(void) { CGDirectDisplayID targetDisplay = kCGDirectMainDisplay; CGDisplayCapture(targetDisplay); /* crucial for being permitted to write on it */ screen.base = (uint32_t *) CGDisplayBaseAddress(targetDisplay); screen.stride = CGDisplayBytesPerRow(targetDisplay) / sizeof(uint32_t); screen.width = CGDisplayPixelsWide(targetDisplay); screen.height = CGDisplayPixelsHigh(targetDisplay); }
static int RLXAPI SetDisplayMode(GXDISPLAYMODEHANDLE mode) { if ((g_pRLX->Video.Config & RLXVIDEO_Windowed)==0) { if (!g_cgOldDisplayModeRestore) { CGDisplayCapture(g_cgDisplayID); } CGDisplaySwitchToMode (g_cgDisplayID, DictRefToModeHandle(mode)); g_cgOldDisplayModeRestore = 1; } return 0; }
//-------------------------------------------------------------------------------------------------// void OSXWindow::createCGLFullscreen(unsigned int width, unsigned int height, unsigned int depth, unsigned int fsaa, CGLContextObj sharedContext) { // Find the best match to what was requested boolean_t exactMatch = 0; int reqWidth, reqHeight, reqDepth; #if defined(MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6 // Get a copy of the current display mode CGDisplayModeRef displayMode = CGDisplayCopyDisplayMode(kCGDirectMainDisplay); // Loop through all display modes to determine the closest match. // CGDisplayBestModeForParameters is deprecated on 10.6 so we will emulate it's behavior // Try to find a mode with the requested depth and equal or greater dimensions first. // If no match is found, try to find a mode with greater depth and same or greater dimensions. // If still no match is found, just use the current mode. CFArrayRef allModes = CGDisplayCopyAllDisplayModes(kCGDirectMainDisplay, NULL); for(int i = 0; i < CFArrayGetCount(allModes); i++) { CGDisplayModeRef mode = (CGDisplayModeRef)CFArrayGetValueAtIndex(allModes, i); String modeString = StringConverter::toString(CGDisplayModeGetWidth(mode)) + String(" x ") + StringConverter::toString(CGDisplayModeGetHeight(mode)) + String(" @ ") + StringConverter::toString(bitDepthFromDisplayMode(mode)) + "bpp."; LogManager::getSingleton().logMessage(modeString); if(bitDepthFromDisplayMode(mode) != depth) continue; if((CGDisplayModeGetWidth(mode) >= width) && (CGDisplayModeGetHeight(mode) >= height)) { displayMode = mode; exactMatch = 1; break; } } // No depth match was found if(!exactMatch) { for(int i = 0; i < CFArrayGetCount(allModes); i++) { CGDisplayModeRef mode = (CGDisplayModeRef)CFArrayGetValueAtIndex(allModes, i); if(bitDepthFromDisplayMode(mode) >= depth) continue; if((CGDisplayModeGetWidth(mode) >= width) && (CGDisplayModeGetHeight(mode) >= height)) { displayMode = mode; exactMatch = 1; break; } } } reqWidth = CGDisplayModeGetWidth(displayMode); reqHeight = CGDisplayModeGetHeight(displayMode); reqDepth = bitDepthFromDisplayMode(displayMode); #else CFDictionaryRef displayMode = CGDisplayBestModeForParameters(kCGDirectMainDisplay, depth, width, height, &exactMatch); const void *value = NULL; value = CFDictionaryGetValue(displayMode, kCGDisplayWidth); CFNumberGetValue((CFNumberRef)value, kCFNumberSInt32Type, &reqWidth); value = CFDictionaryGetValue(displayMode, kCGDisplayHeight); CFNumberGetValue((CFNumberRef)value, kCFNumberSInt32Type, &reqHeight); value = CFDictionaryGetValue(displayMode, kCGDisplayBitsPerPixel); CFNumberGetValue((CFNumberRef)value, kCFNumberSInt32Type, &reqDepth); #endif if(!exactMatch) { // TODO: Report the size difference // That mode is not available, using the closest match String request = StringConverter::toString(width) + String(" x ") + StringConverter::toString(height) + String(" @ ") + StringConverter::toString(depth) + "bpp. "; String received = StringConverter::toString(reqWidth) + String(" x ") + StringConverter::toString(reqHeight) + String(" @ ") + StringConverter::toString(reqDepth) + "bpp. "; LogManager::getSingleton().logMessage(String("RenderSystem Warning: You requested a fullscreen mode of ") + request + String(" This mode is not available and you will receive the closest match. The best display mode for the parameters requested is: ") + received); } // Do the fancy display fading CGDisplayFadeReservationToken reservationToken; CGAcquireDisplayFadeReservation(kCGMaxDisplayReservationInterval, &reservationToken); CGDisplayFade(reservationToken, 0.5, kCGDisplayBlendNormal, kCGDisplayBlendSolidColor, 0.0, 0.0, 0.0, true); // Grab the main display and save it for later. // You could render to any display, but picking what display // to render to could be interesting. CGDisplayCapture(kCGDirectMainDisplay); // Switch to the correct resolution #if defined(MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6 CGDisplaySetDisplayMode(kCGDirectMainDisplay, displayMode, NULL); #else CGDisplaySwitchToMode(kCGDirectMainDisplay, displayMode); #endif // Get a pixel format that best matches what we are looking for CGLPixelFormatAttribute attribs[] = { kCGLPFADoubleBuffer, kCGLPFAAlphaSize, (CGLPixelFormatAttribute)8, kCGLPFADepthSize, (CGLPixelFormatAttribute)reqDepth, kCGLPFAStencilSize, (CGLPixelFormatAttribute)8, kCGLPFASampleBuffers, (CGLPixelFormatAttribute)0, kCGLPFASamples, (CGLPixelFormatAttribute)0, kCGLPFAFullScreen, kCGLPFASingleRenderer, kCGLPFAAccelerated, kCGLPFADisplayMask, (CGLPixelFormatAttribute)CGDisplayIDToOpenGLDisplayMask(kCGDirectMainDisplay), (CGLPixelFormatAttribute)0 }; // Set up FSAA if it was requested if(fsaa > 1) { // turn on kCGLPFASampleBuffers attribs[8] = (CGLPixelFormatAttribute)1; // set the samples for kCGLPFASamples attribs[10] = (CGLPixelFormatAttribute)fsaa; } CGLError err; CGLPixelFormatObj pixelFormatObj; #if (MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_4) GLint numPixelFormats = 0; err = CGLChoosePixelFormat(attribs, &pixelFormatObj, &numPixelFormats); #else long numPixelFormats = 0; err = CGLChoosePixelFormat(attribs, &pixelFormatObj, &numPixelFormats); #endif if(err != 0) { CGReleaseAllDisplays(); OGRE_EXCEPT(Exception::ERR_RENDERINGAPI_ERROR, String("CGL Error: " + String(CGLErrorString(err))), "OSXWindow::createCGLFullscreen"); } // Create the CGLcontext from our pixel format, share it with the sharedContext passed in err = CGLCreateContext(pixelFormatObj, sharedContext, &mCGLContext); if(err != 0) { CGReleaseAllDisplays(); OGRE_EXCEPT(Exception::ERR_RENDERINGAPI_ERROR, String("CGL Error: " + String(CGLErrorString(err))), "OSXWindow::createCGLFullscreen"); } // Once we have the context we can destroy the pixel format // In order to share contexts you must keep a pointer to the context object around // Our context class will now manage the life of the pixelFormatObj //CGLDestroyPixelFormat(pixelFormatObj); // Set the context to full screen #if defined(MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6 CGLSetFullScreenOnDisplay(mCGLContext, CGDisplayIDToOpenGLDisplayMask(kCGDirectMainDisplay)); #else CGLSetFullScreen(mCGLContext); #endif // Set the context as current CGLSetCurrentContext(mCGLContext); // This synchronizes CGL with the vertical retrace // Apple docs suggest that OpenGL blocks rendering calls when waiting for // a vertical retrace anyhow. #if (MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_4) GLint swapInterval = 1; CGLSetParameter(mCGLContext, kCGLCPSwapInterval, &swapInterval); #else long swapInterval = 1; CGLSetParameter(mCGLContext, kCGLCPSwapInterval, &swapInterval); #endif // Give a copy of our context to the rendersystem mContext = new OSXCGLContext(mCGLContext, pixelFormatObj); // Let everyone know we are fullscreen now mIsFullScreen = true; // Set some other variables. Just in case we got a different value from CGDisplayBestModeForParameters than we requested mWidth = reqWidth; mHeight = reqHeight; mColourDepth = reqDepth; CGDisplayFade(reservationToken, 2.0, kCGDisplayBlendSolidColor, kCGDisplayBlendNormal, 0.0, 0.0, 0.0, false); CGReleaseDisplayFadeReservation(reservationToken); }
int doMain (int argc, char **argv) { int dummy; // OSG init OSG::osgInit(argc, argv); // create the graph // beacon for camera and light OSG::NodeUnrecPtr b1n = OSG::Node::create(); OSG::GroupUnrecPtr b1 = OSG::Group::create(); b1n->setCore( b1 ); // transformation OSG::NodeUnrecPtr t1n = OSG::Node::create(); OSG::TransformUnrecPtr t1 = OSG::Transform::create(); t1n->setCore( t1 ); t1n->addChild( b1n ); cam_trans = t1; // light OSG::NodeUnrecPtr dlight = OSG::Node::create(); OSG::DirectionalLightUnrecPtr dl = OSG::DirectionalLight::create(); dlight->setCore( dl ); dl->setAmbient( .3, .3, .3, 1 ); dl->setDiffuse( 1, 1, 1, 1 ); dl->setDirection(0,0,1); dl->setBeacon( b1n); // root root = OSG::Node::create(); OSG::GroupUnrecPtr gr1 = OSG::Group::create(); root->setCore( gr1 ); root->addChild( t1n ); root->addChild( dlight ); // Load the file OSG::NodeUnrecPtr file = NULL; if ( argc > 1 ) file = OSG::SceneFileHandler::the()->read(argv[1]); if ( file == NULL ) { std::cerr << "Couldn't load file, ignoring" << std::endl; file = OSG::makeTorus( .5, 2, 16, 16 ); } OSG::Thread::getCurrentChangeList()->commitChanges(); file->updateVolume(); OSG::Vec3f min,max; file->getVolume().getBounds( min, max ); std::cout << "Volume: from " << min << " to " << max << std::endl; dlight->addChild( file ); std::cerr << "Tree: " << std::endl; //root->dump(); // Camera cam = OSG::PerspectiveCamera::create(); cam->setBeacon( b1n ); cam->setFov( OSG::osgDegree2Rad( 90 ) ); cam->setNear( 0.1 ); cam->setFar( 100000 ); // Background OSG::SolidBackgroundUnrecPtr bkgnd = OSG::SolidBackground::create(); bkgnd->setColor(OSG::Color3f(0,0,1)); // Viewport vp = OSG::Viewport::create(); vp->setCamera( cam ); vp->setBackground( bkgnd ); vp->setRoot( root ); vp->setSize( 0,0, 1,1 ); // Action ract = OSG::RenderAction::create(); // tball OSG::Vec3f pos; pos.setValues(min[0] + ((max[0] - min[0]) * 0.5), min[1] + ((max[1] - min[1]) * 0.5), max[2] + ( max[2] - min[2] ) * 1.5 ); float scale = (max[2] - min[2] + max[1] - min[1] + max[0] - min[0]) / 6; OSG::Pnt3f tCenter(min[0] + (max[0] - min[0]) / 2, min[1] + (max[1] - min[1]) / 2, min[2] + (max[2] - min[2]) / 2); tball.setMode( OSG::Trackball::OSGObject ); tball.setStartPosition( pos, true ); tball.setSum( true ); tball.setTranslationMode( OSG::Trackball::OSGFree ); tball.setTranslationScale(scale); tball.setRotationCenter(tCenter); // CoreGL init // Install event handler EventHandlerUPP eventHandlerUPP = NewEventHandlerUPP(eventHandler); EventTypeSpec eventList[] = { { kEventClassTextInput, kEventTextInputUnicodeForKeyEvent }, { kEventClassMouse, kEventMouseDown }, { kEventClassMouse, kEventMouseUp }, { kEventClassMouse, kEventMouseDragged } }; InstallApplicationEventHandler(eventHandlerUPP, GetEventTypeCount(eventList), eventList, 0, 0); CGDisplayCapture(kCGDirectMainDisplay); CGLPixelFormatAttribute attribs[] = { kCGLPFADoubleBuffer, kCGLPFAFullScreen, kCGLPFADepthSize, (CGLPixelFormatAttribute)16, kCGLPFADisplayMask, (CGLPixelFormatAttribute)CGDisplayIDToOpenGLDisplayMask(kCGDirectMainDisplay), (CGLPixelFormatAttribute)0 }; CGLPixelFormatObj pixelFormatObj; GLint numPixelFormats; CGLChoosePixelFormat(attribs, &pixelFormatObj, &numPixelFormats); CGLContextObj contextObj; CGLCreateContext(pixelFormatObj, 0, &contextObj); CGLDestroyPixelFormat(pixelFormatObj); CGLSetCurrentContext(contextObj); CGLSetFullScreen(contextObj); // Create OpenSG window win = OSG::CoreGLWindow::create(); win->addPort( vp ); win->setContext ( contextObj ); win->init(); win->resize( CGDisplayPixelsWide(kCGDirectMainDisplay), CGDisplayPixelsHigh(kCGDirectMainDisplay) ); win->activate(); // do some OpenGL init. Will move into State Chunks later. glEnable( GL_DEPTH_TEST ); glEnable( GL_LIGHTING ); glEnable( GL_LIGHT0 ); redraw(); // Main loop ( event dispatching ) RunApplicationEventLoop(); // Cleanup CGLSetCurrentContext(0); CGLClearDrawable(contextObj); CGLDestroyContext(contextObj); CGReleaseAllDisplays(); DisposeEventHandlerUPP(eventHandlerUPP); ract = NULL; win = NULL; root = NULL; file = NULL; vp = NULL; cam_trans = NULL; cam = NULL; return 0; }
qboolean VID_InitMode(viddef_mode_t *mode) { const EventTypeSpec winEvents[] = { { kEventClassWindow, kEventWindowClosed }, { kEventClassWindow, kEventWindowCollapsing }, { kEventClassWindow, kEventWindowExpanded }, }; OSStatus carbonError; Rect windowBounds; CFStringRef windowTitle; AGLPixelFormat pixelFormat; GLint attributes [32]; GLenum error; if (!GL_OpenLibrary()) { Con_Printf("Unable to load GL driver\n"); return false; } if ((qaglChoosePixelFormat = (AGLPixelFormat (*) (const AGLDevice *gdevs, GLint ndev, const GLint *attribList))GL_GetProcAddress("aglChoosePixelFormat")) == NULL || (qaglCreateContext = (AGLContext (*) (AGLPixelFormat pix, AGLContext share))GL_GetProcAddress("aglCreateContext")) == NULL || (qaglDestroyContext = (GLboolean (*) (AGLContext ctx))GL_GetProcAddress("aglDestroyContext")) == NULL || (qaglDestroyPixelFormat = (void (*) (AGLPixelFormat pix))GL_GetProcAddress("aglDestroyPixelFormat")) == NULL || (qaglErrorString = (const GLubyte* (*) (GLenum code))GL_GetProcAddress("aglErrorString")) == NULL || (qaglGetError = (GLenum (*) (void))GL_GetProcAddress("aglGetError")) == NULL || (qaglSetCurrentContext = (GLboolean (*) (AGLContext ctx))GL_GetProcAddress("aglSetCurrentContext")) == NULL || (qaglSetDrawable = (GLboolean (*) (AGLContext ctx, AGLDrawable draw))GL_GetProcAddress("aglSetDrawable")) == NULL || (qaglSetFullScreen = (GLboolean (*) (AGLContext ctx, GLsizei width, GLsizei height, GLsizei freq, GLint device))GL_GetProcAddress("aglSetFullScreen")) == NULL || (qaglSetInteger = (GLboolean (*) (AGLContext ctx, GLenum pname, const GLint *params))GL_GetProcAddress("aglSetInteger")) == NULL || (qaglSwapBuffers = (void (*) (AGLContext ctx))GL_GetProcAddress("aglSwapBuffers")) == NULL ) { Con_Printf("AGL functions not found\n"); ReleaseWindow(window); return false; } qCGLEnable = (CGLError (*) (CGLContextObj ctx, CGLContextEnable pname)) CGL_GetProcAddress("CGLEnable"); qCGLDisable = (CGLError (*) (CGLContextObj ctx, CGLContextEnable pname)) CGL_GetProcAddress("CGLDisable"); qCGLGetCurrentContext = (CGLContextObj (*) (void)) CGL_GetProcAddress("CGLGetCurrentContext"); if(!qCGLEnable || !qCGLDisable || !qCGLGetCurrentContext) Con_Printf("CGL functions not found; disabling multithreaded OpenGL\n"); // Ignore the events from the previous window AsyncEvent_Quitting = false; AsyncEvent_Collapsed = false; // Create the window, a bit towards the center of the screen windowBounds.left = 100; windowBounds.top = 100; windowBounds.right = mode->width + 100; windowBounds.bottom = mode->height + 100; carbonError = CreateNewWindow(kDocumentWindowClass, kWindowStandardFloatingAttributes | kWindowStandardHandlerAttribute, &windowBounds, &window); if (carbonError != noErr || window == NULL) { Con_Printf("Unable to create window (error %u)\n", (unsigned)carbonError); return false; } // Set the window title windowTitle = CFSTR("DarkPlaces AGL"); SetWindowTitleWithCFString(window, windowTitle); // Install the callback function for the window events we can't get // through ReceiveNextEvent (i.e. close, collapse, and expand) InstallWindowEventHandler (window, NewEventHandlerUPP (MainWindowEventHandler), GetEventTypeCount(winEvents), winEvents, window, NULL); // Create the desired attribute list VID_BuildAGLAttrib(attributes, mode->bitsperpixel == 32, mode->fullscreen, mode->stereobuffer, mode->samples); if (!mode->fullscreen) { // Output to Window pixelFormat = qaglChoosePixelFormat(NULL, 0, attributes); error = qaglGetError(); if (error != AGL_NO_ERROR) { Con_Printf("qaglChoosePixelFormat FAILED: %s\n", (char *)qaglErrorString(error)); ReleaseWindow(window); return false; } } else // Output is fullScreen { CGDirectDisplayID mainDisplay; CFDictionaryRef refDisplayMode; GDHandle gdhDisplay; // Get the mainDisplay and set resolution to current mainDisplay = CGMainDisplayID(); CGDisplayCapture(mainDisplay); // TOCHECK: not sure whether or not it's necessary to change the resolution // "by hand", or if aglSetFullscreen does the job anyway refDisplayMode = CGDisplayBestModeForParametersAndRefreshRateWithProperty(mainDisplay, mode->bitsperpixel, mode->width, mode->height, mode->refreshrate, kCGDisplayModeIsSafeForHardware, NULL); CGDisplaySwitchToMode(mainDisplay, refDisplayMode); DMGetGDeviceByDisplayID((DisplayIDType)mainDisplay, &gdhDisplay, false); // Set pixel format with built attribs // Note: specifying a device is *required* for AGL_FullScreen pixelFormat = qaglChoosePixelFormat(&gdhDisplay, 1, attributes); error = qaglGetError(); if (error != AGL_NO_ERROR) { Con_Printf("qaglChoosePixelFormat FAILED: %s\n", (char *)qaglErrorString(error)); ReleaseWindow(window); return false; } } // Create a context using the pform context = qaglCreateContext(pixelFormat, NULL); error = qaglGetError(); if (error != AGL_NO_ERROR) { Con_Printf("qaglCreateContext FAILED: %s\n", (char *)qaglErrorString(error)); } // Make the context the current one ('enable' it) qaglSetCurrentContext(context); error = qaglGetError(); if (error != AGL_NO_ERROR) { Con_Printf("qaglSetCurrentContext FAILED: %s\n", (char *)qaglErrorString(error)); ReleaseWindow(window); return false; } // Discard pform qaglDestroyPixelFormat(pixelFormat); // Attempt fullscreen if requested if (mode->fullscreen) { qaglSetFullScreen (context, mode->width, mode->height, mode->refreshrate, 0); error = qaglGetError(); if (error != AGL_NO_ERROR) { Con_Printf("qaglSetFullScreen FAILED: %s\n", (char *)qaglErrorString(error)); return false; } } else { // Set Window as Drawable qaglSetDrawable(context, GetWindowPort(window)); error = qaglGetError(); if (error != AGL_NO_ERROR) { Con_Printf("qaglSetDrawable FAILED: %s\n", (char *)qaglErrorString(error)); ReleaseWindow(window); return false; } } if ((qglGetString = (const GLubyte* (GLAPIENTRY *)(GLenum name))GL_GetProcAddress("glGetString")) == NULL) Sys_Error("glGetString not found in %s", gl_driver); gl_platformextensions = ""; gl_platform = "AGL"; multithreadedgl = false; vid_isfullscreen = mode->fullscreen; vid_usingmouse = false; vid_usinghidecursor = false; vid_hidden = false; vid_activewindow = true; sound_active = true; GL_Init(); SelectWindow(window); ShowWindow(window); return true; }
static AGLContext createContext(WindowRef window) { AGLPixelFormat pf; AGLContext ctx; GDHandle gdh; CFDictionaryRef refMode; GLenum error; CGDirectDisplayID mainDisplay = CGMainDisplayID(); GLint attrs[] = { AGL_RGBA, AGL_DOUBLEBUFFER, AGL_RED_SIZE, 4, AGL_GREEN_SIZE, 4, AGL_BLUE_SIZE, 4, AGL_DEPTH_SIZE, 16, AGL_NONE }; GLint fullscreen_attrs[] = { AGL_FULLSCREEN, AGL_RGBA, AGL_DOUBLEBUFFER, AGL_RED_SIZE, 4, AGL_GREEN_SIZE, 4, AGL_BLUE_SIZE, 4, AGL_DEPTH_SIZE, 16, AGL_NONE }; g_Window.double_buffered = true; if (!g_Window.fs) { pf = aglChoosePixelFormat(NULL, 0, attrs); } else { CGDisplayCapture(mainDisplay); refMode = CGDisplayBestModeForParameters(mainDisplay, 32, g_Window.width, g_Window.height, NULL); CGDisplaySwitchToMode(mainDisplay, refMode); DMGetGDeviceByDisplayID(mainDisplay, &gdh, false); pf = aglChoosePixelFormat(&gdh, 1, fullscreen_attrs); error = aglGetError(); if (error != AGL_NO_ERROR) { printf("%s\n", aglErrorString(error)); return 0; } } if (!pf) { printf("Error choosing pixel format\n"); return 0; } ctx = aglCreateContext(pf, 0); if (!ctx) { printf("%s\n", aglErrorString(aglGetError())); return 0; } aglDestroyPixelFormat(pf); aglSetCurrentContext(ctx); if (g_Window.fs) { aglSetFullScreen(ctx, g_Window.width, g_Window.height, 0, 0); } else { aglSetWindowRef(ctx, window); } return ctx; }