Exemplo n.º 1
0
Arquivo: app.c Projeto: dscape/isdgl
int main(
	int argc,
	char **argv
)
{
	int f=1;

	if(argc != 2) {
		printf(MSG_USAGE);
		f=0;
	} else if(f && readLorenzDataFile(argv[1],&lorenzData) == ERRORISDGL) {
		if(DEBUG)
			printf(MSG_ERROR_IO);
		showErrorGL(MSG_ERROR_IO);
		f=0;
	}

	if(!f)
		defaultLorenzValues(&lorenzData);

	maxiters = lorenzData.maxiters;
	scheme   = lorenzData.scheme;
	style    = lorenzData.style;
	points = malloc(sizeof(Point)*maxiters);

	glutInit(&argc,argv);
	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
	glutInitWindowSize(width,height);
	glutInitWindowPosition(POSITION_X,POSITION_Y);
	windowID = glutCreateWindow(WINDOW_TITLE);
	glutGameModeString("1280x800:32@60");
	glutEnterGameMode();
	initializeGL();

	glutIgnoreKeyRepeat(1);
	glutKeyboardFunc(&keyPressedGL);
	glutSpecialFunc(&specialKeyPressedGL);
	glutSpecialUpFunc(releaseKeyGL);

	glutDisplayFunc(drawGL);
	glutReshapeFunc(reshapeGL);
	glutTimerFunc(20, timerGL, 1);
	glutMainLoop();
	return EXIT_SUCCESS;
}
Exemplo n.º 2
0
//------------------------------------------------------------
void ofAppGlutWindow::setupOpenGL(int w, int h, int screenMode){

	int argc = 1;
	char *argv = "openframeworks";
	char **vptr = &argv;
	glutInit(&argc, vptr);
	glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH | GLUT_ALPHA );

	windowMode = screenMode;
	bNewScreenMode = true;

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

		//Default colors etc are now in ofGraphics - ofSetupGraphicDefaults
		ofSetupGraphicDefaults();

		/*
		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 {
		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();
	}
}
Exemplo n.º 3
0
CGLApplication::CGLApplication(
	const char * title,
	int width,
	int height,
	bool needDepth,
	bool needStencil
	)
{
	// Только один экземпляр приложения разрешено создать
	if (m_pApplication)
	{
		assert(!"Only one instance of the application is permitted");
		return;
	}
	m_pApplication = this;

	// Инициализируем библиотеку GLUT, подсовывая ей
	// фиктивные параметры командой строки
	int argc = 1;
	char *argv[] = { "", };
	glutInit(&argc, argv);

	// Задаем режим буфера кадра, запрошенный пользователем
	glutInitDisplayMode(
		GLUT_RGBA |
		GLUT_DOUBLE |
		(needDepth ? GLUT_DEPTH : 0) |
		(needStencil ? GLUT_STENCIL : 0)
		);

	// Если пользователь указал размеры окна, сообщаем о них GLUT
	if (width > 0 && height > 0)
	{
		glutInitWindowSize(width, height);
	}

	glutGameModeString("1366:768:32"); // For full screen game mode
	glutEnterGameMode();

	// Создаем окно приложения
	//glutCreateWindow(title);

	// Задаем обработчики событий
	InitEventHandlers();
}
Exemplo n.º 4
0
bool WindowGlut::init(Outverbose& o, WindowInfo w)
{
  initShared(o, w);

  int argc = 0;
  char **argv = 0;
  glutInit(&argc, argv);

  // make window
  int mode = GLUT_RGB;
  if (w.doubleBuffer) mode |= GLUT_DOUBLE;
  if (w.depthBuffer) mode |= GLUT_DEPTH;
  glutInitDisplayMode(mode);

  if (!w.fullscreen) {
    glutInitWindowPosition(w.x, w.y);
    glutInitWindowSize(w.width, w.height);
    wid = glutCreateWindow(w.title.c_str());
    *out << VERBOSE_LOUD << "x,y: " << w.x << "," << w.y << ". width,height: " << w.width << "," << w.height;
    *out << " title: " << w.title << " wid: " << wid << '\n';
  }else{
    char str[20];
    // TODO make fullcreen using glutGet(GL_SCREEN_WIDTH)... etc.
#ifdef _MSC_VER
	int size = sprintf(str, "%ix%i:%i@%i", w.width, w.height, w.colorDepth, w.refreshRate);
#else
    int size = std::snprintf(str, 20, "%ix%i:%i@%i", w.width, w.height, w.colorDepth, w.refreshRate);
#endif
    if (size >= 20) {
      *out << VERBOSE_LOUD << "Error: window string too long.\n";
      return false;
    }else{
      glutGameModeString(str);
      wid = glutEnterGameMode();
    }
  }

  glutReshapeFunc(reshape);

  glutMainLoop(); // TODO - this is where we go wrong with glut...
  *out << VERBOSE_LOUD << "initialising window\n";
  return true;
}
Exemplo n.º 5
0
int main (int argc, char **argv) 
{
		unsigned int iseed = (unsigned int) time(NULL);

		srand (iseed);
	
		glutInit (&argc, argv);
		glutInitDisplayMode (GLUT_DOUBLE | GLUT_DEPTH); //set the display to Double buffer, with depth
		glutGameModeString( "1920x1080:32@60" ); //the settings	 for fullscreen mode
		glutEnterGameMode(); //set glut to fullscreen using the settings in the line above
		init (); 
		glutDisplayFunc (display); //use the display function to draw everything
		glutIdleFunc (display); //update any variables in display,display can be changed to anyhing, as long as you move the variables to be updated, in this case, angle++;
		glutReshapeFunc (reshape); //reshape the window accordingly
		glutMouseFunc(mouse);
		glutKeyboardFunc (keyboard); //check the keyboard
		glutMainLoop (); //call the main loop
		return 0;
}
Exemplo n.º 6
0
bool GLUTBackendCreateWindow(unsigned int Width, unsigned int Height, unsigned int bpp, bool isFullScreen, const char* pTitle){
	if (isFullScreen){
		char ModeString[64] = {0};
		glutGameModeString(ModeString);
		glutEnterGameMode();
	}
	else {
		glutInitWindowSize(Width, Height);
		glutCreateWindow(pTitle);
	}

	GLenum res = glewInit();
	if (res != GLEW_OK){
		fprintf(stderr, "Error: '%s'\n", glewGetErrorString(res));
		return false;
	}

	return true;
}
Exemplo n.º 7
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();

}
Exemplo n.º 8
0
int main(int argc, char** argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGBA);
    glutInitWindowSize(WINDOW_WIDTH, WINDOW_HEIGHT);
    glutInitWindowPosition(100, 100);
    glutCreateWindow("Tutorial 16");
    glutGameModeString("1280x1024@32");
    glutEnterGameMode();

    InitializeGlutCallbacks();

    pGameCamera = new Camera(WINDOW_WIDTH, WINDOW_HEIGHT);

    // Must be done after glut is initialized!
    GLenum res = glewInit();
    if (res != GLEW_OK) {
      fprintf(stderr, "Error: '%s'\n", glewGetErrorString(res));
      return 1;
    }

    glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
    glFrontFace(GL_CW);
    glCullFace(GL_BACK);
    glEnable(GL_CULL_FACE);

    CreateVertexBuffer();
    CreateIndexBuffer();

    CompileShaders();

    glUniform1i(gSampler, 0);

    pTexture = new Texture(GL_TEXTURE_2D, "test.png");

    if (!pTexture->Load()) {
        return 1;
    }

    glutMainLoop();

    return 0;
}
int main(int argc, char *argv[]) {

    // Initialise OpenGL
    glutInit(&argc, argv);



    // Set window position, size & create window
    glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);


    if (fullscreen) {
        glutGameModeString("1900x1080:24");
        glutEnterGameMode();
    } else {
        glutInitWindowPosition(50,50);
        glutInitWindowSize(1600,1200);
        windowId = glutCreateWindow("Lab 4: Loading a textured model");
    }


    // Set GLUT callback functions
    glutReshapeFunc(setViewport);
    glutDisplayFunc(renderScene);
    glutIdleFunc(updateScene);
    glutKeyboardFunc(keypress);
    glutKeyboardUpFunc(keyup);
    glutPassiveMotionFunc(mouseMove);
    glutMouseFunc(mouseClick);


    // Setup OpenGL state & scene resources (models, textures etc)
    setupScene();
    importSkybox();

    // Show window & start update loop
    glutMainLoop();

    return 0;

}
Exemplo n.º 10
0
int __main(int* argcp, char** argv)
{
	glutInit(argcp, argv);

	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH | GLUT_STENCIL);

#if (FULL_SCREEN)
	glutGameModeString("640x480:32@60");
	glutEnterGameMode();
#else
	glutInitWindowSize(960, 720);
	glutInitWindowPosition(0, 0);
	glutCreateWindow("Game");
#endif

	glewInit();

	SetCurrentDirectory(L"data");

	glClearColor(1.0, 1.0, 1.0, 1.0);

	glEnable(GL_DEPTH_TEST);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	glEnable(GL_BLEND);//ブレンドの有効化
	//glEnable(GL_CULL_FACE);

	//固定シェーダー用
	glEnable(GL_LIGHTING);
	glEnable(GL_LIGHT0);

	Init();

	glutDisplayFunc(Display);
	glutKeyboardFunc(Keyboard);
	glutIdleFunc(Idle);
	glutReshapeFunc(Resize);
	glutMouseWheelFunc(wheel);
	glutMainLoop();

	return 0;
}
Exemplo n.º 11
0
int main(int argc,char **argv) {
	glutInit(&argc,argv);
	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH | GLUT_STENCIL);

#if defined(DEMO_FULLSCREEN)
    glutGameModeString("800x600");
    glutEnterGameMode();
    glutSetCursor(GLUT_CURSOR_NONE);
#else
	glutInitWindowSize(800, 600);
	glutInitWindowPosition(100, 100);
	glutCreateWindow("02 - Object Line");
#endif

	init();
	glutDisplayFunc(display);
	glutIdleFunc(idle);
	glutKeyboardFunc(keyboard);
	glutMainLoop();
	return 0;
}
Exemplo n.º 12
0
bool GLUTBackendCreateWindow(unsigned int Width, unsigned int Height, unsigned int bpp, bool isFullScreen, const char* pTitle)
{
    if (isFullScreen) {
        char ModeString[64] = { 0 };
        SNPRINTF(ModeString, sizeof(ModeString), "%dx%d@%d", Width, Height, bpp);
        glutGameModeString(ModeString);
        glutEnterGameMode();
    }
    else {
        glutInitWindowSize(Width, Height);
        glutCreateWindow(pTitle);
    }

    // Must be done after glut is initialized!
    GLenum res = glewInit();
    if (res != GLEW_OK) {
        fprintf(stderr, "Error: '%s'\n", glewGetErrorString(res));
        return false;
    }

    return true;
}
Exemplo n.º 13
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;
}
Exemplo n.º 14
0
int main(int argc, char** argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGBA);
    glutInitWindowSize(WINDOW_WIDTH, WINDOW_HEIGHT);
    glutInitWindowPosition(100, 100);
    glutCreateWindow("Tutorial 15");
    glutGameModeString("1920x1200@32");
    glutEnterGameMode();

    InitializeGlutCallbacks();

    pGameCamera = new Camera(WINDOW_WIDTH, WINDOW_HEIGHT);

    // Must be done after glut is initialized!
    GLenum res = glewInit();
    if (res != GLEW_OK) {
      fprintf(stderr, "Error: '%s'\n", glewGetErrorString(res));
      return 1;
    }
    
    glClearColor(0.0f, 0.0f, 0.0f, 0.0f);

    CreateVertexBuffer();
    CreateIndexBuffer();

    CompileShaders();

    gPersProjInfo.FOV = 60.0f;
    gPersProjInfo.Height = WINDOW_HEIGHT;
    gPersProjInfo.Width = WINDOW_WIDTH;
    gPersProjInfo.zNear = 1.0f;
    gPersProjInfo.zFar = 100.0f;
	                
    glutMainLoop();

    return 0;
}
Exemplo n.º 15
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;
}
Exemplo n.º 16
0
bool GLUTEngine::CreateWindow( unsigned int Width, unsigned int Height,
							  unsigned int bit_depth, bool isFullScreen, const char* Title )
{
	if( !init )
		return FAIL;

	if( isFullScreen ) // full-screen 'high-performance' mode
	{
		// write at most 64 bytes
		char GameMode[64] = { 0 };
		snprintf( GameMode, sizeof(GameMode), "%dx%d@%d", Width, Height, bit_depth );

		glutGameModeString( GameMode );
		glutEnterGameMode();
	}
	else			   // render a normal window
	{
		glutInitWindowSize( Width,Height );
		glutCreateWindow(Title);
	}

	return glew_assert();
}
Exemplo n.º 17
0
Window::Window(uword width, uword height, const char *title,bool fullscreen,
               word xpos, word ypos) : resized(true)
{
	data = (void *) new WindowData;

	PRIV(WindowData, wd);
	wd->width = width;
	wd->height = height;
	wd->aspect = (double) width / (double) height;
    wd->fullscreen = fullscreen; 
    glutInitWindowPosition(xpos, ypos);
    glutInitWindowSize(width, height);
    glutCreateWindow(title);
    if(fullscreen){
        glutHideWindow();
        glutDestroyWindow(glutGetWindow());
        char gameModeString [50];
        sprintf (gameModeString, "%dx%d",width,height);
        glutGameModeString(gameModeString);
        glutSetWindow(glutEnterGameMode());
    }
	wd->wid = glutGetWindow();

	glClearColor(0, 0, 0, 0);
	glEnable(GL_DEPTH_TEST);
	glEnable(GL_CULL_FACE);
	glShadeModel(GL_SMOOTH);

	glEnable(GL_LIGHTING);

	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    //Clearing screen to get a black screen while loading..
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
    glutSwapBuffers();
	windows.insert(this);
}
Exemplo n.º 18
0
int main(int argc, char **argv) {
  bool fullscreen = false;

  glutInit(&argc, argv);
  glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
  glutInitWindowSize(screen_x, screen_y);
  glutInitWindowPosition(50, 50);
  if (fullscreen) {
    glutGameModeString("800x600:32");
    glutEnterGameMode();
  } else {
    glutCreateWindow("Fractal");
  }
  glutDisplayFunc(display);
  glutKeyboardFunc(keyboard);
  glutReshapeFunc(reshape);
  glutMouseFunc(mouse);
  glColor3d(0, 0, 0);  // Foreground color.
  glClearColor(1, 1, 1, 0);  // Background color.
  InitializeMyStuff();
  glutMainLoop();

  return 0;
}
Exemplo n.º 19
0
// Make a window for doing OpenGL
void makeWindow(int argc, char** argv) {
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
	glutInitContextVersion(4, 2);
	#ifdef DEBUG
		glutInitContextFlags(GLUT_CORE_PROFILE | GLUT_DEBUG);
	#else
		glutInitContextFlags(GLUT_COMPATIBILITY_PROFILE);
	#endif

	// Open window / full screen
	#ifdef FULLSCREEN
		char modeString[255] = "";
		sprintf(modeString, "%dx%d:24", WINDOW_WIDTH, WINDOW_HEIGHT);
		glutGameModeString(modeString);
		glutEnterGameMode();
	#else
		glutInitWindowSize(WINDOW_WIDTH, WINDOW_HEIGHT);
		glutCreateWindow(WINDOW_TITLE);
	#endif

	// Use GLEW, and make sure it imports EVERYTHING
	glewExperimental = GL_TRUE;
	glewInit();

	#ifdef DEBUG
		registerGlDebugLogger(GL_DEBUG_SEVERITY_MEDIUM);
	#endif

	// Set up OpenGL features
	glEnable(GL_DEPTH_TEST);
	glClearDepth(1.0f);
	glDepthFunc(GL_LEQUAL);
	glEnable(GL_CULL_FACE);
	glCullFace(GL_BACK);
}
Exemplo n.º 20
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);
}
Exemplo n.º 21
0
int main(int argc, char** argv)
{
	char glutGamemode[32];
	char cparam_name[] = "Data/camera_para.dat";
	char vconf[] = "";
	char patt_name[]  = "Data/patt.hiro";
    
    char movieFileName[] = "Data/sample.mov";
    char *movieURI;
	
    //
	// Library inits.
	//

	glutInit(&argc, argv);

	//
	// Video setup.
	//

	if (!setupCamera(cparam_name, vconf, &gCparamLT, &gARHandle, &gAR3DHandle)) {
		ARLOGe("main(): Unable to set up AR camera.\n");
		exit(-1);
	}

	//
	// Graphics setup.
	//

	// Set up GL context(s) for OpenGL to draw into.
	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
	if (!windowed) {
		if (windowRefresh) sprintf(glutGamemode, "%ix%i:%i@%i", windowWidth, windowHeight, windowDepth, windowRefresh);
		else sprintf(glutGamemode, "%ix%i:%i", windowWidth, windowHeight, windowDepth);
		glutGameModeString(glutGamemode);
		glutEnterGameMode();
	} else {
		glutInitWindowSize(windowWidth, windowHeight);
		glutCreateWindow(argv[0]);
	}

	// 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);
	arUtilTimerReset();
		
	// Load marker(s).
	if (!setupMarker(patt_name, &gPatt_id, gARHandle, &gARPattHandle)) {
		ARLOGe("main(): Unable to set up AR marker.\n");
		cleanup();
		exit(-1);
	}
	
    //
    // Movie loading.
    //

    // In this example, we load a movie via a file URI, but other URIs allowed
    // by the QuickTime module would also be fine.

    // Movie relative path is in "movieFileName". Get a file:// URI for it.
    movieURI = arUtilGetFileURI(movieFileName);
    if (!movieURI) {
        ARLOGe("Error: Unable to construct URI for movie file '%s'.\n", movieFileName);
		cleanup();
		exit(-1);
    }
    
    // Now open the movie.
    if (!setupMovie(movieURI)) {
        ARLOGe("Error: Unable to open movie at URI '%s'.\n", movieURI);
        free(movieURI);
		cleanup();
		exit(-1);
    }
    
    free(movieURI); // We're finished with movieURI, so free it.

	// Register GLUT event-handling callbacks.
	// NB: mainLoop() is registered by Visibility.
	glutDisplayFunc(Display);
	glutReshapeFunc(Reshape);
	glutVisibilityFunc(Visibility);
	glutKeyboardFunc(Keyboard);
	
	glutMainLoop();

	return (0);
}
Exemplo n.º 22
0
int main(int argc, char** argv)
{
	int i;
	char glutGamemode[32];
	const char *cparam_name = 
		"Data/camera_para.dat";
#ifdef _WIN32
	char			*vconf = "Data\\WDM_camera_flipV.xml";
#else
	char			*vconf = "";
#endif
	char objectDataFilename[] = "Data/object_data_vrml";
	
	// ----------------------------------------------------------------------------
	// Library inits.
	//

	glutInit(&argc, argv);

	// ----------------------------------------------------------------------------
	// Hardware setup.
	//

	if (!setupCamera(cparam_name, vconf, &gARTCparam)) {
		fprintf(stderr, "main(): Unable to set up AR camera.\n");
		exit(-1);
	}
	
#ifdef _WIN32
	CoInitialize(NULL);
#endif

	// ----------------------------------------------------------------------------
	// Library setup.
	//

	// Set up GL context(s) for OpenGL to draw into.
	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
	if (!prefWindowed) {
		if (prefRefresh) sprintf(glutGamemode, "%ix%i:%i@%i", prefWidth, prefHeight, prefDepth, prefRefresh);
		else sprintf(glutGamemode, "%ix%i:%i", prefWidth, prefHeight, prefDepth);
		glutGameModeString(glutGamemode);
		glutEnterGameMode();
	} else {
		glutInitWindowSize(gARTCparam.xsize, gARTCparam.ysize);
		glutCreateWindow(argv[0]);
	}

	// Setup argl library for current context.
	if ((gArglSettings = arglSetupForCurrentContext()) == NULL) {
		fprintf(stderr, "main(): arglSetupForCurrentContext() returned error.\n");
		exit(-1);
	}
	debugReportMode();
	arUtilTimerReset();

	if (!setupMarkersObjects(objectDataFilename)) {
		fprintf(stderr, "main(): Unable to set up AR objects and markers.\n");
		Quit();
	}
	
	// Test render all the VRML objects.
    fprintf(stdout, "Pre-rendering the VRML objects...");
	fflush(stdout);
    glEnable(GL_TEXTURE_2D);
    for (i = 0; i < gObjectDataCount; i++) {
		arVrmlDraw(gObjectData[i].vrml_id);
    }
    glDisable(GL_TEXTURE_2D);
	fprintf(stdout, " done\n");
	
	// Register GLUT event-handling callbacks.
	// NB: Idle() is registered by Visibility.
	glutDisplayFunc(Display);
	glutReshapeFunc(Reshape);
	glutVisibilityFunc(Visibility);
	glutKeyboardFunc(Keyboard);
	
	glutMainLoop();

	return (0);
}
Exemplo n.º 23
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);
}
Exemplo n.º 24
0
int main(int argc, char** argv)
{
    char glutGamemode[32];
    char *cparam_name = "Data/camera_para.dat";
    char *vconf = "";
    char *patt_name  = "Data/patt.hiro";

    // ----------------------------------------------------------------------------
    // Library inits.
    //

    glutInit(&argc, argv);

    // ----------------------------------------------------------------------------
    // Hardware setup.
    //

    if (!setupCamera(cparam_name, vconf, &gARTCparam)) {
        fprintf(stderr, "main(): Unable to set up AR camera.\n");
        exit(-1);
    }

    // ----------------------------------------------------------------------------
    // Library setup.
    //

    // Set up GL context(s) for OpenGL to draw into.
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
    if (!prefWindowed) {
        if (prefRefresh) sprintf(glutGamemode, "%ix%i:%i@%i", prefWidth, prefHeight, prefDepth, prefRefresh);
        else sprintf(glutGamemode, "%ix%i:%i", prefWidth, prefHeight, prefDepth);
        glutGameModeString(glutGamemode);
        glutEnterGameMode();
    } else {
        glutInitWindowSize(prefWidth, prefHeight);
        glutCreateWindow(argv[0]);
    }

    //	// Setup ARgsub_lite library for current OpenGL context.
    //	if ((gArglSettings = arglSetupForCurrentContext()) == NULL) {
    //		fprintf(stderr, "main(): arglSetupForCurrentContext() returned error.\n");
    //		cleanup();
    //		exit(-1);
    //	}
    //	debugReportMode(gArglSettings);
    glEnable(GL_DEPTH_TEST);
    arUtilTimerReset();

    // Load marker(s).
    if (!setupMarker(patt_name, &gPatt_id)) {
        fprintf(stderr, "main(): Unable to set up AR marker.\n");
        cleanup();
        exit(-1);
    }

    //	// Register GLUT event-handling callbacks.
    //	// NB: mainLoop() is registered by Visibility.
    //	glutDisplayFunc(Display);
    //	glutReshapeFunc(Reshape);
    //	glutVisibilityFunc(Visibility);
    //	glutKeyboardFunc(Keyboard);

    //	glutMainLoop();

    return (0);
}
Exemplo n.º 25
0
int main(int argc, char** argv)
{
	char glutGamemode[32];
	const char *cparam_name = "Data/camera_para.dat";
    char vconf[] = "";
	const char *patt_name  = "Data/cubeMarkerConfig.dat";
	
    //
	// Library inits.
	//

	glutInit(&argc, argv);

	//
	// Video setup.
	//

	if (!setupCamera(cparam_name, vconf, &gCparamLT, &gARHandle, &gAR3DHandle)) {
		ARLOGe("main(): Unable to set up AR camera.\n");
		exit(-1);
	}

	//
	// Graphics setup.
	//

	// Set up GL context(s) for OpenGL to draw into.
	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
	if (!prefWindowed) {
		if (prefRefresh) sprintf(glutGamemode, "%ix%i:%i@%i", prefWidth, prefHeight, prefDepth, prefRefresh);
		else sprintf(glutGamemode, "%ix%i:%i", prefWidth, prefHeight, prefDepth);
		glutGameModeString(glutGamemode);
		glutEnterGameMode();
	} else {
		glutInitWindowSize(prefWidth, prefHeight);
		glutCreateWindow(argv[0]);
	}

	// 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);
	debugReportMode(gARHandle);
	glEnable(GL_DEPTH_TEST);
	arUtilTimerReset();
		
	// Load marker(s).
	if (!setupCubeMarker(patt_name, &gMultiConfig, gARHandle, &gARPattHandle)) {
		ARLOGe("main(): Unable to set up AR marker.\n");
		cleanup();
		exit(-1);
	}
	
	// Register GLUT event-handling callbacks.
	// NB: mainLoop() is registered by Visibility.
	glutDisplayFunc(Display);
	glutReshapeFunc(Reshape);
	glutVisibilityFunc(Visibility);
	glutKeyboardFunc(Keyboard);
	
	glutMainLoop();

	return (0);
}
Exemplo n.º 26
0
Scene::Scene(int width, int height, string title, bool fullscreen) {
	int dummyArgc = 1;
	this->fullscreen = fullscreen;
	graph = new Children;
	fishList = new Children;
	sharkList = new Children;

	// Start calls
	glutInit(&dummyArgc, NULL);
	glutInitDisplayMode (GLUT_RGBA | GLUT_DEPTH | GLUT_DOUBLE);

	if (fullscreen) {
		ostringstream mode;
		mode << width << "x" << height << ":16@60";
		glutGameModeString(mode.str().c_str());
		glutEnterGameMode();    } else {
	    glutInitWindowSize(width, height);
	    glutInitWindowPosition(100,0);
	    glutCreateWindow(title.c_str());
	}

	fpsDisplay = new Text(3, 3, "FPS:", 1.3);

	string helpText[] = {
		"Keys:",
		"H         - Toggle help",
		"Space     - Next camera",
		"Escape    - Quit",
		"P         - Pause",
		"X         - Write TGAs",
		"+         - Increase light of glowing fish",
		"-         - Decrease light of glowing fish",
		"F         - Calculate maximum number of fish",
		"N         - Toggle names",
		"O         - Move camera up",
		"L         - Move camera down",
		"T         - Toggle lamp",
		"1         - Add fish",
		"2         - Remove fish",
		"3         - Add shark",
		"4         - Remove shark"
	};
	for (int i = 0; i < 17; i++) {
	    helpDisplay.push_front(new Text(50, 360 - (18 * i), helpText[i], 1.1));
	    helpDisplay.front()->setEnabled(drawHelp);
	}

	// Register callbacks
	glutDisplayFunc(display);
	glutMouseFunc(mouseHandler);
	glutKeyboardFunc(keyboardDownHandler);
	glutKeyboardUpFunc(keyboardUpHandler);
	glutReshapeFunc(reshapeHandler);
	glutIdleFunc(NULL);

	// Visibility settings etc.
	glClearColor(0.4, 0.4, 0.4, 1.0);
	glClearDepth(1.0);
	glDepthFunc(GL_LESS);    // Kind of depth test
	glEnable(GL_DEPTH_TEST);
	glEnable(GL_COLOR_MATERIAL);
	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	glEnable(GL_LIGHTING);
	glShadeModel(GL_SMOOTH);

	// Light 0: Moving fish light
	GLfloat lightDiffuse[]= {1.0f, 1.0f, 1.0f};
	GLfloat light0Pos[] = {0.0f, 0.0f, 0.0f};
	glLightfv(GL_LIGHT0, GL_DIFFUSE, lightDiffuse);
	glLightfv(GL_LIGHT0, GL_SPECULAR, lightDiffuse);
	glLightfv(GL_LIGHT0, GL_POSITION, light0Pos);
	glLightf(GL_LIGHT0, GL_CONSTANT_ATTENUATION, 0.9f);
	glLightf(GL_LIGHT0, GL_LINEAR_ATTENUATION, 0.0f);
	glLightf(GL_LIGHT0, GL_QUADRATIC_ATTENUATION, 0.0f);
	//glLightf(GL_LIGHT0, GL_QUADRATIC_ATTENUATION, attenuation);
	glEnable(GL_LIGHT0);

	// Light 2: Spot light
	GLfloat lightAmbient[]= {0.5f, 0.5f, 0.5f};
	GLfloat	lightPos[] = {0.0f, 250.0f, 0.0f, 1.0f};
	GLfloat spotDir[] = {0.0f, -100.0f, 0.0f};
	//GLfloat cutoff = 90.0f;
	glLightfv(GL_LIGHT1, GL_AMBIENT, lightAmbient);
	glLightfv(GL_LIGHT1, GL_DIFFUSE, lightDiffuse);
	glLightfv(GL_LIGHT1, GL_POSITION, lightPos);
	glLightfv(GL_LIGHT1, GL_SPOT_DIRECTION, spotDir);
	//glLightfv(GL_LIGHT1, GL_SPOT_CUTOFF, &cutoff);
	glLightf(GL_LIGHT1, GL_SPOT_EXPONENT, 50);
	glLightf(GL_LIGHT1, GL_CONSTANT_ATTENUATION, 1);
	if (topLight) {
	    glEnable(GL_LIGHT1);
	}

	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluPerspective(60.0f, (GLfloat)width / (GLfloat)height, 0.1f, 10000.0f);

	glMatrixMode(GL_MODELVIEW);
	glLineWidth(2.5f);

	// Count FPS
	frames = 0;
	glutTimerFunc(1000, fpsTimer, 1);

	// Animation timer
	glutTimerFunc(40, timer, 1);
}
Exemplo n.º 27
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;
}
Exemplo n.º 28
0
void Tutorial::initGlut()
{
  switch (_tutorialID) {
  case 1:
  case 2:
  case 3:
    _pGameCamera = nullptr;
  case 4:
  case 5:
  case 6:
  case 7:
  case 8:
  case 9:
  case 10:
  case 11:
  case 12:
  case 13:
  case 14:
    setWindowSize(WINDOW_WIDTH_1_14, WINDOW_HEIGHT_1_14);
    _pGameCamera = new Camera(WINDOW_WIDTH_1_14, WINDOW_HEIGHT_1_14);
    break;
  case 15:
    setWindowSize(WINDOW_WIDTH_15_17, WINDOW_HEIGHT_15_17);
    _pGameCamera = new Camera(WINDOW_WIDTH_15_17, WINDOW_HEIGHT_15_17);
    break;
  case 16:
    setWindowSize(WINDOW_WIDTH_16, WINDOW_HEIGHT_16);
    _pGameCamera = new Camera(WINDOW_WIDTH_16, WINDOW_HEIGHT_16);
    break;
  case 17:
  case 18:
  case 19:
  case 20:
  case 21:
  case 22:
  case 23:
    return;

  default:
    setWindowSize(WINDOW_WIDTH_1_14, WINDOW_HEIGHT_1_14);
    _pGameCamera = new Camera(WINDOW_WIDTH_1_14, WINDOW_HEIGHT_1_14);
    break;
  }

  setWindowLocation();
  createWindow(_tutorialID);


  glutDisplayFunc(renderFunction);
  glutIdleFunc(idleFunction);
  glutSpecialFunc(specialKeyboardCB);
  glutKeyboardFunc(keyboardCB);
  glutPassiveMotionFunc(passiveMouseCB);

  if (_tutorialID == 15 || _tutorialID == 17) {
    glutGameModeString("1920x1080@24");
    glutEnterGameMode();
  }
  else if (_tutorialID == 16) {
    glutGameModeString("1280x1024@24");
  }
}
Exemplo n.º 29
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));

}
Exemplo n.º 30
0
int main(int argc, char **argv)
{
    char                glutGamemode[32];
    char                *cpara                                 = NULL;
    char                cparaDefault[]                         = "Data/camera_para.dat";
    char                *vconf                                 = NULL;
    int                 patt_names_count                       = 0;
    char                *patt_names[CHECK_ID_MULTIMARKERS_MAX] = {NULL};
    ARdouble            pattRatio                              = (ARdouble)AR_PATT_RATIO;
    AR_MATRIX_CODE_TYPE matrixCodeType                         = AR_MATRIX_CODE_TYPE_DEFAULT;
    int                 labelingMode                           = AR_DEFAULT_LABELING_MODE;
    int                 patternDetectionMode                   = AR_DEFAULT_PATTERN_DETECTION_MODE;
    int                 i, gotTwoPartOption;
    float               tempF;
    int                 tempI;


    //
    // Library inits.
    //

    glutInit(&argc, argv);

    //
    // Startup options.
    //

    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], "--pattRatio") == 0)
            {
                i++;
                if (sscanf(argv[i], "%f", &tempF) == 1 && tempF > 0.0f && tempF < 1.0f)
                    pattRatio = (ARdouble)tempF;
                else
                    ARLOGe("Error: argument '%s' to --pattRatio invalid.\n", argv[i]);

                gotTwoPartOption = TRUE;
            }
            else if (strcmp(argv[i], "--pattSize") == 0)
            {
                i++;
                if (sscanf(argv[i], "%d", &tempI) == 1 && tempI >= 16 && tempI <= AR_PATT_SIZE1_MAX)
                    gPattSize = tempI;
                else
                    ARLOGe("Error: argument '%s' to --pattSize invalid.\n", argv[i]);

                gotTwoPartOption = TRUE;
            }
            else if (strcmp(argv[i], "--pattCountMax") == 0)
            {
                i++;
                if (sscanf(argv[i], "%d", &tempI) == 1 && tempI > 0)
                    gPattCountMax = tempI;
                else
                    ARLOGe("Error: argument '%s' to --pattSize invalid.\n", argv[i]);

                gotTwoPartOption = TRUE;
            }
            else if (strcmp(argv[i], "--borderSize") == 0)
            {
                i++;
                if (sscanf(argv[i], "%f", &tempF) == 1 && tempF > 0.0f && tempF < 0.5f)
                    pattRatio = (ARdouble)(1.0f - 2.0f * tempF);
                else
                    ARLOGe("Error: argument '%s' to --borderSize invalid.\n", argv[i]);

                gotTwoPartOption = TRUE;
            }
            else if (strcmp(argv[i], "--matrixCodeType") == 0)
            {
                i++;
                if (strcmp(argv[i], "AR_MATRIX_CODE_3x3") == 0)
                    matrixCodeType = AR_MATRIX_CODE_3x3;
                else if (strcmp(argv[i], "AR_MATRIX_CODE_3x3_HAMMING63") == 0)
                    matrixCodeType = AR_MATRIX_CODE_3x3_HAMMING63;
                else if (strcmp(argv[i], "AR_MATRIX_CODE_3x3_PARITY65") == 0)
                    matrixCodeType = AR_MATRIX_CODE_3x3_PARITY65;
                else if (strcmp(argv[i], "AR_MATRIX_CODE_4x4") == 0)
                    matrixCodeType = AR_MATRIX_CODE_4x4;
                else if (strcmp(argv[i], "AR_MATRIX_CODE_4x4_BCH_13_9_3") == 0)
                    matrixCodeType = AR_MATRIX_CODE_4x4_BCH_13_9_3;
                else if (strcmp(argv[i], "AR_MATRIX_CODE_4x4_BCH_13_5_5") == 0)
                    matrixCodeType = AR_MATRIX_CODE_4x4_BCH_13_5_5;
                else if (strcmp(argv[i], "AR_MATRIX_CODE_5x5") == 0)
                    matrixCodeType = AR_MATRIX_CODE_5x5;
                else if (strcmp(argv[i], "AR_MATRIX_CODE_6x6") == 0)
                    matrixCodeType = AR_MATRIX_CODE_6x6;
                else if (strcmp(argv[i], "AR_MATRIX_CODE_GLOBAL_ID") == 0)
                    matrixCodeType = AR_MATRIX_CODE_GLOBAL_ID;
                else
                    ARLOGe("Error: argument '%s' to --matrixCodeType invalid.\n", argv[i]);

                gotTwoPartOption = TRUE;
            }
            else if (strcmp(argv[i], "--labelingMode") == 0)
            {
                i++;
                if (strcmp(argv[i], "AR_LABELING_BLACK_REGION") == 0)
                    labelingMode = AR_LABELING_BLACK_REGION;
                else if (strcmp(argv[i], "AR_LABELING_WHITE_REGION") == 0)
                    labelingMode = AR_LABELING_WHITE_REGION;
                else
                    ARLOGe("Error: argument '%s' to --labelingMode invalid.\n", argv[i]);

                gotTwoPartOption = TRUE;
            }
            else if (strcmp(argv[i], "--patternDetectionMode") == 0)
            {
                i++;
                if (strcmp(argv[i], "AR_TEMPLATE_MATCHING_COLOR") == 0)
                    patternDetectionMode = AR_TEMPLATE_MATCHING_COLOR;
                else if (strcmp(argv[i], "AR_TEMPLATE_MATCHING_MONO") == 0)
                    patternDetectionMode = AR_TEMPLATE_MATCHING_MONO;
                else if (strcmp(argv[i], "AR_MATRIX_CODE_DETECTION") == 0)
                    patternDetectionMode = AR_MATRIX_CODE_DETECTION;
                else if (strcmp(argv[i], "AR_TEMPLATE_MATCHING_COLOR_AND_MATRIX") == 0)
                    patternDetectionMode = AR_TEMPLATE_MATCHING_COLOR_AND_MATRIX;
                else if (strcmp(argv[i], "AR_TEMPLATE_MATCHING_MONO_AND_MATRIX") == 0)
                    patternDetectionMode = AR_TEMPLATE_MATCHING_MONO_AND_MATRIX;
                else
                    ARLOGe("Error: argument '%s' to --patternDetectionMode invalid.\n", argv[i]);

                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 (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 (strncmp(argv[i], "-border=", 8) == 0)
            {
                if (sscanf(&(argv[i][8]), "%f", &tempF) == 1 && tempF > 0.0f && tempF < 0.5f)
                    pattRatio = (ARdouble)(1.0f - 2.0f * tempF);
                else
                    ARLOGe("Error: argument '%s' to -border= invalid.\n", argv[i]);
            }
            else
            {
                if (patt_names_count < CHECK_ID_MULTIMARKERS_MAX)
                {
                    patt_names[patt_names_count] = argv[i];
                    patt_names_count++;
                }

                // } else {
                //    ARLOGe("Error: invalid command line argument '%s'.\n", argv[i]);
                //    usage(argv[0]);
            }
        }

        i++;
    }

    //
    // Video setup.
    //

    if (!cpara)
        cpara = cparaDefault;

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

    //
    // AR init.
    //

    arSetPatternDetectionMode(gARHandle, patternDetectionMode);
    arSetLabelingMode(gARHandle, labelingMode);
    arSetPattRatio(gARHandle, pattRatio);
    arSetMatrixCodeType(gARHandle, matrixCodeType);

    //
    // Graphics setup.
    //

    // Set up GL context(s) for OpenGL to draw into.
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
    if (!windowed)
    {
        if (windowRefresh)
            sprintf(glutGamemode, "%ix%i:%i@%i", windowWidth, windowHeight, windowDepth, windowRefresh);
        else
            sprintf(glutGamemode, "%ix%i:%i", windowWidth, windowHeight, windowDepth);

        glutGameModeString(glutGamemode);
        glutEnterGameMode();
    }
    else
    {
        glutInitWindowSize(gCparamLT->param.xsize, gCparamLT->param.ysize);
        glutCreateWindow(argv[0]);
    }

    // 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);
    arUtilTimerReset();

    // Load marker(s).
    if (!setupMarkers(patt_names_count, (const char**)patt_names, gMultiConfigs, gARHandle, &gARPattHandle))
    {
        ARLOGe("main(): Unable to set up AR marker(s).\n");
        cleanup();
        exit(-1);
    }

    gMultiConfigCount = patt_names_count;

    // Register GLUT event-handling callbacks.
    // NB: mainLoop() is registered by Visibility.
    glutDisplayFunc(Display);
    glutReshapeFunc(Reshape);
    glutVisibilityFunc(Visibility);
    glutKeyboardFunc(Keyboard);

    glutMainLoop();

    return (0);
}