示例#1
0
void VID_Shutdown(void)
{
	if (context == NULL && window == NULL)
		return;

	VID_EnableJoystick(false);
	VID_SetMouse(false, false, false);
	VID_RestoreSystemGamma();

	if (context != NULL)
	{
		qaglDestroyContext(context);
		context = NULL;
	}

	if (vid_isfullscreen)
		CGReleaseAllDisplays();

	if (window != NULL)
	{
		DisposeWindow(window);
		window = NULL;
	}

	vid_hidden = true;
	vid_isfullscreen = false;

	GL_CloseLibrary();
	Key_ClearStates ();
}
示例#2
0
static void RLXAPI Shutdown(void)
{
	if (!g_pCGLC)
		return;

	CGDisplaySwitchToMode(g_cgDisplayID, g_cgPrevDisplayMode);
	CGReleaseAllDisplays();
	ShowMenuBar();
}
示例#3
0
void OpenGLApp::exitAPI(){
	delete renderer;
	
	aglSetCurrentContext(NULL);
	aglSetDrawable(glContext, NULL);
	aglDestroyContext(glContext);
	ReleaseWindow(window);

	if (fullscreen){
		CGReleaseAllDisplays();
		CGDisplaySwitchToMode(kCGDirectMainDisplay, initialMode);
	}
}
示例#4
0
static void RLXAPI Shutdown(void)
{
	if (!g_pAGLC)
		return;

	if (g_cgOldDisplayModeRestore)
	{
		CGDisplaySwitchToMode(g_cgDisplayID, g_cgPrevDisplayMode);
		CGReleaseAllDisplays();
		g_cgOldDisplayModeRestore = 0;
		ShowMenuBar();
	}
}
GHOST_TSuccess GHOST_SystemCarbon::beginFullScreen(const GHOST_DisplaySetting& setting, GHOST_IWindow **window, const bool stereoVisual)
{	
	GHOST_TSuccess success = GHOST_kFailure;

	// need yo make this Carbon all on 10.5 for fullscreen to work correctly
	CGCaptureAllDisplays();
	
	success = GHOST_System::beginFullScreen(setting, window, stereoVisual);
	
	if (success != GHOST_kSuccess) {
		// fullscreen failed for other reasons, release
		CGReleaseAllDisplays();
	}

	return success;
}
示例#6
0
void _glfwPlatformCloseWindow( void )
{
    if( _glfwWin.WindowFunctions != NULL )
    {
        if( _glfwWin.WindowUPP != NULL )
        {
            DisposeEventHandlerUPP( _glfwWin.WindowUPP );
            _glfwWin.WindowUPP = NULL;
        }

        _glfwWin.WindowFunctions->CloseWindow();

        if( !_glfwWin.Fullscreen && _glfwWin.AGLContext != NULL )
        {
            aglSetCurrentContext( NULL );
            aglSetDrawable( _glfwWin.AGLContext, NULL );
            aglDestroyContext( _glfwWin.AGLContext );
            _glfwWin.AGLContext = NULL;
        }

        if( _glfwWin.Fullscreen && _glfwWin.CGLContext != NULL )
        {
            CGLSetCurrentContext( NULL );
            CGLClearDrawable( _glfwWin.CGLContext );
            CGLDestroyContext( _glfwWin.CGLContext );
            CGReleaseAllDisplays();
            _glfwWin.CGLContext = NULL;
        }

        if( _glfwWin.MacWindow != NULL )
        {
            ReleaseWindow( _glfwWin.MacWindow );
            _glfwWin.MacWindow = NULL;
        }

        _glfwWin.WindowFunctions = NULL;
    }
}
void CL_DisplayWindow_OpenGL::set_windowed()
{
	if(!fullscreen)
		return;

	if (context == fs_context)
	{
	    aglSetDrawable(fs_context, 0);
	}
	
	CGReleaseAllDisplays();
	aglSetCurrentContext(win_context);
	aglUpdateContext(win_context);
	install_event_handler(GetWindowEventTarget(window_ref));

	fullscreen = false;
	context = win_context;
	focus = IsWindowHilited(window_ref);
	
	//After toggling to the fullscreen context, nothing is going draw unless
	//we reapply the GL states/properties -mrfun 6-2-2006
	CL_GLStateChecker::from_gc(get_gc())->reinitialize_asap();
	
}
GHOST_TSuccess GHOST_SystemCarbon::endFullScreen(void)
{	
	CGReleaseAllDisplays();
	return GHOST_System::endFullScreen();
}
示例#9
0
//-------------------------------------------------------------------------------------------------//
void OSXWindow::destroyCGLFullscreen(void)
{
	CGReleaseAllDisplays();
}
示例#10
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);
}
Window::Window(const Rect & rect, int fulls)
{ 
   m_rect = rect;
   m_win = 0;
   m_init = false;
   m_ctx = 0;
  
   //
   // Create the Carbon window:
   OSStatus s;

   if ( fulls ) {
      s = CreateNewWindow(kOverlayWindowClass,
         kWindowStandardHandlerAttribute | kWindowCompositingAttribute,
         &m_rect, &m_win);
      if(s != noErr) {
         fprintf(stderr,"failed to create window at %i,%i,%i,%i\n",m_rect.left,m_rect.top,m_rect.right,m_rect.bottom);
         abort();
      }

      // Hide Cursor
      CGCaptureAllDisplays();
      CGDisplayHideCursor(kCGDirectMainDisplay); 
      CGReleaseAllDisplays();
    
   }
   else
   {
      // just a little offset when opening the window
      s = CreateNewWindow(kDocumentWindowClass,
         kWindowStandardDocumentAttributes | kWindowStandardHandlerAttribute| kWindowInWindowMenuAttribute,
         &m_rect, &m_win);
      if(s != noErr) {
         fprintf(stderr,"failed to create window at %i,%i,%i,%i\n",m_rect.left,m_rect.top,m_rect.right,m_rect.bottom);
         abort();
      }

      // Put a title
      SetWindowTitleWithCFString (m_win, CFSTR("SAGE GStream Receiver"));
   }

   SetWindowActivationScope(m_win,kWindowActivationScopeAll);
   ShowWindow(m_win);
   ActivateWindow(m_win, true);


   if ( ! fulls ) {
      Rect arect;
      short hGlobal, vGlobal;
      GetWindowBounds(m_win, kWindowStructureRgn, &arect);
      MoveWindow (m_win, arect.left, (arect.top < 0) ? 40 : arect.top+50, true);
   }

   // Create context
   m_ctx = aglCreateContext(agl_fmt,0);
   if(m_ctx == 0) {
      fprintf(stderr,"failed to create OpenGL context\n");
      abort();
   }

   // Set the global context, shared by other windows:
   if(agl_ctx == 0) {
      agl_ctx = m_ctx;
   }

   //
   // All your window are belong to us:
   GLboolean e;
   e = aglSetDrawable(m_ctx,GetWindowPort(m_win));
   if(!e) {
      fprintf(stderr,"failed aglSetDrawable\n");
      abort();
   }

   // Initialize the OpenGL
   aglSetCurrentContext(m_ctx);
   glViewport(0,0,m_rect.right - m_rect.left,m_rect.bottom - rect.top);
    
    /* glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(m_rect.left,m_rect.right,m_rect.top,m_rect.bottom,-1,1);
    
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    */
    
   glClearColor(0,0,0,1);
   glClear(GL_COLOR_BUFFER_BIT);

   aglSwapBuffers(m_ctx);
}
示例#12
0
static int RLXAPI CreateSurface(int numberOfSparePages)
{
    CGOpenGLDisplayMask displayMask = CGDisplayIDToOpenGLDisplayMask( g_cgDisplayID ) ;
    static CGLPixelFormatAttribute attribs[32];
	CGLPixelFormatAttribute	*pAttrib =  attribs;
    CGLPixelFormatObj pixelFormatObj ;
    long numPixelFormats = 0;

	*pAttrib = kCGLPFAFullScreen; pAttrib++;
	*pAttrib = kCGLPFASingleRenderer; pAttrib++;

	*pAttrib = kCGLPFADisplayMask; pAttrib++;
	*pAttrib = (CGLPixelFormatAttribute)displayMask; pAttrib++;

	*pAttrib = kCGLPFADoubleBuffer; pAttrib++;
	*pAttrib = kCGLPFAColorSize; pAttrib++;
	*pAttrib = (CGLPixelFormatAttribute)gl_bpp; pAttrib++;

	 if ((g_pRLX->pGX->View.Flags & GX_CAPS_MULTISAMPLING))
	{
		*pAttrib = kCGLPFASampleBuffers; pAttrib++;
		*pAttrib = (CGLPixelFormatAttribute)1;  pAttrib++;

		*pAttrib = kCGLPFASamples;  pAttrib++;
		*pAttrib = (CGLPixelFormatAttribute)g_pRLX->pGX->View.Multisampling; pAttrib++;
	}

	if (SYS_CGLTRACE(CGLChoosePixelFormat( attribs, &pixelFormatObj, &numPixelFormats )))
		return -1;

    if (!numPixelFormats)
        return -2;

	DEBUG_PIXEL_FORMAT(pixelFormatObj);

    if (SYS_CGLTRACE(CGLCreateContext( pixelFormatObj, NULL, &g_pCGLC )))
       return -3;

    CGLDestroyPixelFormat( pixelFormatObj ) ;

    long swapInterval = !!(g_pRLX->pGX->View.Flags & GX_CAPS_VSYNC);
    SYS_CGLTRACE(CGLSetParameter( g_pCGLC, kCGLCPSwapInterval, &swapInterval));
    SYS_CGLTRACE(CGLSetCurrentContext( g_pCGLC ));
    if (SYS_CGLTRACE(CGLSetFullScreen( g_pCGLC )))
	{
		CGDisplaySwitchToMode(g_cgDisplayID, g_cgPrevDisplayMode);
		CGReleaseAllDisplays();

		return -5;
	}

	HideMenuBar();

    // Reset engine
    GL_InstallExtensions();
	GL_ResetViewport();

	g_pRLX->pGX->Surfaces.maxSurface = numberOfSparePages;;

	if (g_pRLX->pGX->View.Flags & GX_CAPS_MULTISAMPLING)
	{
		glEnable(GL_MULTISAMPLE_ARB);
	}

    return 0;
}
示例#13
0
void _glfwPlatformCloseWindow( void )
{
    if( _glfwWin.mouseUPP != NULL )
    {
        DisposeEventHandlerUPP( _glfwWin.mouseUPP );
        _glfwWin.mouseUPP = NULL;
    }
    if( _glfwWin.commandUPP != NULL )
    {
        DisposeEventHandlerUPP( _glfwWin.commandUPP );
        _glfwWin.commandUPP = NULL;
    }
    if( _glfwWin.keyboardUPP != NULL )
    {
        DisposeEventHandlerUPP( _glfwWin.keyboardUPP );
        _glfwWin.keyboardUPP = NULL;
    }
    if( _glfwWin.windowUPP != NULL )
    {
        DisposeEventHandlerUPP( _glfwWin.windowUPP );
        _glfwWin.windowUPP = NULL;
    }

    if( _glfwWin.fullscreen )
    {
        if( _glfwWin.cglContext != NULL )
        {
            CGLSetCurrentContext( NULL );
            CGLClearDrawable( _glfwWin.cglContext );
            CGLDestroyContext( _glfwWin.cglContext );
            CGReleaseAllDisplays();
            _glfwWin.cglContext = NULL;
        }

        if( _glfwWin.cglPixelFormat != NULL )
        {
            CGLDestroyPixelFormat( _glfwWin.cglPixelFormat );
            _glfwWin.cglPixelFormat = NULL;
        }
    }
    else
    {
        if( _glfwWin.aglContext != NULL )
        {
            aglSetCurrentContext( NULL );
            aglSetDrawable( _glfwWin.aglContext, NULL );
            aglDestroyContext( _glfwWin.aglContext );
            _glfwWin.aglContext = NULL;
        }

        if( _glfwWin.aglPixelFormat != NULL )
        {
            aglDestroyPixelFormat( _glfwWin.aglPixelFormat );
            _glfwWin.aglPixelFormat = NULL;
        }
    }

    if( _glfwWin.window != NULL )
    {
        ReleaseWindow( _glfwWin.window );
        _glfwWin.window = NULL;
    }
}
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;
}