Exemplo n.º 1
0
void CGuiGlut::InitializeGraphics (int argc, char **argv, CApplication* application)
{
	//
	m_application = application;

    // initialize GLUT state based on command line arguments
    glutInit (&argc, argv);

    // display modes: RGB+Z and double buffered
    GLint mode = GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE;
    glutInitDisplayMode (mode);

    // create and initialize our window with GLUT tools
    // (center window on screen with size equal to "ws" times screen size)
    const int sw = m_application->GetWindowInfo()->m_width; //glutGet (GLUT_SCREEN_WIDTH);
    const int sh = m_application->GetWindowInfo()->m_height; //glutGet (GLUT_SCREEN_HEIGHT);
    const float ws = 0.8f; // window_size / screen_size
    const int ww = (int) (sw * ws);
    const int wh = (int) (sh * ws);
    glutInitWindowPosition ((int) (sw * (1-ws)/2), (int) (sh * (1-ws)/2));
    glutInitWindowSize (ww, wh);
    windowID = glutCreateWindow (appVersionName.c_str());
    ReshapeFunc (ww, wh);
    InitGL ();

    // register our display function, make it the idle handler too
    glutDisplayFunc (&DisplayFunc);
    glutIdleFunc (&DisplayFunc);

    // register handler for window reshaping
    glutReshapeFunc (&ReshapeFunc);

    // register handler for keyboard events
    glutKeyboardFunc (&KeyboardFunc);
    glutSpecialFunc (&SpecialFunc);

    //// register handler for mouse button events
    //glutMouseFunc (&mouseButtonFunc);

    //// register handler to track mouse motion when any button down
    //glutMotionFunc (mouseMotionFunc);

    //// register handler to track mouse motion when no buttons down
    //glutPassiveMotionFunc (mousePassiveMotionFunc);

    //// register handler for when mouse enters or exists the window
    //glutEntryFunc (mouseEnterExitWindowFunc);

	m_application->Init();
}
Exemplo n.º 2
0
void CGLWindow_X::Execute()
{
m_created = true;
Select();
ReshapeFunc( m_width, m_height );
XMapWindow( m_display, m_window );
XEvent event;
while ( true )
  {
  XNextEvent( m_display, &event );
  LockForTerminate();
  switch ( event.type )
    {
    case Expose:
      DisplayFunc();
      break;
    case ConfigureNotify:
      ReshapeFunc( event.xconfigure.width, event.xconfigure.height );
      break;
    case KeyPress:
      {
      KEY_VK key = XKeyEventToKeyVK( &(event.xkey) );
      KeyboardFunc( KEYDIRECT_DOWN, KEY_MOD_NONE, key );
      }
      break;
    case KeyRelease:
      {
      KEY_VK key = XKeyEventToKeyVK( &(event.xkey) );
      KeyboardFunc( KEYDIRECT_UP, KEY_MOD_NONE, key );
      }
      break;
    case ButtonPress:
      {
      int x = event.xbutton.x;
      int y = event.xbutton.y;
      MB button = XButtonToMB( event.xbutton.button );
      MouseButtonFunc( MB_DOWN, x, y, button );
      }
      break;
    case ButtonRelease:
      {
      int x = event.xbutton.x;
      int y = event.xbutton.y;
      MB button = XButtonToMB( event.xbutton.button );
      MouseButtonFunc( MB_DOWN, x, y, button );
      }
      break;
    case MotionNotify:
      {
      int x = event.xmotion.x;
      int y = event.xmotion.y;
      MouseMotionFunc( x, y );
      }
      break;
    case CreateNotify:
//            XCreateWindowEvent xcreatewindow;
      break;
    case DestroyNotify:
      DestroyWindowFunc();
      return;
    default:
      break;
    };
  UnLockForTerminate();
  };
}
Exemplo n.º 3
0
void glutMainLoop(void)
{
   int idleiters;

   if(ReshapeFunc)
      ReshapeFunc(VarInfo.xres, VarInfo.yres);

   if(!DisplayFunc) {
      sprintf(exiterror, "Fatal Error: No Display Function registered\n");
      exit(0);
   }   

   for(;;) {
      ProcessTimers();

      if(Active)
	 ReceiveInput();
      else
	 if(VisiblePoll)
	    TestVisible();

      if(IdleFunc)
	 IdleFunc();
      
      if(VisibleSwitch) {
	 VisibleSwitch = 0;
	 if(VisibilityFunc)
	    VisibilityFunc(Visible ? GLUT_VISIBLE : GLUT_NOT_VISIBLE);
      }

      if(Resized) {
         SetVideoMode();
         CreateBuffer();

         if(!glFBDevMakeCurrent( Context, Buffer, Buffer )) {
            sprintf(exiterror, "Failure to Make Current\n");
            exit(0);
         }

         InitializeMenus();

         if(ReshapeFunc)
            ReshapeFunc(VarInfo.xres, VarInfo.yres);

         Redisplay = 1;
         Resized = 0;
      }

      if(Visible && Redisplay) {
	 Redisplay = 0;
         EraseCursor();
	 DisplayFunc();
	 if(!(DisplayMode & GLUT_DOUBLE)) {
	    if(ActiveMenu)
	       DrawMenus();
            DrawCursor();
	 }
         idleiters = 0;
      } else {
         /* we sleep if not receiving redisplays, and
            the main loop is running faster than 2khz */

         static int lasttime;
         int time = glutGet(GLUT_ELAPSED_TIME);
         if(time > lasttime) {
            if(idleiters >= 2)
               usleep(100);

            idleiters = 0;
            lasttime = time;
         }
         idleiters++;         
      }
   }
}