Ejemplo n.º 1
0
int main(int argc, char** argv) {
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
	glutGameModeGet(GLUT_GAME_MODE_POSSIBLE);
	if(GLUT_GAME_MODE_POSSIBLE)
	{
		glutEnterGameMode(); 
	}
	else
	{
			RECT desktop;
		   // Get a handle to the desktop window
		   const HWND hDesktop = GetDesktopWindow();
		   // Get the size of screen to the variable desktop
		   GetWindowRect(hDesktop, &desktop);
		   width = desktop.right;
		   height = desktop.bottom-65;
			glutInitWindowSize(desktop.right, desktop.bottom-55);
		glutInitWindowPosition (0,0);
		glutCreateWindow("Six Sides of Destruction");
	}
	initRendering();
	glutDisplayFunc(screen_title);
	glutKeyboardFunc(handle_titlescreen_key);
	glutReshapeFunc(handleResize);
	glutTimerFunc(2, update, 0);
	
	glutMainLoop();
	return 0;
}
Ejemplo n.º 2
0
void ModeSelection::gameMode() {
	worldModel::initGame();	
	
	char c[16];
	Graphic::resolution(c);
	glutGameModeString(c);
	if (glutGameModeGet(GLUT_GAME_MODE_POSSIBLE)) 
		glutEnterGameMode();
	else {
		Error::MesBoxOk("Fehler", "Falscher Grafikmodus");
		exit(1);
	}

	glClearColor(0.5, 0.5, 0.5, 1.0);
	
	
	
	GraIngame::init();

	glShadeModel(GL_SMOOTH);
	glDepthFunc(GL_LEQUAL);
	glEnable(GL_DEPTH_TEST);
	glutKeyboardFunc(ViewAndControl::input);
	glutSpecialFunc(ViewAndControl::inputSp);
	glutMouseFunc(ViewAndControl::mouse);
	glutDisplayFunc(ViewAndControl::draw);
	glutIdleFunc(ViewAndControl::mouse_calc);
	glutReshapeFunc(Graphic::changeSize);
	glutPassiveMotionFunc(ViewAndControl::mouseMove);
	glutMotionFunc(ViewAndControl::mouseMove);
	//glutTimerFunc(10,worldModel::unitMovement,10);
	glutTimerFunc(1000,worldModel::partyCalc,10);
}
Ejemplo n.º 3
0
// Main Function For Bringing It All Together.
int main(int argc, char** argv)
{
	ask_gamemode();                                  // Ask For Fullscreen Mode
	glutInit(&argc, argv);                           // GLUT Initializtion
	glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);     // Display Mode (Rgb And Double Buffered)
	if(g_gamemode){
		glutGameModeString("640x480:16");            // Select The 640x480 In 16bpp Mode
		if (glutGameModeGet(GLUT_GAME_MODE_POSSIBLE))
			glutEnterGameMode();                     // Enter Full Screen
		else g_gamemode = false;                     // Cannot Enter Game Mode, Switch To Windowed
	}
	if( ! g_gamemode){
		glutInitWindowSize(WCX, WCY);                // Window Size If We Start In Windowed Mode
		glutCreateWindow("NeHe's OpenGL Framework"); // Window Title 
	}
	if( ! InitGL()){                                 // Our Initialization
		return 1;
	}
	glutDisplayFunc(DrawGLScene);                    // Register The Display Function
	glutReshapeFunc(ReSizeGLScene);                  // Register The Reshape Handler
	glutKeyboardFunc(keyboard);                      // Register The Keyboard Handler
	glutSpecialFunc(special_keys);                   // Register Special Keys Handler
	glutTimerFunc (20, Update, 20);					 // post a redraw every 20 milliseconds
	glutMainLoop();                                  // Go To GLUT Main Loop
	return 0;
}
Ejemplo n.º 4
0
// Main Function For Bringing It All Together.
int main(int argc, char** argv)
{
	ask_gamemode();                                  // Ask For Fullscreen Mode
	glutInit(&argc, argv);                           // GLUT Initializtion
	glutInitDisplayMode(GLUT_DEPTH | GLUT_RGB | GLUT_DOUBLE); // (CHANGED)
	if (g_gamemode) {
		glutGameModeString("640x480:32");            // Select The 640x480 In 32bpp Mode
		if (glutGameModeGet(GLUT_GAME_MODE_POSSIBLE))
			glutEnterGameMode();                     // Enter Full Screen
		else g_gamemode = false;                     // Cannot Enter Game Mode, Switch To Windowed
	}
	if (!g_gamemode) {
		glutInitWindowSize(640, 480);                // Window Size If We Start In Windowed Mode
		glutCreateWindow("DirectShow VideoCapture OpenGL/GLUT Sample, "
						 "© 2002 Thomas Pintaric");	 // Window Title 
	}
	if (!init()) {                                   // Our Initialization
		MessageBox(NULL,"Cannot initialize textures.","Error",MB_ICONSTOP);
		return -1;
	}

	if (!setup_dsWrapper(argc > 1 ? argv[1] : "")) {        // DirectShow Capture Graph Initialization
		MessageBox(NULL,"Cannot initialize capture graph.","Error",MB_ICONSTOP);
		return -1;
	}

	glutDisplayFunc(render);                         // Register The Display Function
	glutReshapeFunc(reshape);                        // Register The Reshape Handler
	glutKeyboardFunc(keyboard);                      // Register The Keyboard Handler
	glutSpecialFunc(special_keys);                   // Register Special Keys Handler
	glutIdleFunc(render);                            // We Render In Idle Time
	glutMainLoop();                                  // Go To GLUT Main Loop
	return 0;
}
Ejemplo n.º 5
0
void normalKeyboard(unsigned char key, int xx, int yy)
{

	glutSetMenu(mainMenu);
	switch (key) {
		case 27:
			glutDestroyMenu(mainMenu);
			glutDestroyMenu(fillMenu);
			glutDestroyMenu(colorMenu);
			glutDestroyMenu(shrinkMenu);
			exit(0);
			break;

		case 's':
			if (!menuFlag)
			  glutChangeToSubMenu(2,"Shrink",shrinkMenu);
			break;
		case 'c':
			if (!menuFlag)
				glutChangeToSubMenu(2,"Color",colorMenu);
			break;
	}
	if (key == 27)
        if (glutGameModeGet(GLUT_GAME_MODE_ACTIVE) != 0)
				glutLeaveGameMode();
		exit(0);
}
Ejemplo n.º 6
0
void KPGlutUserInterface::SetWindowMode(bool FullScreen) const
{
    if (windowID == 0 || !CanToggleFullScreen())
    {
        return;
    }

    if (FullScreen)
    {
        std::stringstream modeString;

        modeString
                << config->ScreenXResolution << 'x'
                << ((config->ScreenXResolution * 3) / 4) << ':'
                << config->ColorDepth;

        glutGameModeString(modeString.str().c_str());

        if (!glutGameModeGet(GLUT_GAME_MODE_POSSIBLE))
        {
            std::cout << "  No Game Mode possible!" << std::endl << std::endl;
        }

        glutFullScreen();
    }
    else
    {
        glutReshapeWindow(config->ScreenXResolution,
                          (config->ScreenXResolution * 3) / 4);
        glutPositionWindow(1, 0);
        glutPositionWindow(0, 0);
    }
}
Ejemplo n.º 7
0
void StopEventLoop()
{
    if(glutGameModeGet(GLUT_GAME_MODE_ACTIVE)){
        glutLeaveGameMode();
    }
	glutLeaveMainLoop();
}
Ejemplo n.º 8
0
//------------------------------------------------------------
void ofAppGlutWindow::setupOpenGL(int w, int h, int screenMode){

	int argc = 1;
	char *argv = (char*)"openframeworks";
	char **vptr = &argv;
	glutInit(&argc, vptr);

	if( displayString != ""){
		glutInitDisplayString( displayString.c_str() );
	}else{
		if(bDoubleBuffered){  
			glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH | GLUT_ALPHA );
		}else{
			glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE | GLUT_DEPTH | GLUT_ALPHA );
		}
	}

	windowMode = screenMode;
	bNewScreenMode = true;

	if (windowMode != OF_GAME_MODE){
		glutInitWindowSize(w, h);
		glutCreateWindow("");

		/*
		ofBackground(200,200,200);		// default bg color
		ofSetColor(0xFFFFFF); 			// default draw color
		// used to be black, but
		// black + texture = black
		// so maybe grey bg
		// and "white" fg color
		// as default works the best...
		*/

		requestedWidth  = glutGet(GLUT_WINDOW_WIDTH);
		requestedHeight = glutGet(GLUT_WINDOW_HEIGHT);
	} else {
		if( displayString != ""){
			glutInitDisplayString( displayString.c_str() );
		}else{
			glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH | GLUT_ALPHA );
		}

    	// w x h, 32bit pixel depth, 60Hz refresh rate
		char gameStr[64];
		sprintf( gameStr, "%dx%d:%d@%d", w, h, 32, 60 );

    	glutGameModeString(gameStr);

    	if (!glutGameModeGet(GLUT_GAME_MODE_POSSIBLE)){
    		ofLog(OF_LOG_ERROR,"game mode error: selected format (%s) not available \n", gameStr);
    	}
    	// start fullscreen game mode
    	glutEnterGameMode();
	}
	windowW = glutGet(GLUT_WINDOW_WIDTH);
	windowH = glutGet(GLUT_WINDOW_HEIGHT);
}
Ejemplo n.º 9
0
void GLUTAPIENTRY
glutLeaveGameMode (void)
{
   if (glutGameModeGet(GLUT_GAME_MODE_ACTIVE)) {
      game_active = GL_FALSE;

      glutDestroyWindow(game);
   }
}
Ejemplo n.º 10
0
int main(int argc, char **argv)
{
  glutInit(&argc, argv);

  // Configure GLUT:
  //  - framebuffer with RGB + Alpha values per pixel
  //  - Z-buffer
  //  - two sets of above mentioned buffers, so that
  //    doublebuffering is possible
  //
  glutInitDisplayMode(GLUT_RGBA | GLUT_DEPTH | GLUT_DOUBLE);

  // Print the title
  printf("\nApache mod_helicopter\n\n");

  // Handle arguments
  int window_mode;
  window_mode = 0;
  // Use (forced) window mode?
  if(argc > 1 && (strcmp(argv[1], "-w") == 0)) {
    printf("	-w	Using window mode\n");
    window_mode = 1;

  }

  // Clear some space before program output
  printf("\n\n");

  // Setup window (1024x768)
  // Check if fullscreen is possible
  if (glutGameModeGet(GLUT_GAME_MODE_POSSIBLE) && !(window_mode == 1)) {
    // Start fullscreen game mode
    glutGameModeString("1024x768:32@60");
    glutEnterGameMode();
  } else {
    // Use regular window
    glutInitWindowSize(1024, 768);
    glutCreateWindow("Apache mod_helicopter");
  }

  // Hide the mouse cursor
  glutSetCursor(GLUT_CURSOR_NONE);

  // Initialize everything!
  initHelperLibrary();
  init();

  // Register our display- and idle-functions with GLUT
  glutDisplayFunc(display);
  glutIdleFunc(idle);

  // Enter GLUT's main loop; this function will never return
  glutMainLoop();

  return 0;
}
Ejemplo n.º 11
0
// initialize the render window
void initwindow(int width,int height)
   {
   miniscene::MINISCENE_PARAMS prms;

   viewer->get(prms);

   if (sw_full==0)
      {
      winwidth=width;
      winheight=height;
      }
   else
      {
      winwidth=glutGameModeGet(GLUT_GAME_MODE_WIDTH);
      winheight=glutGameModeGet(GLUT_GAME_MODE_HEIGHT);

      prms.fps=glutGameModeGet(GLUT_GAME_MODE_REFRESH_RATE);

      if (winwidth<=0 || winheight<=0 || prms.fps<=0.0f)
         {
         winwidth=width;
         winheight=height;

         prms.fps=VIEWER_FPS;
         }
      }

   if (winwidth<1) winwidth=1;
   if (winheight<1) winheight=1;

   prms.winwidth=winwidth;
   prms.winheight=winheight;

   viewer->set(prms);

   glViewport(0,0,winwidth,winheight);
   }
Ejemplo n.º 12
0
int APIENTRY
glutEnterGameMode (void)
{
   if (glutGameModeGet(GLUT_GAME_MODE_POSSIBLE)) {
      _glut_visual.bpp = game_bpp;
      _glut_visual.refresh = game_refresh;

      glutInitWindowSize(game_width, game_height);

      if ((game = glutCreateWindow("<game>")) > 0) {
         game_active = GL_TRUE;
      }

      return game;
   } else {
      return 0;
   }
}
Ejemplo n.º 13
0
void Window::setup(int *argc, char **argv) {
  glutInit(argc, argv);
  glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH | GLUT_STENCIL | GLUT_MULTISAMPLE);
  glutInitWindowSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);
  glutCreateWindow("glPortal");
  glutWarpPointer(width/2, height/2); // Center pointer  

  if (glutGameModeGet(GLUT_GAME_MODE_POSSIBLE)){
    glutGameModeString("1680x1050:32@60");
    glutEnterGameMode();
  }
  else {
    printf("Game mode not available using default.\n");
  } 
  glutSetCursor(GLUT_CURSOR_NONE);
  setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);
  glewInit();

}
Ejemplo n.º 14
0
int main (int argc, char **argv)
{
    glutInit (&argc, argv);
    glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH | GLUT_STENCIL);
    if (isGameMode)
    {
        glutGameModeString ("1024x768:32");
        if (glutGameModeGet (GLUT_GAME_MODE_POSSIBLE))
        glutEnterGameMode ();
        else
        isGameMode = 0;
    }
    if (!isGameMode)
    {
        glutInitWindowSize (1024, 768);
        glutCreateWindow ("tetris");
    }
    initWindow ();
    initDisplayLists ();
    glutMainLoop ();
    return 0;
}
Ejemplo n.º 15
0
//-------------------------------------------------------------------------
//  Swap Full screen.  
//-------------------------------------------------------------------------
void windows_togglefullscreen_cb(puObject* obj)
{

  if( glutGameModeGet(GLUT_GAME_MODE_ACTIVE)) return;
  int aWin = glutGetWindow();
  switch (globals->mScreen.full)  {
    case 0:
      { glutSetWindow(1);
        glutFullScreen();
        globals->mScreen.full = 1;
        return;
      }
    case 1:
      { glutSetWindow(1);
        glutReshapeWindow(globals->mScreen.Width,
                        globals->mScreen.Height);
        glutPositionWindow( 0, 0 );
        globals->mScreen.full = 0;
        return;
      }
  }
  return;
}
Ejemplo n.º 16
0
// Main Function For Bringing It All Together.
int main(int argc, char** argv)
{
	ask_gamemode();                                  // Ask For Fullscreen Mode
	glutInit(&argc, argv);                           // GLUT Initializtion
	glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);     // Display Mode (Rgb And Double Buffered)
	if (g_gamemode) {
		glutGameModeString("640x480:16");            // Select The 640x480 In 16bpp Mode
		if (glutGameModeGet(GLUT_GAME_MODE_POSSIBLE))
			glutEnterGameMode();                     // Enter Full Screen
		else g_gamemode = false;                     // Cannot Enter Game Mode, Switch To Windowed
	}
	if (!g_gamemode) {
		glutInitWindowSize(w, h);                // Window Size If We Start In Windowed Mode
		glutCreateWindow("SolarSystem"); // Window Title 
	}
	init();                                          // Our Initialization
	glutDisplayFunc(render);                         // Register The Display Function
	glutReshapeFunc(reshape);                        // Register The Reshape Handler
	glutKeyboardFunc(keyboard);                      // Register The Keyboard Handler
	glutSpecialFunc(special_keys);                   // Register Special Keys Handler
	glutMainLoop();                                  // Go To GLUT Main Loop
	return 0;
}
Ejemplo n.º 17
0
void GLInit() 
{
	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA);

	glutInitWindowPosition(0, 0);
	glutInitWindowSize(1024, 768);
	glutCreateWindow("Paper Tower Defense");
	
	glutGameModeString("1024x768:32@60");
	if (glutGameModeGet(GLUT_GAME_MODE_POSSIBLE) == true)
	{
		//glutEnterGameMode();
	}
	else 
	{
		//Exit();
	}

	glutIgnoreKeyRepeat(true);
	glutKeyboardFunc(HandleNormalKeyDown);
	glutSpecialFunc(HandleSpecialKeyDown);
	glutSpecialUpFunc(HandleSpecialKeyUp);
	glutPassiveMotionFunc(HandlePassiveMouseMotion);
	glutMotionFunc(HandleMouseMotion);
	glutMouseFunc(HandleMouseEvent);
	glutDisplayFunc(ProcessFrame);
	glutIdleFunc(ProcessFrame);
	glutReshapeFunc(ResizeWindow);

	glutSetCursor(GLUT_CURSOR_NONE);

	glEnable(GL_TEXTURE_2D);
	glEnable(GL_ALPHA_TEST);
	glAlphaFunc(GL_GREATER, 0.0f);
	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
Ejemplo n.º 18
0
void initGL(int argc, char** argv){
	// Inicialização do GLUT
	glutInit(&argc, argv);

	glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH | GLUT_RGBA);
	
	glutGameModeString(OGLWindow_getGameModeString());
	if(glutGameModeGet(GLUT_GAME_MODE_POSSIBLE))
	{
		OGLWindow_initGameMode();
	}
	else // Cria Janela Normal
	{
		OGLWindow_initWindowMode();
	}



	// Registar funções de callback
	glutDisplayFunc(display);
	glutReshapeFunc(reshape);
	glutIdleFunc(display);
	glutIgnoreKeyRepeat(1);
	glutKeyboardFunc(pressNormalKeys);
	glutKeyboardUpFunc(releaseNormalKeys);
	glutSpecialFunc(pressSpecialKey);
	glutSpecialUpFunc(releaseSpecialKey);
	glutMotionFunc(mouseMove);

	glutMouseFunc(mouseClick);

	// - Directly redirect GLUT mouse button events to AntTweakBar
	//glutMouseFunc((GLUTmousebuttonfun)TwEventMouseButtonGLUT);
	// - Directly redirect GLUT mouse "passive" motion events to AntTweakBar (same as MouseMotion)
	glutPassiveMotionFunc((GLUTmousemotionfun)TwEventMouseMotionGLUT);
}
Ejemplo n.º 19
0
ScreenGL::ScreenGL( int inWide, int inHigh, char inFullScreen, 
                    unsigned int inMaxFrameRate,
                    char inRecordEvents,
					const char *inWindowName,
					KeyboardHandlerGL *inKeyHandler,
					MouseHandlerGL *inMouseHandler,
					SceneHandlerGL *inSceneHandler  ) 
	: mWide( inWide ), mHigh( inHigh ),
      mImageSizeSet( false ),
      mImageWide( inWide ), mImageHigh( inHigh ), 
      mFullScreen( inFullScreen ),
      m2DMode( false ),
	  mViewPosition( new Vector3D( 0, 0, 0 ) ),
	  mViewOrientation( new Angle3D( 0, 0, 0 ) ),
	  mMouseHandlerVector( new SimpleVector<MouseHandlerGL*>() ),
	  mKeyboardHandlerVector( new SimpleVector<KeyboardHandlerGL*>() ),
	  mSceneHandlerVector( new SimpleVector<SceneHandlerGL*>() ),
	  mRedrawListenerVector( new SimpleVector<RedrawListenerGL*>() ) {


	// add handlers if NULL (the default) was not passed in for them
	if( inMouseHandler != NULL ) {
		addMouseHandler( inMouseHandler );
		}
	if( inKeyHandler != NULL ) {
		addKeyboardHandler( inKeyHandler );
		}
	if( inSceneHandler != NULL ) {
		addSceneHandler( inSceneHandler );
		}

	
	if( mFullScreen ) {
		glutInitDisplayMode( 
			GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH );
            //| GLUT_FULLSCREEN );
		}
	else {
		glutInitDisplayMode( 
			GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH );
		}
	
    if( !mFullScreen ) {
        
        glutInitWindowSize( mWide, mHigh );
        glutCreateWindow( inWindowName );
        }
    else {
        // use game mode for full screen
        char *gameMode = autoSprintf( "%dx%d:32", mWide, mHigh );
        
        glutGameModeString( gameMode );
        
        if( glutGameModeGet( GLUT_GAME_MODE_POSSIBLE ) ) {
            glutEnterGameMode();
            delete [] gameMode;
            }
        else {
            printf( "The full-screen mode %s is not available\n", gameMode );
            delete [] gameMode;
            exit(1);
            }        
        }

    glutIgnoreKeyRepeat( 1 );
    

	glutKeyboardFunc( callbackKeyboard );
	glutKeyboardUpFunc( callbackKeyboardUp );
	glutSpecialFunc( callbackSpecialKeyboard );
	glutSpecialUpFunc( callbackSpecialKeyboardUp );
	glutReshapeFunc( callbackResize );
	glutMotionFunc( callbackMotion );
	glutMouseFunc( callbackMouse );
	glutPassiveMotionFunc( callbackPassiveMotion );
	glutDisplayFunc( callbackDisplay );
	glutIdleFunc( callbackIdle );
	
	glEnable( GL_DEPTH_TEST );
	glEnable( GL_CULL_FACE );
	glEnable( GL_BLEND );
	glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
	glCullFace( GL_BACK );
	glFrontFace( GL_CCW );
	
	}
Ejemplo n.º 20
0
int main(int argc, char** argv)
{
	char    glutGamemode[32] = "";
    char   *vconf = NULL;
    char    cparaDefault[] = "Data2/camera_para.dat";
    char   *cpara = NULL;
    int     i;
    int     gotTwoPartOption;
    const char markerConfigDataFilename[] = "Data2/markers.dat";
	const char objectDataFilename[] = "Data2/objects.dat";
	
#ifdef DEBUG
    arLogLevel = AR_LOG_LEVEL_DEBUG;
#endif
    
    //
	// Process command-line options.
	//
    
	glutInit(&argc, argv);
    
    i = 1; // argv[0] is name of app, so start at 1.
    while (i < argc) {
        gotTwoPartOption = FALSE;
        // Look for two-part options first.
        if ((i + 1) < argc) {
            if (strcmp(argv[i], "--vconf") == 0) {
                i++;
                vconf = argv[i];
                gotTwoPartOption = TRUE;
            } else if (strcmp(argv[i], "--cpara") == 0) {
                i++;
                cpara = argv[i];
                gotTwoPartOption = TRUE;
            } else if (strcmp(argv[i],"--width") == 0) {
                i++;
                // Get width from second field.
                if (sscanf(argv[i], "%d", &prefWidth) != 1) {
                    ARLOGe("Error: --width option must be followed by desired width.\n");
                }
                gotTwoPartOption = TRUE;
            } else if (strcmp(argv[i],"--height") == 0) {
                i++;
                // Get height from second field.
                if (sscanf(argv[i], "%d", &prefHeight) != 1) {
                    ARLOGe("Error: --height option must be followed by desired height.\n");
                }
                gotTwoPartOption = TRUE;
            } else if (strcmp(argv[i],"--refresh") == 0) {
                i++;
                // Get refresh rate from second field.
                if (sscanf(argv[i], "%d", &prefRefresh) != 1) {
                    ARLOGe("Error: --refresh option must be followed by desired refresh rate.\n");
                }
                gotTwoPartOption = TRUE;
            }
        }
        if (!gotTwoPartOption) {
            // Look for single-part options.
            if (strcmp(argv[i], "--help") == 0 || strcmp(argv[i], "-help") == 0 || strcmp(argv[i], "-h") == 0) {
                usage(argv[0]);
            } else if (strncmp(argv[i], "-cpara=", 7) == 0) {
                cpara = &(argv[i][7]);
            } else if (strcmp(argv[i], "--version") == 0 || strcmp(argv[i], "-version") == 0 || strcmp(argv[i], "-v") == 0) {
                ARLOG("%s version %s\n", argv[0], AR_HEADER_VERSION_STRING);
                exit(0);
            } else if (strcmp(argv[i],"--windowed") == 0) {
                prefWindowed = TRUE;
            } else if (strcmp(argv[i],"--fullscreen") == 0) {
                prefWindowed = FALSE;
            } else {
                ARLOGe("Error: invalid command line argument '%s'.\n", argv[i]);
                usage(argv[0]);
            }
        }
        i++;
    }
    

	//
	// Video setup.
	//
    
	if (!setupCamera((cpara ? cpara : cparaDefault), vconf, &gCparamLT)) {
		ARLOGe("main(): Unable to set up AR camera.\n");
		exit(-1);
	}

    //
    // AR init.
    //
    
    if (!initNFT(gCparamLT, arVideoGetPixelFormat())) {
		ARLOGe("main(): Unable to init NFT.\n");
		exit(-1);
    }

    //
    // Markers setup.
    //
    
    // Load marker(s).
    newMarkers(markerConfigDataFilename, &markersNFT, &markersNFTCount);
    if (!markersNFTCount) {
        ARLOGe("Error loading markers from config. file '%s'.\n", markerConfigDataFilename);
		cleanup();
		exit(-1);
    }
    ARLOGi("Marker count = %d\n", markersNFTCount);
    
    // Marker data has been loaded, so now load NFT data.
    if (!loadNFTData()) {
        ARLOGe("Error loading NFT data.\n");
		cleanup();
		exit(-1);
    }
	
	//
	// Graphics setup.
	//

	// Set up GL context(s) for OpenGL to draw into.
	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
    if (prefWindowed) {
        if (prefWidth > 0 && prefHeight > 0) glutInitWindowSize(prefWidth, prefHeight);
        else glutInitWindowSize(gCparamLT->param.xsize, gCparamLT->param.ysize);
        glutCreateWindow(argv[0]);
    } else {
        if (glutGameModeGet(GLUT_GAME_MODE_POSSIBLE)) {
            if (prefWidth && prefHeight) {
                if (prefDepth) {
                    if (prefRefresh) snprintf(glutGamemode, sizeof(glutGamemode), "%ix%i:%i@%i", prefWidth, prefHeight, prefDepth, prefRefresh);
                    else snprintf(glutGamemode, sizeof(glutGamemode), "%ix%i:%i", prefWidth, prefHeight, prefDepth);
                } else {
                    if (prefRefresh) snprintf(glutGamemode, sizeof(glutGamemode), "%ix%i@%i", prefWidth, prefHeight, prefRefresh);
                    else snprintf(glutGamemode, sizeof(glutGamemode), "%ix%i", prefWidth, prefHeight);
                }
            } else {
                prefWidth = glutGameModeGet(GLUT_GAME_MODE_WIDTH);
                prefHeight = glutGameModeGet(GLUT_GAME_MODE_HEIGHT);
                snprintf(glutGamemode, sizeof(glutGamemode), "%ix%i", prefWidth, prefHeight);
            }
            glutGameModeString(glutGamemode);
            glutEnterGameMode();
        } else {
            if (prefWidth > 0 && prefHeight > 0) glutInitWindowSize(prefWidth, prefHeight);
            glutCreateWindow(argv[0]);
            glutFullScreen();
        }
    }
    
    // Create the OpenGL projection from the calibrated camera parameters.
    arglCameraFrustumRH(&(gCparamLT->param), VIEW_DISTANCE_MIN, VIEW_DISTANCE_MAX, cameraLens);
    cameraPoseValid = FALSE;
    
	// Setup ARgsub_lite library for current OpenGL context.
	if ((gArglSettings = arglSetupForCurrentContext(&(gCparamLT->param), arVideoGetPixelFormat())) == NULL) {
		ARLOGe("main(): arglSetupForCurrentContext() returned error.\n");
		cleanup();
		exit(-1);
	}
    
    // Load objects (i.e. OSG models).
    VirtualEnvironmentInit(objectDataFilename);
    VirtualEnvironmentHandleARViewUpdatedCameraLens(cameraLens);
    
    //
    // Setup complete. Start tracking.
    //
    
    // Start the video.
    if (arVideoCapStart() != 0) {
    	ARLOGe("setupCamera(): Unable to begin camera data capture.\n");
		return (FALSE);
	}
	arUtilTimerReset();
	
	// Register GLUT event-handling callbacks.
	// NB: mainLoop() is registered by Visibility.
	glutDisplayFunc(Display);
	glutReshapeFunc(Reshape);
	glutVisibilityFunc(Visibility);
	glutKeyboardFunc(Keyboard);
	
	glutMainLoop();

	return (0);
}
Ejemplo n.º 21
0
// ------------------------------------------------------------------
// Name : initGlutWindow
// ------------------------------------------------------------------
void DisplayEngine::initGlutWindow()
{
    extern bool g_bIgnoreNextResize;
    g_bIgnoreNextResize = true;

    if (m_iWindow == -2)  // was fullscreen
        glutLeaveGameMode();
    else if (m_iWindow >= 0)  // was windowed
    {
        m_pClientParams->winXPos = glutGet(GLUT_WINDOW_X);
        m_pClientParams->winYPos = glutGet(GLUT_WINDOW_Y);
        glutDestroyWindow(m_iWindow);
    }

    extern int g_iOldW;
    extern int g_iOldH;
    g_iOldW = m_pClientParams->screenXSize;
    g_iOldH = m_pClientParams->screenYSize;
    if (m_pClientParams->fullscreen)
    {
        glutGameModeString(m_pClientParams->sGameModeString);
        glutEnterGameMode();
        m_pClientParams->screenXSize = glutGameModeGet(GLUT_GAME_MODE_WIDTH);
        m_pClientParams->screenYSize = glutGameModeGet(GLUT_GAME_MODE_HEIGHT);
        m_iWindow = -2;
    }
    else
    {
        glutInitWindowPosition(m_pClientParams->winXPos, m_pClientParams->winYPos);
        m_pClientParams->screenXSize = m_pClientParams->winWidth;
        m_pClientParams->screenYSize = m_pClientParams->winHeight;
        glutInitWindowSize(m_pClientParams->screenXSize, m_pClientParams->screenYSize);
        m_iWindow = glutCreateWindow("Shahnarman");
    }
    resizeWindow();

    glShadeModel(GL_SMOOTH);
    glDisable(GL_BLEND);
    glAlphaFunc(GL_GREATER, 0.0001f);
    glEnable(GL_ALPHA_TEST);

    glDepthFunc(GL_LEQUAL);
    glEnable(GL_DEPTH_TEST);
    glClearColor(0.1f, 0.05f, 0.1f, 0.0f);
    glClearDepth(1.0f);
    glClearStencil(0);

    GLenum err = glewInit();
    if (err != GLEW_OK)
    {
        char sLog[1024] = "";
        snprintf(sLog, 1024, "Error in glewInit: %s.\n", glewGetErrorString(err));
        m_pDebug->notifyErrorMessage(sLog);
    }
    if (!glewIsSupported("GL_ARB_shading_language_100"))
        m_pDebug->notifyErrorMessage("Warning: extension GL_ARB_shading_language_100 not supported.");
    if (!glewIsSupported("GL_ARB_shader_objects"))
        m_pDebug->notifyErrorMessage("Warning: extension GL_ARB_shader_objects not supported.");
    if (!glewIsSupported("GL_ARB_vertex_shader"))
        m_pDebug->notifyErrorMessage("Warning: extension GL_ARB_vertex_shader not supported.");
    if (!glewIsSupported("GL_ARB_fragment_shader"))
        m_pDebug->notifyErrorMessage("Warning: extension GL_ARB_fragment_shader not supported.");

    Geometry * pGeometry = (Geometry*) m_pRegisteredGeometries->getFirst(0);
    while (pGeometry != NULL)
    {
        pGeometry->reload();
        pGeometry = (Geometry*) m_pRegisteredGeometries->getNext(0);
    }

    if (m_pTexEngine != NULL)
        m_pTexEngine->reloadAllTextures();
}
Ejemplo n.º 22
0
    /**
    * Initializes the window
    */
    void Window::init(){
        // initial opengl code
        glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_ALPHA | GLUT_DEPTH);
        glutInitWindowSize(this->width, this->height);
        glutInitWindowPosition(0, 0);
        this->window = glutCreateWindow(this->title);
        
        // initialize rendering

        glEnable(GL_DEPTH_TEST);
        glClearColor(0.0f, 0.0f, 0.0f, 0.5f);
        glClearDepth(1.0f);
        glDepthFunc(GL_LEQUAL);
        glShadeModel(GL_SMOOTH);
        glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);

        //Setup Lighting
        glEnable(GL_NORMALIZE);

        LightAmbient[0] = 0.1f; LightAmbient[1] = 0.1f; LightAmbient[2] = 0.1f; LightAmbient[3] = 1.0f;
        LightDiffuse[0] = 0.8f; LightDiffuse[1] = 0.8f; LightDiffuse[2] = 0.8f; LightDiffuse[3] = 1.0f;
        LightPosition[0] = 3.0f; LightPosition[1] = 3.0f; LightPosition[2] = 7.0f; LightPosition[3] = 1.0f;

        // Spotlight not visible...? [http://www.vbforums.com/showthread.php?416780-RESOLVED-Problems-with-Specular-light-and-Spotlight-in-OpenGL]?
        //SpotLightPosition[0] = 3.0f; SpotLightPosition[1] = 5.0f; SpotLightPosition[2] = -6.0f; SpotLightPosition[3] = 1.0f;
        //SpotLightDirection[0] = 0.0f; SpotLightDirection[1] = -1.0f; SpotLightDirection[2] = 0.0f;

        glLightfv(GL_LIGHT1, GL_AMBIENT, LightAmbient);         // Setup The Ambient Light
        glLightfv(GL_LIGHT1, GL_DIFFUSE, LightDiffuse);         // Setup The Diffuse Light
        glLightfv(GL_LIGHT1, GL_POSITION,LightPosition);        // Position The Light

        //glLightf (GL_LIGHT2, GL_SPOT_CUTOFF, 15.f);             // Spotlight
        ////glLightfv(GL_LIGHT2, GL_DIFFUSE, LightDiffuse);
        //glLightfv(GL_LIGHT2, GL_POSITION,SpotLightPosition);
        //glLightfv(GL_LIGHT2, GL_SPOT_DIRECTION, SpotLightDirection);

        glEnable(GL_LIGHT1);
        //glEnable(GL_LIGHT2);
        
        lightSwitch = true;
        LODSwitch = false;

        glEnable(GL_COLOR_MATERIAL);      // Enable Color Material
        glColorMaterial(GL_FRONT, GL_DIFFUSE);


        // get window refresh rate and interval
        this->windowRefreshRate = glutGameModeGet(GLUT_GAME_MODE_REFRESH_RATE);
        if(this->windowRefreshRate <= 0){
            this->windowRefreshRate = 60;
        }
        this->windowRefreshInterval = (int) floor(1000.0f/this->windowRefreshRate);
        std::cout << "Rendering with " << this->windowRefreshRate << " hz" << std::endl;
        
        glutDisplayFunc(&display_wrapper);
        glutReshapeFunc(&resize_wrapper);
        glutKeyboardFunc(&keyPressed_wrapper);
		//Arrow-Key functions
		glutSpecialFunc(&keySpecial_wrapper);
        glutTimerFunc(this->windowRefreshInterval, &timer_wrapper, 1);
        
        this->resize(this->width, this->height);
        //glutFullScreen();
        glutMainLoop();
    }
Ejemplo n.º 23
0
int main(int argc, char **argv) {
  bool gameMode = false;
  int startX = 100, startY = 100;
  VECTOR4D Target = { 0.0f, 0.0f, 0.0f, 1.0f };
  VECTOR4D Eye = { 3.0f, 3.0f, 3.0f, 1.0f };
  VECTOR4D Up = { 0.0f, 0.0f, 1.0f, 0.0f };
  VECTOR4D r = { 1, 0, 0, 1 };
  VECTOR4D g = { 0, 1, 0, 1 };
  VECTOR4D b = { 0, 0, 1, 1 };
  VECTOR4D w = { 1, 1, 1, 1 };
  VECTOR4D y = { 1, 1, 0, 1 };

  // Init GLUT and create Window
  glutInit(&argc, argv);
  glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);

  if (argc > 1) {
    if (std::string(argv[1]) == "-game") {
      glutGameModeString("1024x768:32");
      if (glutGameModeGet(GLUT_GAME_MODE_POSSIBLE)) {
        gameMode = true;
        glutEnterGameMode();
      }
    }
    if (std::string(argv[1]) == "-center") {
      startX = glutGet(GLUT_SCREEN_WIDTH) / 2 - WINDOW_WIDTH / 2;
      startY = glutGet(GLUT_SCREEN_HEIGHT) / 2 - WINDOW_HEIGHT / 2;
    }
  }
  if (!gameMode) {
    glutInitWindowPosition(startX, startY);
    glutInitWindowSize(WINDOW_WIDTH, WINDOW_HEIGHT);
    glutCreateWindow("MSC GC 705080 - Demo 4 (Analytic and Parametric Surfaces)");
  }

  // Initialize viewport and rotation matrix
  Vi = View(Eye, Target, Up);
  R = Identity();

  // Create surfaces
  g_EggCarton.BuildAnalyticSurface(30, 30, -1, -1, 2.0f / (30 - 1), 2.0f / (30 - 1), SinCos);
  g_EggCarton.SetColor(r, g, b, w);
  g_Plate.BuildAnalyticSurface(40, 40, -1, -1, 2.0f / (40 - 1), 2.0f / (40 - 1), x2y2);
  g_Plate.SetColor(r, g, b, w);
  g_Sphere.BuildParametricSurface(30, 30, -1, -1, 1.0f / (30 - 1), 1.0f / (30 - 1), Sphere);
  g_Sphere.SetColor(r, b, b, r);
  g_Flower.BuildParametricSurface(100, 30, -1, -1, 1.0f / (10 - 1), 1.0f / (10 - 1), Dini);
  g_Flower.SetColor(b, w, w, b);
  g_Bananas.BuildParametricSurface(30, 30, -1, -1, 1.0f / (30 - 1), 1.0f / (30 - 1), Bananas);
  g_Bananas.SetColor(y, w, w, y);

  // Register callbacks
  glutDisplayFunc(renderScene);
  glutKeyboardFunc(keyHandler);
  glutKeyboardUpFunc(keyUpHandler);
  glutTimerFunc(REFRESH_MILISECS, animateScene, 0);

  // Enter GLUT event processing cycle
  glEnable(GL_DEPTH_TEST);
  glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
  glutMainLoop();

  return 0;
}
Ejemplo n.º 24
0
void specialKeyboard(int key, int x, int y)
{
    float fraction = 0.2f;
    switch(key)
    {
    case GLUT_KEY_DOWN:
        //Code to move DOWN
        x -= lx*fraction;
        z -= lz*fraction;
        break;
    case GLUT_KEY_UP:
        //Code to move UPWN
        x += lx*fraction;
        z += lz*fraction;
        break;
    case GLUT_KEY_LEFT:
        //Code to move LEFT
        angle1 -= 0.1f;
        lx = sin(angle1);
        lz = -cos(angle1);
        break;
    case GLUT_KEY_RIGHT:
        //Code to move RIGHT
        angle1 += 0.1f;
        lx = sin(angle1);
        lz = -cos(angle1);
        break;
    //case GLUT_KEY_F1:
        //Code for opening HELP menu
    //case GLUT_KEY_F2:
        //Code for GAME refresh
    case GLUT_KEY_F1:
			// define resolution, color depth
			glutGameModeString("640x480:32");
			// enter full screen
			if (glutGameModeGet(GLUT_GAME_MODE_POSSIBLE)) {
				glutEnterGameMode();
				sprintf(gameModeString,"640x480:32");
				// register callbacks again
				// and init OpenGL context
				init();
			}
			else
				glutGameModeString(gameModeString);
			break;
		case GLUT_KEY_F2:
			// define resolution, color depth
			glutGameModeString("800x600:32");
			// enter full screen
			if (glutGameModeGet(GLUT_GAME_MODE_POSSIBLE)) {
				glutEnterGameMode();
				sprintf(gameModeString,"800x600:32");
				// register callbacks again
				// and init OpenGL context
				init();
			}
			else
				glutGameModeString(gameModeString);
			break;
		case GLUT_KEY_F3:
			// define resolution, color depth
			glutGameModeString("1024x768:32");
			// enter full screen
			if (glutGameModeGet(GLUT_GAME_MODE_POSSIBLE)) {
				glutEnterGameMode();
				sprintf(gameModeString,"1024x768:32");
				// register callbacks again
				// and init OpenGL context
				init();
			}
			else
				glutGameModeString(gameModeString);
			break;
		case GLUT_KEY_F4:
			// define resolution, color depth
			glutGameModeString("1280x1024:32");
			// enter full screen
			if (glutGameModeGet(GLUT_GAME_MODE_POSSIBLE)) {
				glutEnterGameMode();
				sprintf(gameModeString,"1280x1024:32");
				// register callbacks again
				// and init OpenGL context
				init();
			}
			else
				glutGameModeString(gameModeString);
			break;
		case GLUT_KEY_F5:
			// define resolution, color depth
			glutGameModeString("1920x1200");
			// enter full screen
			if (glutGameModeGet(GLUT_GAME_MODE_POSSIBLE)) {
				glutEnterGameMode();
				sprintf(gameModeString,"1920x1200");
				// register callbacks again
				// and init OpenGL context
				init();
			}
			else
				glutGameModeString(gameModeString);
			break;
		case GLUT_KEY_F6:
			// return to default window
			width = 800;height = 600;
			if (glutGameModeGet(GLUT_GAME_MODE_ACTIVE) != 0) {
				glutLeaveGameMode();
				//init();
			}
			break;
    }
    if (glutGameModeGet(GLUT_GAME_MODE_ACTIVE) == 0)
		sprintf(currentMode,"Current Mode: Window");
	else
		sprintf(currentMode,
			"Current Mode: Game Mode %dx%d at %d hertz, %d bpp",
			glutGameModeGet(GLUT_GAME_MODE_WIDTH),
			glutGameModeGet(GLUT_GAME_MODE_HEIGHT),
			glutGameModeGet(GLUT_GAME_MODE_REFRESH_RATE),
			glutGameModeGet(GLUT_GAME_MODE_PIXEL_DEPTH));

}
Ejemplo n.º 25
0
void keyboardPress(unsigned char pressedKey, int mouseXPosition, int mouseYPosition)
{
	switch(pressedKey)
	{
		case 'w'://VK_UP:
		{
			camera->moveCamera(movementSpeed);
			break;
		}
		case 'W'://VK_UP:
		{
			camera->moveCamera(movementSpeed * acceleration);
			break;
		}
		case 's'://VK_DOWN:
		{
			camera->moveCamera(-movementSpeed);
			break;
		}
		case 'S'://VK_UP:
		{
			camera->moveCamera(-movementSpeed * acceleration);
			break;
		}
		case 'a'://VK_LEFT:
		{
			camera->rotateAroundPoint(camera->m_vView, movementSpeed, 0, 1, 0);
			break;
		}
		case 'A'://VK_LEFT:
		{
			camera->rotateAroundPoint(camera->m_vView, movementSpeed  * acceleration, 0, 1, 0);
			break;
		}
		case 'd'://VK_RIGHT:
		{
			camera->rotateAroundPoint(camera->m_vView, -movementSpeed, 0, 1, 0);
			break;
		}
		case 'D'://VK_RIGHT:
		{
			camera->rotateAroundPoint(camera->m_vView, -movementSpeed * acceleration, 0, 1, 0);
			break;
		}
		case '+':
		{
			solarSystem->setRotationSpeed(solarSystem->getRotationSpeed() * 2.0);
			break;
		}
		case '-':
		{
			solarSystem->setRotationSpeed(solarSystem->getRotationSpeed() * 0.5);
			break;
		}
		case 27:
		{
			if (glutGameModeGet(GLUT_GAME_MODE_ACTIVE) != 0) 
			{
				glutLeaveGameMode();
				exit(0);
			}
			break;
		}
	}
}
Ejemplo n.º 26
0
//fullscreen GameMode creates a new GL context
//currently requires re-registering event callbacks and re-loading texture maps
//------------------------------------------------------------------------------
void npglFullscreen (void* dataRef)
{
	int deltaX = 0, deltaY = 0;
	int result = 0;		//fullscreen window used only if gamemode fails

	pData data = (pData) dataRef;
	pNPgl gl = &data->io.gl;

	if (gl->fullscreen)
	{
		if (glutGameModeGet(GLUT_GAME_MODE_ACTIVE) != 0)		//stereo 3D
		{
			glutLeaveGameMode();
			glutSetWindow (gl->windowID);
            glutShowWindow ();

			//! register keyboard, mouse and display events with GLUT
			npGlutEventFuncs();
			
			npInitGL (data);
		}
	
		//exit fullscreen and restore previous window position
		gl->fullscreen = false;

		glutReshapeWindow (gl->windowSize.x, gl->windowSize.y);
		glutPositionWindow (gl->position.x, gl->position.y);

		//correct for window border offset, glut workaround
		deltaX = gl->position.x - glutGet((GLenum)GLUT_WINDOW_X);
		deltaY = gl->position.y - glutGet((GLenum)GLUT_WINDOW_Y);
		if (deltaX != 0 || deltaY != 0)
			glutPositionWindow (gl->position.x + deltaX,
								gl->position.y + deltaY);
	
		npPostMsg("Exit FullScreen", kNPmsgGL, data);
	}
	else
	{
/*		glutSetWindow (	gl->windowID);
		glutHideWindow ();

		//Game Mode with stereo 3D
		if (gl->stereo3D)
			glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH | GLUT_STEREO); // stereo display mode for glut
		else
			glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);

		//stereo 3D and GameMode
		printf("Attempting Game Mode, please ignore GLUT warnings\n");
		glutGameModeString("1920x1080:32@121");
		if ( glutEnterGameMode() == 0 )
		{
			glutGameModeString("1920x1080:32@120");
			if ( glutEnterGameMode() == 0 )
			{
				glutGameModeString("1920x1080:32@119");
				if ( glutEnterGameMode() == 0 )
				{
					glutGameModeString("1920x1080:32@60"); //does not specify refresh
					result = ( glutEnterGameMode() );
		}}}
*/
		gl->position.x = glutGet((GLenum)GLUT_WINDOW_X);
		gl->position.y = glutGet((GLenum)GLUT_WINDOW_Y);

		gl->windowSize.x = gl->width;
		gl->windowSize.y = gl->height;

		if (result == 0)	//fullscreen window used only if gamemode fails
		{
			printf("FullScreen Window\n");
			glutShowWindow ();
			glutFullScreen ();
		}
		else
		{	//GameMode may be different then what we requested, so get the modes
			glutSetWindowTitle("ANTz - GameMode");

			gl->width = glutGameModeGet( GLUT_GAME_MODE_WIDTH );
			gl->height = glutGameModeGet( GLUT_GAME_MODE_HEIGHT );
			gl->pixelDepth = glutGameModeGet( GLUT_GAME_MODE_PIXEL_DEPTH );
			gl->refreshRate = (float)glutGameModeGet( GLUT_GAME_MODE_REFRESH_RATE );
			printf("FullScreen Game Mode: %dx%d:%d@%d\n", gl->width, gl->height,
							gl->pixelDepth, (int)gl->refreshRate);
		}

		gl->fullscreen = true;
	}
}
Ejemplo n.º 27
0
/*
 * Class:     gruenewa_opengl_GLUT__
 * Method:    glutGameModeGet
 * Signature: (I)I
 */
JNIEXPORT jint JNICALL Java_gruenewa_opengl_GLUT_00024_glutGameModeGet
  (JNIEnv * jenv, jobject jobj, jint arg1) {
  return glutGameModeGet(arg1); 
}
Ejemplo n.º 28
0
int main(int argc, char **argv)
{
    int i;
    if (argc > 1) {		/* make sure at least 2 args, program and file */
      strncpy(filename, argv[argc - 1], sizeof(filename));	/* get the last arg as the file always */
	for (i = 0; i < argc; i++) {	/* check for startup params */
	    if (strstr(argv[i], "-s"))
		stereo = 1;
	}
    }

    else {			/* user only entered program name, help them */

	printf("Usage: %s [-s] <obj filename>\n", argv[0]);
	exit(0);
    }
    glutInit(&argc, argv);
    if (stereo)
	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH |
			    GLUT_STEREO);

    else
	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
    if (game_mode) {
	glutGameModeString("1024x768:32@75");	/*  Select The 640x480 In 16bpp Mode */
	if (glutGameModeGet(GLUT_GAME_MODE_POSSIBLE))
	    glutEnterGameMode();	/*  Enter Full Screen */

	else
	    game_mode = 0;	/*  Cannot Enter Game Mode, Switch To Windowed */
    }
    if (!game_mode) {
	glutInitWindowSize(1024, 768);	/*  Window Size If We Start In Windowed Mode */
	glutCreateWindow("Wavefront Obj File Viewer");
    }
    glutDisplayFunc(Display);
    glutKeyboardFunc(Keyboard);
    getMatrix();
    glClearColor(0.0, 0.0, 0.0, 0.0);
    glClearAccum(0.0, 0.0, 0.0, 0.0);
    glutReshapeFunc(Reshape);
    glutMouseFunc(Mouse);
    glutMotionFunc(Motion);
    glutSpecialFunc(SpecialKeys);	/*  Register Special Keys Handler */
    glutSpecialUpFunc(SpecialKeysUp);	/*  Called When A Special Key Released */
    glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
    glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
    glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
    glLightfv(GL_LIGHT0, GL_POSITION, light_position);
    glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
    glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
    glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
    glMaterialfv(GL_FRONT, GL_SHININESS, high_shininess);
    glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT0);
    glDepthFunc(GL_LESS);
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_NORMALIZE);
    glEnable(GL_TEXTURE_2D);

#ifdef SMOOTH_HINT
    if (smooth_hint) {
	glEnable(GL_LINE_SMOOTH);

	/* glEnable (GL_POLYGON_SMOOTH); */
	glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);

	/* glHint (GL_POLYGON_SMOOTH_HINT, GL_NICEST); */
    }
#endif				/*  */
    if (!pmodel) {		/* load up the model */
	pmodel = glmReadOBJ(filename);
	if (!pmodel) {
	    printf("\nUsage: objviewV2 <-s> <obj filename>\n");
	    exit(0);
	}
	glmUnitize(pmodel);
	glmVertexNormals(pmodel, 90.0, GL_TRUE);
    }
    glutMainLoop();
    exit(0);
}
Ejemplo n.º 29
0
int main(int argc, char** argv)
{
	char    glutGamemode[32] = "";
    char   *vconf = NULL;
    char    cparaDefault[] = "../share/artoolkit-examples/Data/camera_para.dat";
    char   *cpara = NULL;
    int     i;
    int     gotTwoPartOption;
    const char markerConfigDataFilename[] = "../share/artoolkit-examples/Data/markers.dat";
	const char objectDataFilename[] = "../share/artoolkit-examples/Data/objects.dat";
    //
	// Process command-line options.
	//
    
	glutInit(&argc, argv);
    
    i = 1; // argv[0] is name of app, so start at 1.
    while (i < argc) {
        gotTwoPartOption = FALSE;
        // Look for two-part options first.
        if ((i + 1) < argc) {
            if (strcmp(argv[i], "--vconf") == 0) {
                i++;
                vconf = argv[i];
                gotTwoPartOption = TRUE;
            } else if (strcmp(argv[i], "--cpara") == 0) {
                i++;
                cpara = argv[i];
                gotTwoPartOption = TRUE;
            } else if (strcmp(argv[i],"--width") == 0) {
                i++;
                // Get width from second field.
                if (sscanf(argv[i], "%d", &prefWidth) != 1) {
                    ARLOGe("Error: --width option must be followed by desired width.\n");
                }
                gotTwoPartOption = TRUE;
            } else if (strcmp(argv[i],"--height") == 0) {
                i++;
                // Get height from second field.
                if (sscanf(argv[i], "%d", &prefHeight) != 1) {
                    ARLOGe("Error: --height option must be followed by desired height.\n");
                }
                gotTwoPartOption = TRUE;
            } else if (strcmp(argv[i],"--refresh") == 0) {
                i++;
                // Get refresh rate from second field.
                if (sscanf(argv[i], "%d", &prefRefresh) != 1) {
                    ARLOGe("Error: --refresh option must be followed by desired refresh rate.\n");
                }
                gotTwoPartOption = TRUE;
            }
        }
        if (!gotTwoPartOption) {
            // Look for single-part options.
            if (strcmp(argv[i], "--help") == 0 || strcmp(argv[i], "-help") == 0 || strcmp(argv[i], "-h") == 0) {
                usage(argv[0]);
            } else if (strncmp(argv[i], "-cpara=", 7) == 0) {
                cpara = &(argv[i][7]);
            } else if (strcmp(argv[i], "--version") == 0 || strcmp(argv[i], "-version") == 0 || strcmp(argv[i], "-v") == 0) {
                ARLOG("%s version %s\n", argv[0], AR_HEADER_VERSION_STRING);
                exit(0);
            } else if (strcmp(argv[i],"--windowed") == 0) {
                prefWindowed = TRUE;
            } else if (strcmp(argv[i],"--fullscreen") == 0) {
                prefWindowed = FALSE;
            } else {
                ARLOGe("Error: invalid command line argument '%s'.\n", argv[i]);
                usage(argv[0]);
            }
        }
        i++;
    }
    

	//
	// Video setup.
	//
    
	if (!setupCamera((cpara ? cpara : cparaDefault), vconf, &gCparamLT)) {
		ARLOGe("main(): Unable to set up AR camera.\n");
		exit(-1);
	}

    //
    // AR init.
    //
    
    // Init AR.
    gARPattHandle = arPattCreateHandle();
	if (!gARPattHandle) {
		ARLOGe("Error creating pattern handle.\n");
		exit(-1);
	}
    
    gARHandle = arCreateHandle(gCparamLT);
    if (!gARHandle) {
        ARLOGe("Error creating AR handle.\n");
		exit(-1);
    }
    arPattAttach(gARHandle, gARPattHandle);
    
    if (arSetPixelFormat(gARHandle, arVideoGetPixelFormat()) < 0) {
        ARLOGe("Error setting pixel format.\n");
		exit(-1);
    }
    
    gAR3DHandle = ar3DCreateHandle(&gCparamLT->param);
    if (!gAR3DHandle) {
        ARLOGe("Error creating 3D handle.\n");
		exit(-1);
    }
            
    //
    // Markers setup.
    //
    
    // Load marker(s).
    newMarkers(markerConfigDataFilename, gARPattHandle, &markersSquare, &markersSquareCount, &gARPattDetectionMode);
    ARLOGi("Marker count = %d\n", markersSquareCount);
    
    //
    // Other ARToolKit setup.
    //
    
    arSetMarkerExtractionMode(gARHandle, AR_USE_TRACKING_HISTORY_V2);
    //arSetMarkerExtractionMode(gARHandle, AR_NOUSE_TRACKING_HISTORY);
    //arSetLabelingThreshMode(gARHandle, AR_LABELING_THRESH_MODE_MANUAL); // Uncomment to force manual thresholding.
    
    // Set the pattern detection mode (template (pictorial) vs. matrix (barcode) based on
    // the marker types as defined in the marker config. file.
    arSetPatternDetectionMode(gARHandle, gARPattDetectionMode); // Default = AR_TEMPLATE_MATCHING_COLOR
    
    // Other application-wide marker options. Once set, these apply to all markers in use in the application.
    // If you are using standard ARToolKit picture (template) markers, leave commented to use the defaults.
    // If you are usign a different marker design (see http://www.artoolworks.com/support/app/marker.php )
    // then uncomment and edit as instructed by the marker design application.
    //arSetLabelingMode(gARHandle, AR_LABELING_BLACK_REGION); // Default = AR_LABELING_BLACK_REGION
    //arSetBorderSize(gARHandle, 0.25f); // Default = 0.25f
    //arSetMatrixCodeType(gARHandle, AR_MATRIX_CODE_3x3); // Default = AR_MATRIX_CODE_3x3
    
	//
	// Graphics setup.
	//

	// Set up GL context(s) for OpenGL to draw into.
	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
    if (prefWindowed) {
        if (prefWidth > 0 && prefHeight > 0) glutInitWindowSize(prefWidth, prefHeight);
        else glutInitWindowSize(gCparamLT->param.xsize, gCparamLT->param.ysize);
        glutCreateWindow(argv[0]);
    } else {
        if (glutGameModeGet(GLUT_GAME_MODE_POSSIBLE)) {
            if (prefWidth && prefHeight) {
                if (prefDepth) {
                    if (prefRefresh) snprintf(glutGamemode, sizeof(glutGamemode), "%ix%i:%i@%i", prefWidth, prefHeight, prefDepth, prefRefresh);
                    else snprintf(glutGamemode, sizeof(glutGamemode), "%ix%i:%i", prefWidth, prefHeight, prefDepth);
                } else {
                    if (prefRefresh) snprintf(glutGamemode, sizeof(glutGamemode), "%ix%i@%i", prefWidth, prefHeight, prefRefresh);
                    else snprintf(glutGamemode, sizeof(glutGamemode), "%ix%i", prefWidth, prefHeight);
                }
            } else {
                prefWidth = glutGameModeGet(GLUT_GAME_MODE_WIDTH);
                prefHeight = glutGameModeGet(GLUT_GAME_MODE_HEIGHT);
                snprintf(glutGamemode, sizeof(glutGamemode), "%ix%i", prefWidth, prefHeight);
            }
            glutGameModeString(glutGamemode);
            glutEnterGameMode();
        } else {
            if (prefWidth > 0 && prefHeight > 0) glutInitWindowSize(prefWidth, prefHeight);
            glutCreateWindow(argv[0]);
            glutFullScreen();
        }
    }
    
    // Create the OpenGL projection from the calibrated camera parameters.
    arglCameraFrustumRH(&(gCparamLT->param), VIEW_DISTANCE_MIN, VIEW_DISTANCE_MAX, cameraLens);
    cameraPoseValid = FALSE;
    
	// Setup ARgsub_lite library for current OpenGL context.
	if ((gArglSettings = arglSetupForCurrentContext(&(gCparamLT->param), arVideoGetPixelFormat())) == NULL) {
		ARLOGe("main(): arglSetupForCurrentContext() returned error.\n");
		cleanup();
		exit(-1);
	}
    arglSetupDebugMode(gArglSettings, gARHandle);
    
    // Load objects (i.e. OSG models).
    VirtualEnvironmentInit(objectDataFilename);
    VirtualEnvironmentHandleARViewUpdatedCameraLens(cameraLens);
    
    //
    // Setup complete. Start tracking.
    //
    
    // Start the video.
    if (arVideoCapStart() != 0) {
    	ARLOGe("setupCamera(): Unable to begin camera data capture.\n");
		return (FALSE);
	}
	arUtilTimerReset();
	
	// Register GLUT event-handling callbacks.
	// NB: mainLoop() is registered by Visibility.
	glutDisplayFunc(Display);
	glutReshapeFunc(Reshape);
	glutVisibilityFunc(Visibility);
	glutKeyboardFunc(Keyboard);
	
	glutMainLoop();

	return (0);
}
Ejemplo n.º 30
0
/*
 * The sample's entry point
 */
int main( int argc, char** argv )
{
    int menuID, subMenuA, subMenuB;

    glutInitDisplayString( "stencil~2 rgb double depth>=16 samples" );
    glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH );
    glutInitWindowPosition( 100, 100 );

    glutInit( &argc, argv );

    glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE,GLUT_ACTION_GLUTMAINLOOP_RETURNS);
    glutMenuStatusFunc( SampleMenuStatus );
    glutIdleFunc( SampleIdle );

    subMenuA = glutCreateMenu( SampleMenu );
    glutAddMenuEntry( "Sub menu A1 (01)", 1 );
    glutAddMenuEntry( "Sub menu A2 (02)", 2 );
    glutAddMenuEntry( "Sub menu A3 (03)", 3 );

    subMenuB = glutCreateMenu( SampleMenu );
    glutAddMenuEntry( "Sub menu B1 (04)", 4 );
    glutAddMenuEntry( "Sub menu B2 (05)", 5 );
    glutAddMenuEntry( "Sub menu B3 (06)", 6 );
    glutAddSubMenu( "Going to sub menu A", subMenuA );

    menuID = glutCreateMenu( SampleMenu );
    glutAddMenuEntry( "Entry one",   1 );
    glutAddMenuEntry( "Entry two",   2 );
    glutAddMenuEntry( "Entry three", 3 );
    glutAddMenuEntry( "Entry four",  4 );
    glutAddMenuEntry( "Entry five",  5 );
    glutAddSubMenu( "Enter sub menu A", subMenuA );
    glutAddSubMenu( "Enter sub menu B", subMenuB );

    g_mainwin1 = glutCreateWindow( "Hello world!" );
    glutDisplayFunc( SampleDisplay );
    glutReshapeFunc( SampleReshape );
    glutKeyboardFunc( SampleKeyboard );
    glutSpecialFunc( SampleSpecial );
    glutEntryFunc( SampleEntry );
    glutAttachMenu( GLUT_LEFT_BUTTON );

    glutInitWindowPosition( 200, 200 );
    g_mainwin2 = glutCreateWindow( "I am not Jan B." );
    glutDisplayFunc( SampleDisplay );
    glutReshapeFunc( SampleReshape );
    glutKeyboardFunc( SampleKeyboard );
    glutSpecialFunc( SampleSpecial );
    glutEntryFunc( SampleEntry );
    glutAttachMenu( GLUT_LEFT_BUTTON );
    glutSetMenu(subMenuA);
    glutAttachMenu( GLUT_RIGHT_BUTTON );

    g_sw1=glutCreateSubWindow(g_mainwin2,200,0,100,100);
    glutDisplayFunc( SampleDisplay );
    glutSetMenu(subMenuB);
    glutAttachMenu( GLUT_LEFT_BUTTON );

    g_sw2=glutCreateSubWindow(g_sw1,50,0,50,50);
    glutDisplayFunc( SampleDisplay );
    glutSetMenu(menuID);
    glutAttachMenu( GLUT_RIGHT_BUTTON );

    printf( "Testing game mode string parsing, don't panic!\n" );
    glutGameModeString( "320x240:32@100" );
    glutGameModeString( "640x480:16@72" );
    glutGameModeString( "1024x768" );
    glutGameModeString( ":32@120" );
    glutGameModeString( "Toudi glupcze, Danwin bedzie moj!" );

    glutGameModeString( "640x480:37@300" );    /* this one should fail */
    glutEnterGameMode();

    glutGameModeString( "800x600" );    /* this one is likely to succeed */
    g_gamemodewin = glutEnterGameMode();

    if (glutGameModeGet(GLUT_GAME_MODE_ACTIVE))
        g_InGameMode = 1;
    glutDisplayFunc( SampleDisplay );
    glutReshapeFunc( SampleReshape );
    glutKeyboardFunc( SampleGameModeKeyboard );
    glutEntryFunc( SampleEntry );
    glutSetMenu(menuID);
    glutAttachMenu( GLUT_LEFT_BUTTON );

    printf( "current window is %ix%i at (%i,%i)\n",
            glutGet( GLUT_WINDOW_WIDTH ), glutGet( GLUT_WINDOW_HEIGHT ),
            glutGet( GLUT_WINDOW_X ), glutGet( GLUT_WINDOW_Y )
          );

    /*
     * Describe pixel format
     */
    printf("The current window has %i red bits, %i green bits, %i blue bits and %i alpha bits for a total buffer size of %i bits\n",glutGet(GLUT_WINDOW_RED_SIZE),glutGet(GLUT_WINDOW_GREEN_SIZE),glutGet(GLUT_WINDOW_BLUE_SIZE),glutGet(GLUT_WINDOW_ALPHA_SIZE),glutGet(GLUT_WINDOW_BUFFER_SIZE));
    printf("It furthermore has %i depth bits and %i stencil bits\n",glutGet(GLUT_WINDOW_DEPTH_SIZE),glutGet(GLUT_WINDOW_STENCIL_SIZE));

    /*
     * Enter the main FreeGLUT processing loop
     */
    glutMainLoop();

    /*
     * returned from mainloop after window closed
     * see glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE,GLUT_ACTION_GLUTMAINLOOP_RETURNS); above
     */
    printf( "glutMainLoop() termination works fine!\n" );

    return EXIT_SUCCESS;
}