Esempio n. 1
0
/* ARGSUSED1 */
void key(unsigned char key, int x, int y)
{
    switch(key)
    {
    case 'u': /* unmodified highlight */
        printf("Use unmodified gouraud highlight\n");
        glutDisplayFunc(redraw_original);
        glutPostRedisplay();
        break;
    case 'd':
        printf("Draw diffuse only\n");
        glutDisplayFunc(redraw_diffuse);
        glutPostRedisplay();
        break;
    case 'g': /* separate gouraud shaded highlight */
        printf("Use separate gouraud shaded highlight\n");
        glutDisplayFunc(redraw_phong);
        glutPostRedisplay();
        break;
    case 't': /* separate textured highlight */
        printf("Use separate texture highlight\n");
        glutDisplayFunc(redraw_tex);
        glutPostRedisplay();
        break;
    case 'o':
        /* toggle object type */
        object++;
        if(object > maxobject)
            object = 2;
        glutPostRedisplay();
        break;
    case 'm':
        /* show highlight texture map */
        printf("Show highlight texture map\n");
        glutDisplayFunc(redraw_map);
        glutPostRedisplay();
        break;
    case 'n':
        if(notex)
            notex = FALSE;
        else
            notex = TRUE;
        glutPostRedisplay();
        break;
    case 'h':
        printf("Show textured phong highlight\n");
        glutDisplayFunc(redraw_tex_highlight);
        glutPostRedisplay();
        break;
    case 'p':
        printf("Show gouraud-shaded phong highlight\n");
        glutDisplayFunc(redraw_gouraud_highlight);
        glutPostRedisplay();
        break;
    case 'w':
        printf("Show white object\n");
        glutDisplayFunc(redraw_white);
        glutPostRedisplay();
        break;
    case '\033':
        exit(0);
        break;
    default:
        fprintf(stderr, "Keyboard commands:\n\n"
                "u - (unmodified opengl lighting)\n"
                "d - diffuse only\n"
                "g - multipass gouraud highlight\n"
                "t - multipass texture highlight\n"
                "o - toggle object\n"
                "m - show highlight texture map\n"
                "n - toggle surface texturing\n"
                "h - show textured phong highlight\n"
                "p - show gouraud-shaded phong highlight\n"
                "w - show unlit white object\n");
        break;
    }

}
Esempio n. 2
0
void INIT(void)
{
  printf("Morph 3D - Shows morphing platonic polyhedra\n");
  printf("Author: Marcelo Fernandes Vianna ([email protected])\n\n");
  printf("  [1]    - Tetrahedron\n");
  printf("  [2]    - Hexahedron (Cube)\n");
  printf("  [3]    - Octahedron\n");
  printf("  [4]    - Dodecahedron\n");
  printf("  [5]    - Icosahedron\n");
  printf("  [s]    - Slow,  more sleep time\n");
  printf("  [f]    - Faster,less sleep time\n");
  printf("[SPACE]  - Toggle colored faces\n");
  printf("[RETURN] - Toggle smooth/flat shading\n");
  printf(" [ESC]   - Quit\n");

  object=1;

  glutInitWindowPosition(0,0);
  glutInitWindowSize(640,480);

  glutInitDisplayMode( GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGB );

  if (glutCreateWindow("Morph 3D - Shows morphing platonic polyhedra") <= 0) {
     exit(0);
  }

  glClearDepth(1.0);
  glClearColor( 0.0, 0.0, 0.0, 1.0 );
  glColor3f( 1.0, 1.0, 1.0 );

  glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
  glFlush();
  glutSwapBuffers();

  glLightfv(GL_LIGHT0, GL_AMBIENT, ambient);
  glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse);
  glLightfv(GL_LIGHT0, GL_POSITION, position0);
  glLightfv(GL_LIGHT1, GL_AMBIENT, ambient);
  glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuse);
  glLightfv(GL_LIGHT1, GL_POSITION, position1);
  glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient);
  glLightModelfv(GL_LIGHT_MODEL_TWO_SIDE, lmodel_twoside);
  glEnable(GL_LIGHTING);
  glEnable(GL_LIGHT0);
  glEnable(GL_LIGHT1);
  glEnable(GL_DEPTH_TEST);
  glEnable(GL_NORMALIZE);

  glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, front_shininess);
  glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, front_specular);

  glHint(GL_FOG_HINT, GL_FASTEST);
  glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST);
  glHint(GL_POLYGON_SMOOTH_HINT, GL_FASTEST);

  pinit();

  glutReshapeFunc( reshape );
  glutKeyboardFunc( key );
  glutIdleFunc( idle_ );
  glutDisplayFunc( draw );
  glutMainLoop();
  
}
Esempio n. 3
0
int main(int argc, char **argv) {

//  GLUT initialization
	glutInit(&argc, argv);

	glutInitDisplayMode(GLUT_DEPTH|GLUT_DOUBLE|GLUT_RGBA|GLUT_MULTISAMPLE);

	glutInitContextVersion (3, 3);
	glutInitContextFlags (GLUT_COMPATIBILITY_PROFILE );

	glutInitWindowPosition(100,100);
	glutInitWindowSize(320,320);
	glutCreateWindow("Lighthouse3D - Assimp Demo");
		

//  Callback Registration
	glutDisplayFunc(renderScene);
	glutReshapeFunc(changeSize);
	glutIdleFunc(renderScene);

//	Mouse and Keyboard Callbacks
	glutKeyboardFunc(processKeys);
	glutMouseFunc(processMouseButtons);
	glutMotionFunc(processMouseMotion);
	
	glutMouseWheelFunc ( mouseWheel ) ;

//	Init GLEW
	//glewExperimental = GL_TRUE;
	glewInit();
	if (glewIsSupported("GL_VERSION_3_3"))
		printf("Ready for OpenGL 3.3\n");
	else {
		printf("OpenGL 3.3 not supported\n");
		return(1);
	}

//  Init the app (load model and textures) and OpenGL
	if (!init())
		printf("Could not Load the Model\n");

   printf ("Vendor: %s\n", glGetString (GL_VENDOR));
   printf ("Renderer: %s\n", glGetString (GL_RENDERER));
   printf ("Version: %s\n", glGetString (GL_VERSION));
   printf ("GLSL: %s\n", glGetString (GL_SHADING_LANGUAGE_VERSION));


   // return from main loop
	glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_GLUTMAINLOOP_RETURNS);

//  GLUT main loop
	glutMainLoop();

	// cleaning up
	textureIdMap.clear();  

	// clear myMeshes stuff
	for (unsigned int i = 0; i < myMeshes.size(); ++i) {
			
		glDeleteVertexArrays(1,&(myMeshes[i].vao));
		glDeleteTextures(1,&(myMeshes[i].texIndex));
		glDeleteBuffers(1,&(myMeshes[i].uniformBlockIndex));
	}
	// delete buffers
	glDeleteBuffers(1,&matricesUniBuffer);

	return(0);
}
/* ---------------------------------------------------------------------------- */
int main(int argc, char **argv)
{
	struct aiLogStream stream;

	glutInitWindowSize(900,600);
	glutInitWindowPosition(100,100);
	glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
	glutInit(&argc, argv);

	glutCreateWindow("Assimp - Very simple OpenGL sample");
	glutDisplayFunc(display);
	glutReshapeFunc(reshape);

	/* get a handle to the predefined STDOUT log stream and attach
	   it to the logging system. It remains active for all further
	   calls to aiImportFile(Ex) and aiApplyPostProcessing. */
	stream = aiGetPredefinedLogStream(aiDefaultLogStream_STDOUT,NULL);
	aiAttachLogStream(&stream);

	/* ... same procedure, but this stream now writes the
	   log messages to assimp_log.txt */
	stream = aiGetPredefinedLogStream(aiDefaultLogStream_FILE,"assimp_log.txt");
	aiAttachLogStream(&stream);

	/* the model name can be specified on the command line. If none
	  is specified, we try to locate one of the more expressive test 
	  models from the repository (/models-nonbsd may be missing in 
	  some distributions so we need a fallback from /models!). */
	if( 0 != loadasset( argc >= 2 ? argv[1] : "../../test/models-nonbsd/X/dwarf.x")) {
		if( argc != 1 || (0 != loadasset( "../../../../test/models-nonbsd/X/dwarf.x") && 0 != loadasset( "../../test/models/X/Testwuson.X"))) { 
			return -1;
		}
	}

	glClearColor(0.1f,0.1f,0.1f,1.f);

	glEnable(GL_LIGHTING);
	glEnable(GL_LIGHT0);    /* Uses default lighting parameters */

	glEnable(GL_DEPTH_TEST);

	glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
	glEnable(GL_NORMALIZE);

	/* XXX docs say all polygons are emitted CCW, but tests show that some aren't. */
	if(getenv("MODEL_IS_BROKEN"))  
		glFrontFace(GL_CW);

	glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);

	glutGet(GLUT_ELAPSED_TIME);
	glutMainLoop();

	/* cleanup - calling 'aiReleaseImport' is important, as the library 
	   keeps internal resources until the scene is freed again. Not 
	   doing so can cause severe resource leaking. */
	aiReleaseImport(scene);

	/* We added a log stream to the library, it's our job to disable it
	   again. This will definitely release the last resources allocated
	   by Assimp.*/
	aiDetachAllLogStreams();
	return 0;
}
Esempio n. 5
0
/**
 * The entry point of the application.
 *
 * @param argc  The number of command line arguments
 * @param argv  The array of command line arguments
 * @return      A status code
 */
int main(int argc, char **argv)
 {
     delay = 20;
     glutInit(&argc, argv);
     window = createWindow("Stage", 640, 480, 0, 0);
     glutDisplayFunc(display);
     glutMouseFunc(mouse);
     glutKeyboardFunc(keyboard);
     glutSpecialFunc(keySpecial);
     glutTimerFunc(delay, timer, 0);

     
     char* testImages[] = {"/raws/exit_2704.raw", "/raws/plain_wall.raw", "/raws/left_hallways_floor.raw", "/raws/plain_wall.raw", "/raws/plain_wall.raw", "/raws/ceiling.raw"};
     
     CubeFactory        factory;
     Model              model;
     BaseCube           middle;
     vector<Cube>       cubes;
     vector<Hallway*>   hallways;
     Cube               nTelasRoom, nTelasRoomHallway;
     CubeProperties     properties;
     GLfloat            startingAngles[3];
     Hallway           *jmuFront, *jmuBack, *jmuRight, *jmuLeft, *jmuMiddle;
     Position           position;
     
     startingAngles[0] = 0;
     startingAngles[1] = 0;
     startingAngles[2] = 0;
     
     properties = CubeProperties();
     factory    = CubeFactory();
     
     /***Front Hallway ***/
     startingAngles[1]  = 90;
     properties.setCubeVertices(10, 10, 10);
     properties.setImages(FRONTH);
     cubes      = factory.createUniformCubes(-120, 0, 45, 13, startingAngles, properties, 20, 0,0);
     jmuFront = new JmuFrontHallway(cubes);
     hallways.push_back(jmuFront);
          
     /***Back Hallway ***/
     startingAngles[1]  = -90;
     properties.setImages(BACKH);
     cubes      = factory.createUniformCubes(-120, 0, -195, 13, startingAngles, properties, 20,0,0);
     jmuBack    = new JmuBackHallway(cubes);
     hallways.push_back(jmuBack);
     
     startingAngles[1]  = 0;
     
     /***Left Hallway ***/
     properties.setImages(LEFTH);
     cubes      = factory.createUniformCubes(-120, 0, 45, 13, startingAngles, properties, 0,0,-20);
     jmuLeft    = new JmuLeftHallway(cubes);
     hallways.push_back(jmuLeft);
     
     /***Right Hallway ***/
     properties.setImages(RIGHTH);
     cubes      = factory.createUniformCubes(120, 0, 45, 13, startingAngles, properties, 0,0,-20);
     jmuRight   = new JmuRightHallway(cubes);
     hallways.push_back(jmuRight);
     
     /***Middle Hallway ***/
     properties.setCubeVertices(30, 10, 10);
     properties.setImages(MIDDLEH);
     cubes      = factory.createUniformCubes(0, 0, 45, 13, startingAngles, properties, 0,0,-20);
     jmuMiddle  = new JmuMiddleHallway(cubes);
     hallways.push_back(jmuMiddle);

     middle      = BaseCube(0, 0, 55, 10.0);
     model       = Model(hallways, middle, startingAngles);
     stage.addSprite(&model);
     stage.start();
     
     return 0;
 }
Esempio n. 6
0
int main(int argc, char** argv)
{
	char *modelFilename    = NULL;
	char *modelTexturePath = NULL;
	
	if(argc == 2)
	{
		modelFilename = argv[1];
		modelTexturePath = NULL;
	}
	else if(argc == 3)
	{
		modelFilename = argv[1];
		modelTexturePath = argv[2];
	}
	else
	{
		printf("Usage:\n"
		       "%s modelFile     - Textures are assumed to be in the same directory as the model.\n"
		       "- or -\n"
		       "%s modelFile texturePath\n", argv[0], argv[0]);
		exit(1);
	}

	/* set up our GLUT window */
	glutInit(&argc, argv);
	glutInitWindowSize(512, 512);
	/* Ask GLUT to for a double buffered, full color window that
	 * includes a depth buffer */
#ifdef FREEGLUT
	glutSetOption(GLUT_MULTISAMPLE, 4); // set msaa samples; default to 4
	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH | GLUT_MULTISAMPLE);
	glutInitContextVersion(3,2);
	glutInitContextProfile(GLUT_CORE_PROFILE);
#else
	glutInitDisplayMode(GLUT_3_2_CORE_PROFILE | GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH | GLUT_MULTISAMPLE);
#endif
	glutCreateWindow(argv[0]); // set window title to executable name
	glEnable(GL_MULTISAMPLE);

	/* Initialize GLEW */
	glewExperimental = GL_TRUE;
	GLenum glewError = glewInit();
	if(glewError != GLEW_OK)
	{
		fprintf(stderr, "Error initializing GLEW: %s\n", glewGetErrorString(glewError));
		exit(EXIT_FAILURE);
	}
	/* When experimental features are turned on in GLEW, the first
	 * call to glGetError() or kuhl_errorcheck() may incorrectly
	 * report an error. So, we call glGetError() to ensure that a
	 * later call to glGetError() will only see correct errors. For
	 * details, see:
	 * http://www.opengl.org/wiki/OpenGL_Loading_Library */
	glGetError();

	// setup callbacks
	glutDisplayFunc(display);
	glutKeyboardFunc(keyboard);

	/* Compile and link a GLSL program composed of a vertex shader and
	 * a fragment shader. */
	program = kuhl_create_program(GLSL_VERT_FILE, GLSL_FRAG_FILE);

	dgr_init();     /* Initialize DGR based on environment variables. */
	projmat_init(); /* Figure out which projection matrix we should use based on environment variables */

	float initCamPos[3]  = {0,1.55,2}; // 1.55m is a good approx eyeheight
	float initCamLook[3] = {0,0,0}; // a point the camera is facing at
	float initCamUp[3]   = {0,1,0}; // a vector indicating which direction is up
	viewmat_init(initCamPos, initCamLook, initCamUp);

	// Clear the screen while things might be loading
	glClearColor(.2,.2,.2,1);
	glClear(GL_COLOR_BUFFER_BIT);

	// Load the model from the file
	modelgeom = kuhl_load_model(modelFilename, modelTexturePath, program, bbox);

	/* Count the number of kuhl_geometry objects for this model */
	unsigned int geomCount = kuhl_geometry_count(modelgeom);
	
	/* Allocate an array of particle arrays */
	particles = malloc(sizeof(particle*)*geomCount);
	int i = 0;
	for(kuhl_geometry *g = modelgeom; g != NULL; g=g->next)
	{
		/* allocate space to store velocity information for all of the
		 * vertices in this kuhl_geometry */
		particles[i] = malloc(sizeof(particle)*g->vertex_count);
		for(unsigned int j=0; j<g->vertex_count; j++)
			vec3f_set(particles[i][j].velocity, 0,0,0);

		/* Change the geometry to be drawn as points */
		g->primitive_type = GL_POINTS; // Comment out this line to default to triangle rendering.
		i++;
	}

	/* Tell GLUT to start running the main loop and to call display(),
	 * keyboard(), etc callback methods as needed. */
	glutMainLoop();
	/* // An alternative approach:
	   while(1)
	   glutMainLoopEvent();
	*/

	exit(EXIT_SUCCESS);
}
Esempio n. 7
0
void setupGLUTFunctions()
{
	glutDisplayFunc(displayGLUT);
	glutIdleFunc(idleGLUT);
}
    FreeGlutGLView* FreeGlutGLView::start(void* _renderer, std::string name, int _width, int _height) {
		printf("freglutglview start");
	    renderer = (RendererWin32*) _renderer;

	    /* annoying useless setup for glutInit */

		char* argv[] = {_strdup(name.c_str())};
	    int argc = 1;
	
	    glutInit(&argc, argv);
	    glutInitContextVersion(3,3);
		
		printf("freglutglview start");
		glutInitWindowSize(_width, _height);
	    glutCreateWindow(name.c_str());

		//glew initialization
		glewExperimental = GL_TRUE;
		GLenum err = glewInit();
		if (GLEW_OK != err)	{
			cerr << "Error: " << glewGetErrorString(err) << endl;
		}
		else {
			if (GLEW_VERSION_3_3) {
				cout << "Driver supports OpenGL 3.3\nDetails:" << endl;
			}
		}
		err = glGetError(); //this is to ignore INVALID ENUM error 1282
	//	GL_CHECK_ERRORS


			//output hardware information
		cout << "\tUsing GLEW " << glewGetString(GLEW_VERSION) << endl;
		cout << "\tVendor: " << glGetString(GL_VENDOR) << endl;
		cout << "\tRenderer: " << glGetString(GL_RENDERER) << endl;
		cout << "\tVersion: " << glGetString(GL_VERSION) << endl;
		cout << "\tGLSL: " << glGetString(GL_SHADING_LANGUAGE_VERSION) << endl;

		// call this ONLY when linking with FreeImage as a static library
		
		#ifdef FREEIMAGE_LIB
				FreeImage_Initialise();
				cout << "\tFreeImage: " << FreeImage_GetVersion() << endl;
		#endif
		

    //	glutGameModeString("1280x1024:32@60");
    //	glutEnterGameMode();
		
		renderer->setStartTick();
	    renderer->onCreate();

	    glutDisplayFunc(&display);
	    glutReshapeFunc(&reshape);
		glutKeyboardFunc(&keyboard);
	    glutMouseFunc(&pressed);
	    glutMotionFunc(&dragged);
	    glutPassiveMotionFunc(&moved);
		glutIdleFunc(&animate);
		printf("freglutglview start");
		//lastTime = std::clock();
		//std::time(&lastTime);
	    //gettimeofday(&lastTime, NULL);
		printf("freglutglview start");
	    glutMainLoop();

	    //glutInitDisplayMode(GL_RGBA);
	    //glutInitWindowSize(200,200);
	    //glutCreateWindow("test");
		printf("freglutglview start");
	    return NULL;
	    //return glView;
		
    }
Esempio n. 9
0
int main(int argc, char** argv)
{
	testCount = 0;
	while (g_testEntries[testCount].createFcn != NULL)
	{
		++testCount;
	}

	testIndex = b2Clamp(testIndex, 0, testCount-1);
	testSelection = testIndex;

	entry = g_testEntries + testIndex;

	test = entry->createFcn();

	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE);
	glutInitWindowSize(width, height);
	char title[32];
	sprintf(title, "Box2D Version %d.%d.%d", b2_version.major, b2_version.minor, b2_version.revision);
	mainWindow = glutCreateWindow(title);
	//glutSetOption (GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_GLUTMAINLOOP_RETURNS);

	glutDisplayFunc(SimulationLoop);

/*	int theConnection=0;
	theConnection=setup_rlglue_network();
	runEnvironmentEventLoop(theConnection);*/

	GLUI_Master.set_glutReshapeFunc(Resize);  
	GLUI_Master.set_glutKeyboardFunc(Keyboard);
	GLUI_Master.set_glutSpecialFunc(KeyboardSpecial);
	GLUI_Master.set_glutMouseFunc(Mouse);
#ifdef FREEGLUT
	glutMouseWheelFunc(MouseWheel);
#endif
	glutMotionFunc(MouseMotion);

	glui = GLUI_Master.create_glui_subwindow( mainWindow, 
		GLUI_SUBWINDOW_RIGHT );

	glui->add_statictext("Tests");
	GLUI_Listbox* testList =
		glui->add_listbox("", &testSelection);

	glui->add_separator();

	GLUI_Spinner* velocityIterationSpinner =
		glui->add_spinner("Vel Iters", GLUI_SPINNER_INT, &settings.velocityIterations);
	velocityIterationSpinner->set_int_limits(1, 500);

	GLUI_Spinner* positionIterationSpinner =
		glui->add_spinner("Pos Iters", GLUI_SPINNER_INT, &settings.positionIterations);
	positionIterationSpinner->set_int_limits(0, 100);

	GLUI_Spinner* hertzSpinner =
		glui->add_spinner("Hertz", GLUI_SPINNER_FLOAT, &settingsHz);

	hertzSpinner->set_float_limits(5.0f, 200.0f);

	glui->add_checkbox("Warm Starting", &settings.enableWarmStarting);
	glui->add_checkbox("Time of Impact", &settings.enableContinuous);

	//glui->add_separator();

	GLUI_Panel* drawPanel =	glui->add_panel("Draw");
	glui->add_checkbox_to_panel(drawPanel, "Shapes", &settings.drawShapes);
	glui->add_checkbox_to_panel(drawPanel, "Joints", &settings.drawJoints);
	glui->add_checkbox_to_panel(drawPanel, "AABBs", &settings.drawAABBs);
	glui->add_checkbox_to_panel(drawPanel, "Pairs", &settings.drawPairs);
	glui->add_checkbox_to_panel(drawPanel, "Contact Points", &settings.drawContactPoints);
	glui->add_checkbox_to_panel(drawPanel, "Contact Normals", &settings.drawContactNormals);
	glui->add_checkbox_to_panel(drawPanel, "Contact Forces", &settings.drawContactForces);
	glui->add_checkbox_to_panel(drawPanel, "Friction Forces", &settings.drawFrictionForces);
	glui->add_checkbox_to_panel(drawPanel, "Center of Masses", &settings.drawCOMs);
	glui->add_checkbox_to_panel(drawPanel, "Statistics", &settings.drawStats);

	int32 testCount = 0;
	TestEntry* e = g_testEntries;
	while (e->createFcn)
	{
		testList->add_item(testCount, e->name);
		++testCount;
		++e;
	}

	glui->add_button("Pause", 0, Pause);
	glui->add_button("Single Step", 0, SingleStep);
	glui->add_button("Restart", 0, Restart);

	glui->add_button("Quit", 0,(GLUI_Update_CB)exit);
	glui->set_main_gfx_window( mainWindow );

	// Use a timer to control the frame rate.
	glutTimerFunc(framePeriod, Timer, 0);

////////////////////////////////////////////////////////////////////////////////////////////
	/*const char *task_spec;
	printf("\nThis is a RL Test program(Start)\n");
	task_spec = RL_init();
	printf("\nTASK SPEC : %s\n",task_spec);
   	printf("Starting offline demo\n----------------------------\nWill alternate learning for 25 episodes, then freeze policy and evaluate for 10 episodes.\n\n");
	printf("After Episode\tMean Return\tStandard Deviation\n-------------------------------------------------------------------------\n");

	oa = RL_start();

	RL_agent_message("load_policy results.dat");
	RL_agent_message("freeze learning");*/

	const char* task_spec;
	task_spec = env_init();
	agent_init(task_spec);

////////////////////////////////////////////////////////////////////////////////////////////
/*
	agent_message("load_policy results.dat");
	agent_message("freeze learning");*/

	glutMainLoop();

	return 0;
}
Esempio n. 10
0
int
main(int argc, char **argv)
{
  int i;

  glutInitWindowSize(400, 200);
  glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH | GLUT_MULTISAMPLE);
  glutInit(&argc, argv);

  for (i = 1; i < argc; i++) {
    if (!strcmp("-sb", argv[i])) {
      glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_MULTISAMPLE);
      singleBuffer = 1;
    }
  }

  glutCreateWindow("multilight");

  glClearColor(0.0, 0.0, 0.0, 0.0);

  glMatrixMode(GL_PROJECTION);
  gluPerspective(50.0, 2.0, 0.1, 100.0);
  glMatrixMode(GL_MODELVIEW);
  gluLookAt(
    0.0, 1.0, -16.0,
    0.0, 0.0, 0.0,
    0.0, 1.0, 0.);

  numActiveLights = MIN_VALUE(MAX_LIGHTS, 8);
  for (i = 0; i < numActiveLights; i++) {
    initLight(i);
  }

  glLightModelfv(GL_LIGHT_MODEL_AMBIENT, modelAmb);
  glLightModelf(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE);
  glLightModelf(GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE);
  glEnable(GL_CULL_FACE);
  glEnable(GL_DEPTH_TEST);

  glMaterialfv(GL_FRONT, GL_AMBIENT, matAmb);
  glMaterialfv(GL_FRONT, GL_DIFFUSE, matDiff);
  glMaterialfv(GL_FRONT, GL_SPECULAR, matSpec);
  glMaterialfv(GL_FRONT, GL_EMISSION, matEmission);
  glMaterialf(GL_FRONT, GL_SHININESS, 10.0);

  glNewList(DL_LIGHT_SPHERE, GL_COMPILE);
  glutSolidSphere(0.2, 4, 4);
  glEndList();

  glNewList(DL_BIG_SPHERE, GL_COMPILE);
  glutSolidSphere(1.5, 20, 20);
  glEndList();

  glNewList(DL_ICO, GL_COMPILE);
  glutSolidIcosahedron();
  glEndList();

  glutDisplayFunc(display);
  glutVisibilityFunc(visible);
  glutKeyboardFunc(key);
  glutMouseFunc(mouse);
  glutMotionFunc(motion);

  glutCreateMenu(menu);
  glutAddMenuEntry("Sphere", M_SPHERE);
  glutAddMenuEntry("Icosahedron", M_ICO);
  glutAddMenuEntry("Linear attenuation", M_LINEAR);
  glutAddMenuEntry("Quadratic attenuation", M_QUAD);
  glutAddMenuEntry("Toggle Light Number Labels", M_LABELS);
  glutAddMenuEntry("Report Light Significance", M_REPORT_SIG);
  glutAddMenuEntry("Lambertian-based Significance", M_LAMBERTIAN);
  glutAddMenuEntry("Distance-based Significance", M_DISTANCE);
  glutAddMenuEntry("Time Frames", M_TIME);
  glutAddMenuEntry("Quit", 666);
  glutAttachMenu(GLUT_RIGHT_BUTTON);

  glutMainLoop();
  return 0;             /* ANSI C requires main to return int. */
}
int main(int argc, char** argv)
{
	if (argc != 7) {
        printf("%d", argc);
        for (int i = 0; i < argc; i++) {
            printf("%s\n", argv[i]);
        }
		usage();
    }

	vertexShader   = std::string(argv[1]);
	fragmentShader = std::string(argv[2]);
    meshOBJ        = std::string(argv[3]);
	normalMap      = std::string(argv[4]);
	displacementMap      = std::string(argv[5]);
	colorMap       =std::string(argv[6]);

    //
    // Initialize GLUT.
    //
    glutInit(&argc, argv);
    glutInitDisplayMode( GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
    glutInitWindowPosition(20, 20);
    glutInitWindowSize(640, 480);
    glutCreateWindow("CS148 Texturing");
    
    //
    // Initialize GLEW.
    //
#ifndef __APPLE__
    glewInit();
    if(!GLEW_VERSION_2_0) {
        printf("Your graphics card or graphics driver does\n"
			   "\tnot support OpenGL 2.0, trying ARB extensions\n");

        if(!GLEW_ARB_vertex_shader || !GLEW_ARB_fragment_shader) {
            printf("ARB extensions don't work either.\n");
            printf("\tYou can try updating your graphics drivers.\n"
				   "\tIf that does not work, you will have to find\n");
            printf("\ta machine with a newer graphics card.\n");
            exit(1);
        }
    }
#endif

    // Be sure to initialize GLUT (and GLEW for this assignment) before
    // initializing your application.

    Setup();

    glutDisplayFunc(DisplayCallback);
    glutReshapeFunc(ReshapeCallback);
    glutSpecialFunc(SpecialKeyCallback);
    glutKeyboardFunc(KeyCallback);
    glutMouseFunc(MouseCallback);
    glutMotionFunc(MouseMotionCallback);
    glutIdleFunc(DisplayCallback);

    glutMainLoop();

    // Cleanup code should be called here.
    CleanUp();

    return 0;
}
Esempio n. 12
0
/* Parse arguments, and set up interface between OpenGL and window system */
int
main(int argc, char *argv[])
{
    GLUquadricObj *sphere, *cone, *base;
    GLfloat v0[3], v1[3], v2[3];
    unsigned *floortex;
    int texcomps, texwid, texht;

    glutInit(&argc, argv);
    glutInitWindowSize(512, 512);
    if(argc > 1)
    {
	char *args = argv[1];
	int done = GL_FALSE;
	while(!done)
	{
	    switch(*args)
	    {
	    case 's': /* single buffer */
		printf("Single Buffered\n");
		dblbuf = GL_FALSE;
		break;
	    case '-': /* do nothing */
		break;
	    case 0:
		done = GL_TRUE;
		break;
	    }
	    args++;
	}
    }
    if(dblbuf)
	glutInitDisplayMode(GLUT_RGBA|GLUT_DEPTH|GLUT_STENCIL|GLUT_DOUBLE);
    else
	glutInitDisplayMode(GLUT_RGBA|GLUT_DEPTH|GLUT_STENCIL);

    (void)glutCreateWindow("projection shadows");
    glutDisplayFunc(redraw);
    glutKeyboardFunc(key);
    glutMouseFunc(mouse);
    glutMotionFunc(motion);
    glutReshapeFunc(reshape);

    glutCreateMenu(menu);
    glutAddMenuEntry("No Shadows", NONE);
    glutAddMenuEntry("Black Shadows", SHADOW_BLACK);
    glutAddMenuEntry("Shadows on Texture", SHADOW);
    glutAttachMenu(GLUT_RIGHT_BUTTON);


    /* draw a perspective scene */
    glMatrixMode(GL_PROJECTION);
    glFrustum(-100., 100., -100., 100., 320., 640.); 
    glMatrixMode(GL_MODELVIEW);

    /* turn on features */
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT0);

    /* make shadow matricies */

      /* 3 points on floor */
      v0[X] = -100.f; v0[Y] = -100.f; v0[Z] = -320.f;
      v1[X] =  100.f; v1[Y] = -100.f; v1[Z] = -320.f;
      v2[X] =  100.f; v2[Y] = -100.f; v2[Z] = -520.f;
      
      findplane(floorplane, v0, v1, v2);
      shadowmatrix(floorshadow, floorplane, lightpos);

      /* 3 points on left wall */
      v0[X] = -100.f; v0[Y] = -100.f; v0[Z] = -320.f;
      v1[X] = -100.f; v1[Y] = -100.f; v1[Z] = -520.f;
      v2[X] = -100.f; v2[Y] =  100.f; v2[Z] = -520.f;

      findplane(lwallplane, v0, v1, v2);
      shadowmatrix(leftwallshadow, lwallplane, lightpos);

    /* place light 0 in the right place */
    glLightfv(GL_LIGHT0, GL_POSITION, lightpos);

    /* remove back faces to speed things up */
    glCullFace(GL_BACK);

    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);

    /* make display lists for sphere and cone; for efficiency */

    glNewList(WALLS, GL_COMPILE);
    glColor3f(1.f, 1.f, 1.f);
    glBegin(GL_QUADS);
    /* right wall */
    glNormal3f(-1.f, 0.f, 0.f);
    glVertex3f( 100.f, -100.f, -320.f);
    glVertex3f( 100.f,  100.f, -320.f);
    glVertex3f( 100.f,  100.f, -520.f);
    glVertex3f( 100.f, -100.f, -520.f);

    /* ceiling */
    glNormal3f(0.f, -1.f, 0.f);
    glVertex3f(-100.f,  100.f, -320.f);
    glVertex3f(-100.f,  100.f, -520.f);
    glVertex3f( 100.f,  100.f, -520.f);
    glVertex3f( 100.f,  100.f, -320.f);

    /* back wall */
    glNormal3f(0.f, 0.f, 1.f);
    glVertex3f(-100.f, -100.f, -520.f);
    glVertex3f( 100.f, -100.f, -520.f);
    glVertex3f( 100.f,  100.f, -520.f);
    glVertex3f(-100.f,  100.f, -520.f);
    glEnd();
    glEndList();


    glNewList(SPHERE, GL_COMPILE);
    sphere = gluNewQuadric();
    glPushMatrix();
    glTranslatef(60.f, -50.f, -360.f);
    gluSphere(sphere, 20.f, 20, 20);
    gluDeleteQuadric(sphere);
    glPopMatrix();
    glEndList();


    glNewList(LIGHT, GL_COMPILE);
    sphere = gluNewQuadric();
    gluSphere(sphere, 5.f, 20, 20);
    gluDeleteQuadric(sphere);
    glEndList();

    glNewList(CONE, GL_COMPILE);
    cone = gluNewQuadric();
    base = gluNewQuadric();
    glPushMatrix();
    glTranslatef(-40.f, -40.f, -400.f);
    glRotatef(-90.f, 1.f, 0.f, 0.f);
    gluDisk(base, 0., 20., 20, 1);
    gluCylinder(cone, 20., 0., 60., 20, 20);
    gluDeleteQuadric(cone);
    gluDeleteQuadric(base);
    glPopMatrix();
    glEndList();


    glNewList(SHADOWERS, GL_COMPILE);
    glCallList(CONE);
    glCallList(SPHERE);
    glEndList();

    glNewList(FLOOR, GL_COMPILE);
    /* make the floor textured */
    glEnable(GL_TEXTURE_2D);
    glBegin(GL_QUADS);
    glNormal3f(0.f, 1.f, 0.f);
    glTexCoord2i(0, 0);
    glVertex3f(-100.f, -100.f, -320.f);
    glTexCoord2i(1, 0);
    glVertex3f( 100.f, -100.f, -320.f);
    glTexCoord2i(1, 1);
    glVertex3f( 100.f, -100.f, -520.f);
    glTexCoord2i(0, 1);
    glVertex3f(-100.f, -100.f, -520.f);
    glEnd();
    glDisable(GL_TEXTURE_2D);
    glEndList();

    glNewList(LEFTWALL, GL_COMPILE);
    glBegin(GL_QUADS);
    /* left wall */
    glNormal3f(1.f, 0.f, 0.f);
    glVertex3f(-100.f, -100.f, -320.f);
    glVertex3f(-100.f, -100.f, -520.f);
    glVertex3f(-100.f,  100.f, -520.f);
    glVertex3f(-100.f,  100.f, -320.f);
    glEnd();
    glEndList();

    floortex = read_texture("../../data/wood0.rgb",
			    &texwid, &texht, &texcomps);

    gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, texwid, texht, GL_RGBA,
		      GL_UNSIGNED_BYTE, floortex);

    free(floortex);

    glEnable(GL_COLOR_MATERIAL);
    glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);

    glutMainLoop();
    return 0;
}
Esempio n. 13
0
int main(int argc, char *argv[])
{
	elf_firmware_t f;
	const char * fname =  "atmega168_timer_64led.axf";
	//char path[256];

//	sprintf(path, "%s/%s", dirname(argv[0]), fname);
	//printf("Firmware pathname is %s\n", path);
	elf_read_firmware(fname, &f);

	printf("firmware %s f=%d mmcu=%s\n", fname, (int)f.frequency, f.mmcu);

	avr = avr_make_mcu_by_name(f.mmcu);
	if (!avr) {
		fprintf(stderr, "%s: AVR '%s' now known\n", argv[0], f.mmcu);
		exit(1);
	}
	avr_init(avr);
	avr_load_firmware(avr, &f);

	//
	// initialize our 'peripherals'
	//
	hc595_init(avr, &shifter);
	
	button_init(avr, &button[B_START], "button.start");
	avr_connect_irq(
		button[B_START].irq + IRQ_BUTTON_OUT,
		avr_io_getirq(avr, AVR_IOCTL_IOPORT_GETIRQ('C'), 0));
	button_init(avr, &button[B_STOP], "button.stop");
	avr_connect_irq(
		button[B_STOP].irq + IRQ_BUTTON_OUT,
		avr_io_getirq(avr, AVR_IOCTL_IOPORT_GETIRQ('B'), 1));
	button_init(avr, &button[B_RESET], "button.reset");
	avr_connect_irq(
		button[B_RESET].irq + IRQ_BUTTON_OUT,
		avr_io_getirq(avr, AVR_IOCTL_IOPORT_GETIRQ('B'), 0));

	// connects the fake 74HC595 array to the pins
	avr_irq_t * i_mosi = avr_io_getirq(avr, AVR_IOCTL_SPI_GETIRQ(0), SPI_IRQ_OUTPUT),
			* i_reset = avr_io_getirq(avr, AVR_IOCTL_IOPORT_GETIRQ('D'), 4),
			* i_latch = avr_io_getirq(avr, AVR_IOCTL_IOPORT_GETIRQ('D'), 7);
	avr_connect_irq(i_mosi, shifter.irq + IRQ_HC595_SPI_BYTE_IN);
	avr_connect_irq(i_reset, shifter.irq + IRQ_HC595_IN_RESET);
	avr_connect_irq(i_latch, shifter.irq + IRQ_HC595_IN_LATCH);

	avr_irq_t * i_pwm = avr_io_getirq(avr, AVR_IOCTL_TIMER_GETIRQ('0'), TIMER_IRQ_OUT_PWM0);
	avr_irq_register_notify(
		i_pwm,
		pwm_changed_hook, 
		NULL);	
	avr_irq_register_notify(
		shifter.irq + IRQ_HC595_OUT,
		hc595_changed_hook, 
		NULL);

	// even if not setup at startup, activate gdb if crashing
	avr->gdb_port = 1234;
	if (0) {
		//avr->state = cpu_Stopped;
		avr_gdb_init(avr);
	}

	/*
	 *	VCD file initialization
	 *	
	 *	This will allow you to create a "wave" file and display it in gtkwave
	 *	Pressing "r" and "s" during the demo will start and stop recording
	 *	the pin changes
	 */
	avr_vcd_init(avr, "gtkwave_output.vcd", &vcd_file, 10000 /* usec */);

	avr_vcd_add_signal(&vcd_file, 
		avr_get_interrupt_irq(avr, 7), 1 /* bit */ ,
		"TIMER2_COMPA" );
	avr_vcd_add_signal(&vcd_file, 
		avr_get_interrupt_irq(avr, 17), 1 /* bit */ ,
		"SPI_INT" );
	avr_vcd_add_signal(&vcd_file, 
		i_mosi, 8 /* bits */ ,
		"MOSI" );

	avr_vcd_add_signal(&vcd_file, 
		i_reset, 1 /* bit */ ,
		"595_RESET" );
	avr_vcd_add_signal(&vcd_file, 
		i_latch, 1 /* bit */ ,
		"595_LATCH" );
	avr_vcd_add_signal(&vcd_file, 
		button[B_START].irq + IRQ_BUTTON_OUT, 1 /* bits */ ,
		"start" );
	avr_vcd_add_signal(&vcd_file, 
		button[B_STOP].irq + IRQ_BUTTON_OUT, 1 /* bits */ ,
		"stop" );
	avr_vcd_add_signal(&vcd_file, 
		button[B_RESET].irq + IRQ_BUTTON_OUT, 1 /* bits */ ,
		"reset" );

	avr_vcd_add_signal(&vcd_file, 
		shifter.irq + IRQ_HC595_OUT, 32 /* bits */ ,
		"HC595" );
	avr_vcd_add_signal(&vcd_file, 
		i_pwm, 8 /* bits */ ,
		"PWM" );

	// 'raise' it, it's a "pullup"
	avr_raise_irq(button[B_START].irq + IRQ_BUTTON_OUT, 1);
	avr_raise_irq(button[B_STOP].irq + IRQ_BUTTON_OUT, 1);
	avr_raise_irq(button[B_RESET].irq + IRQ_BUTTON_OUT, 1);

	printf( "Demo : This is a real world firmware, a 'stopwatch'\n"
			"   timer that can count up to 99 days. It features a PWM control of the\n"
			"   brightness, blinks the dots, displays the number of days spent and so on.\n\n"
			"   Press '0' to press the 'start' button\n"
			"   Press '1' to press the 'stop' button\n"
			"   Press '2' to press the 'reset' button\n"
			"   Press 'q' to quit\n\n"
			"   Press 'r' to start recording a 'wave' file - with a LOT of data\n"
			"   Press 's' to stop recording\n"
			"  + Make sure to watch the brightness dim once you stop the timer\n\n"
			);

	/*
	 * OpenGL init, can be ignored
	 */
	glutInit(&argc, argv);		/* initialize GLUT system */


	int w = 22, h = 8;
	
	glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
	glutInitWindowSize(w * pixsize, h * pixsize);		/* width=400pixels height=500pixels */
	window = glutCreateWindow("Press 0, 1, 2 or q");	/* create window */

	// Set up projection matrix
	glMatrixMode(GL_PROJECTION); // Select projection matrix
	glLoadIdentity(); // Start with an identity matrix
	glOrtho(0, w * pixsize, 0, h * pixsize, 0, 10);
	glScalef(1,-1,1);
	glTranslatef(0, -1 * h * pixsize, 0);

	glutDisplayFunc(displayCB);		/* set window's display callback */
	glutKeyboardFunc(keyCB);		/* set window's key callback */
	glutTimerFunc(1000 / 24, timerCB, 0);

	// the AVR run on it's own thread. it even allows for debugging!
	pthread_t run;
	pthread_create(&run, NULL, avr_run_thread, NULL);

	glutMainLoop();
}
Esempio n. 14
0
main(int argc, char *argv[])
{
    GLuint *tex;
    int texwid, texht, texcomps;

    GLUquadricObj *quadric;

    glutInitWindowSize(winWidth, winHeight);
    glutInit(&argc, argv);
    if(argc > 1)
    {
        char *args = argv[1];
        int done = FALSE;
        while(!done)
        {
            switch(*args)
            {
            case 's': /* single buffer */
                printf("Single Buffered\n");
                dblbuf = FALSE;
                break;
            case '-': /* do nothing */
                break;
            case 0:
                done = TRUE;
                break;
            }
            args++;
        }
    }
    if(dblbuf)
        glutInitDisplayMode(GLUT_RGBA|GLUT_DEPTH|GLUT_DOUBLE);
    else
        glutInitDisplayMode(GLUT_RGBA|GLUT_DEPTH);
    (void)glutCreateWindow("example program");
    glutDisplayFunc(redraw_original);
    glutReshapeFunc(reshape);
    glutMouseFunc(mouse);
    glutMotionFunc(motion);
    glutKeyboardFunc(key);

    /* draw a perspective scene */
    glMatrixMode(GL_PROJECTION);
    glFrustum(-100., 100., -100., 100., 300., 600.);
    glMatrixMode(GL_MODELVIEW);
    /* look at scene from (0, 0, 450) */
    gluLookAt(0., 0., 450., 0., 0., 0., 0., 1., 0.);

    /* turn on features */
    glEnable(GL_DEPTH_TEST);

    glEnable(GL_TEXTURE_2D);
    glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT0);

    glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
    glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);

    glMateriali(GL_FRONT, GL_SHININESS, 128); /* cosine power */

    /* remove back faces to speed things up */
    glCullFace(GL_BACK);
    glBlendFunc(GL_ONE, GL_ONE);

    lightchanged[UPDATE_TEX] = GL_TRUE;
    lightchanged[UPDATE_OGL] = GL_TRUE;

    /* load pattern for current 2d texture */

    tex = read_texture("../data/wood.rgb", &texwid, &texht, &texcomps);

    gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, texwid, texht, GL_RGBA,
                      GL_UNSIGNED_BYTE, tex);
    free(tex);
    CHECK_ERROR("end of main");

    lighttex = (GLfloat *)malloc(texdim * texdim * sizeof(GL_FLOAT) * 3);



    /* XXX TODO use display list to avoid retesselating */
    glNewList(1, GL_COMPILE);
    glutSolidSphere((GLdouble)texdim/2., 50, 50);
    glEndList();


    glNewList(2, GL_COMPILE);
    glutSolidTeapot(70.);
    glEndList();

    quadric = gluNewQuadric();
    gluQuadricTexture(quadric, GL_TRUE);

    glNewList(3, GL_COMPILE);
    gluSphere(quadric, 70., 20, 20);
    glEndList();

    gluDeleteQuadric(quadric);
    maxobject = 3;

    glutMainLoop();

    return 0;
}
Esempio n. 15
0
int main (int argc, char **argv)
{

/* **************************************************************************************************************************** */

 	/* Pointeurs vers l'application */
	glutInit(&argc, argv);         

  	/*  Activation des buffers :   
     	Double buffer 
     	RGBA color
     	Depth buffer */               
	glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH); 

  	/* Création de la fenêtre */
	glutInitWindowSize(1024, 768);

	/* Positionnement de la fenêtre */
	glutInitWindowPosition(100, 100);

	/* Ouverture de la fenêtre */  
	glutCreateWindow("TD_Animation_3D");

	/* Spécification de la fontion de dessin */
	glutDisplayFunc(display);

  	/* Spécification de la fontion de redimensionnement */
	glutReshapeFunc(reshape);

  	/* Spécification des fontions de gestion du clavier */
	glutKeyboardFunc(keyboardDown);
	glutKeyboardUpFunc(keyboardUp);
	glutSpecialFunc(keyboardSpecDown);
	glutSpecialUpFunc(keyboardSpecUp);

 	/* Spécification des fontions de gestion de la souris */
	glutMouseFunc(mouse);
	glutMotionFunc(motion);

 	/* Spécification de la fonction de mise-à-jour */
	glutIdleFunc(timeTick);

/* **************************************************************************************************************************** */

	/* Affichage des fonctions clavier */
	HelpMessage();

/* **************************************************************************************************************************** */

	/* Intitialisation des paramètres de l'affichage et de la fenêtre */
	GLInit();

	/* Intitialisation des paramètres du squelette */ 
	SkeletInit();

	/* Intitialisation de la scène cinématique */
	IKInit();

/* **************************************************************************************************************************** */

  	/* Lancement de la boucle OpenGL */  
	glutMainLoop();

/* **************************************************************************************************************************** */

	return 0;

/* **************************************************************************************************************************** */
}
void main(int argc, char ** argv)
{
	int argc_ = 1;
	char *argv_[1] = {(char *)"something"};
	//glutInit(&argc_, argv_);          // initialize the toolkit
	//GLuint glutwindow = glutCreateWindow("something"); // open the screen window
	if(!glfwInit()) {
		printf("glfwinit fail");
		return ;
	}
	CheckGlErrors("glfwInit");
	GLFWwindow *glfwwindow = glfwCreateWindow(screenWidth, screenHeight, "example", NULL, NULL);
	CheckGlErrors("glfwCreateWindow");
	if(glfwwindow == NULL) {
		printf("glfwCreateWindow fail");
		glfwTerminate();
		return ;
	}
	glfwHideWindow(glfwwindow);
	CheckGlErrors("glfwHideWindow");
	glfwMakeContextCurrent(glfwwindow);
	CheckGlErrors("glfwMakeContextCurrent");
	
#ifndef FBO
	glutDisplayFunc(renderFBO);     // register the redraw function
#endif
	GLenum err = glewInit();
	if(GLEW_OK != err) {
		printf("glewInit Error: %s\n", glewGetErrorString(err));
		getchar();
		return ;
	}
	myInit(); 
	glslProcess();
#ifdef FBO
	for(int i=1;i<3;++i) {
		char filename[30];
		sprintf(filename, "%d.png", i+1);
		img = cv::imread(filename);
		if(img.empty())
			return ;
		//cv::cvtColor(img, img, CV_BGR2RGB);
		renderFBO();
		readBack();
		//cv::cvtColor(img1, img1, CV_BGR2RGB);
		printf("output img, width is %d, height is %d, %d\n", img1.cols, img1.rows, img1.channels());
		
		sprintf(filename, "D:\\%d.bmp", 20+i);
		cv::imwrite(filename, img1);
	}
	//getchar();
#else
	glutMainLoop(); 		     // go into a perpetual loop
#endif
	glDeleteFramebuffers(1, &fb);
	glDeleteTextures(2, texId);
	//glutDestroyWindow(glutwindow);
	glfwTerminate();

	getchar();
}
Esempio n. 17
0
void	keyboard(unsigned char ch, int x, int y)
{
	x = ch; y = ch;
	switch (ch)
	{
		case 27:             /* escape */
			running = !running;
			break;
		case 'w':
		case 'W':
			glTranslatef(0,-10, 0);
			glutPostRedisplay();
			break;
		case 's':
		case 'S':
			glTranslatef(0, 10, 0);
			glutPostRedisplay();
			break;
		case 'a':
		case 'A':
			glTranslatef(10, 0,0);
			glutPostRedisplay();
			break;
		case 'd':
		case 'D':
			glTranslatef(-10, 0,0);
			glutPostRedisplay();
			break;
		case 'Q':
		case 'q':
			conf_rotate = (conf_rotate) ? false : true;
			glutPostRedisplay();
			break;
		case 'X':
		case 'x':
			conf_skip_frames = !conf_skip_frames;
			std::cout << "conf_skip_frames = " << conf_skip_frames << std::endl;
			break;
		case '=':
			conf_zoom *= 0.9f;
			std::cout << "conf_zoom = " << conf_zoom << std::endl;
			break ;
		case '-':
			conf_zoom /= 0.9f;
			std::cout << "conf_zoom = " << conf_zoom << std::endl;
			break ;
		case 'r':
		case 'R':
			target_rotate += 45.0f * 2.0f;
			break;
		case 'P':
		case 'p':
			conf_pause = !conf_pause;
			break;
		case ' ':
			pour_water = !pour_water;
			break;
		case '1':
			glutReshapeFunc(reshape_vue_haute);
			glutDisplayFunc(display_vue_haute);
			reshape_vue_haute(glutGet(GLUT_WINDOW_WIDTH), glutGet(GLUT_WINDOW_HEIGHT));
			glutPostRedisplay();
			break;
		case '2':
			glutReshapeFunc(reshape_iso);
			glutDisplayFunc(display_iso);
			reshape_iso(glutGet(GLUT_WINDOW_WIDTH), glutGet(GLUT_WINDOW_HEIGHT));
			glutPostRedisplay();
			break;
		case '3':
			glutReshapeFunc(reshape);
			glutDisplayFunc(display);
			reshape(glutGet(GLUT_WINDOW_WIDTH), glutGet(GLUT_WINDOW_HEIGHT));
			glutPostRedisplay();
			break;
        case 'v':
        case 'V':
            vidange = !vidange;
            break;
		default:
			break;
	}
}
Esempio n. 18
0
int main(int argc, char *argv[]) {
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH |
		GLUT_STENCIL);
	if((argc > 1) && (strcmpi(argv[1], "--helmet") == 0)) {
		/*left eye*/
		glutInitWindowPosition(0,0);
		glutInitWindowSize(640, 480);
		left_eye = glutCreateWindow("Escher World - Left Eye");

		glutSetWindow(left_eye);
		set_window_size(640, 480);
		glutDisplayFunc(displayleft);
		glutKeyboardFunc(keyfunc);
		glutMouseFunc(mouse_button);
		glutPassiveMotionFunc(passive_mouse_motion);
		glutMotionFunc(passive_mouse_motion);
		glutReshapeFunc(set_window_size);
/*		glutTimerFunc(10,child,1);*/

		/* right eye */
		glutInitWindowPosition(641,0);
		glutInitWindowSize(640, 480);
		right_eye = glutCreateWindow("Escher World - Right Eye");

		glutSetWindow(right_eye);
		set_window_size(640, 480);
		glutDisplayFunc(displayright);
		glutKeyboardFunc(keyfunc);
		glutMouseFunc(mouse_button);
		glutPassiveMotionFunc(passive_mouse_motion);
		glutMotionFunc(passive_mouse_motion);
		glutReshapeFunc(set_window_size);

		glutSetWindow(left_eye);
		create_menus();
		init();
		/* Initialize the scene */
		init_scene(FILENAME);

		glutSetWindow(right_eye);
		create_menus();
		create_menus();
		init();
		/* Initialize the scene */
		init_scene(FILENAME);

#ifdef USE_HELMET
/*		main_helmet();
		signal(SIGUSR1, cleanup);
*/		birdinit();
/*		glutTimerFunc(10,child,1);*/
#endif

	} else {
		glutInitWindowPosition(64,64);

		glutInitWindowSize(768, 832);
		glut_window = glutCreateWindow("Escher World");

		glutSetWindow(glut_window);
		set_window_size(768, 832);
		helmet = !helmet;
		glutDisplayFunc(displaymid);
		glutKeyboardFunc(keyfunc);
		glutMouseFunc(mouse_button);
		glutPassiveMotionFunc(passive_mouse_motion);
		glutMotionFunc(passive_mouse_motion);
		glutReshapeFunc(set_window_size);
		create_menus();
		init();
		/* Initialize the scene */
		init_scene(FILENAME);
	}

	glutMainLoop();

	return 0;
}
Esempio n. 19
0
int main(int argc, char** argv)
{
	//The order of initialisation may be wrong. TODO check.

	//For OGL3.2
	glutInitContextVersion (3, 2);
	glutInitContextProfile(GLUT_CORE_PROFILE);
	//Usual glut code
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
	#ifdef DEBUG
	//TODO: Check if freeglut is at least at version 2.60 (?)
	std::cout<< "Glut version:" << glutGet(GLUT_VERSION) << std::endl;
	#endif
	glutInitWindowSize(250, 250);
	glutInitWindowPosition(100, 100);
	glutCreateWindow("Hello");
	init();
	
	GLfloat square[] = {0.25, 0.25, 0.0, 0.75, 0.25, 0.0, 0.75, 0.75, 0.0,\
				 0.25, 0.75, 0.0};
	//Indices assume GL_TRIANGLES  TODO-- check!
	GLuint square_indices[] = {0, 3, 2, 2, 1, 0};
	//Using VBO's and VAO's
	
	//Generate the name for a Vertex Array
	GLuint vao_name;
	glGenVertexArrays(1, &vao_name);
	
	//Bind this vao as the currently used object
	glBindVertexArray(vao_name);
	
	//Create the names two vertex buffer object
	GLuint vbo_names[2];
	glGenBuffers(2, vbo_names);

	//Bind the first vbo and indicate that it contains vertex data
	glBindBuffer(GL_ARRAY_BUFFER, vbo_names[0]);

	/* TODO: See if there is a better spec for vbo access 
	 * than GL_STATIC_DRAW
	 */
	
	//Copy the vertex data from the square array to this buffer 
	glBufferData(GL_ARRAY_BUFFER, sizeof(GL_FLOAT) * 12, square,\
			 GL_STATIC_DRAW);
	
	/* Specify that the vertex data is going into vertex attribute zero.
	 * in the vertex attribute array. Enable the corresponding attribute 
	 * in the array.
	 */
	glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
	glEnableVertexAttribArray(0);

	//Bind the second vbo as being an active buffer
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo_names[1]);
	
	//Copy the index data to the second vbo
	glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(GLuint) * 6, \
			 square_indices, GL_STATIC_DRAW);
	
	/* Specify that the index data is going into vertex attribute one
	 * n the vertex attribute array. Enable the corresponding attribute 
	 * in the array.
	 */
	glVertexAttribPointer(1, 1, GL_INT, GL_FALSE, 0, 0);
	glEnableVertexAttribArray(1);

	//Shaders!	
	GLchar *vertex_source, *fragment_source;
	GLuint vertex_shader, fragment_shader;
	GLuint shader_program;

	//Obtain the source for the shader programs.
	vertex_source = file_to_char_pointer("first_vertex_shader.glsl");
	fragment_source = file_to_char_pointer("first_fragment_shader.glsl");

	if((vertex_source != NULL) && (fragment_source != NULL))
	{
	
		//Obtain the name for the shader program.
		shader_program = glCreateProgram();
	
		//Obtain the names of the shaders
		vertex_shader = glCreateShader(GL_VERTEX_SHADER);
		fragment_shader = glCreateShader(GL_FRAGMENT_SHADER);

		//Set the source code of the shaders.
		//Fix this unsafe casting.
		glShaderSource(vertex_shader, 1, (const GLchar**)&vertex_source, NULL); 
							//Strings \0 terminated
		glShaderSource(fragment_shader, 1, (const GLchar**) &fragment_source, NULL);
	
		//Compile the shaders
		glCompileShader(vertex_shader);
		glCompileShader(fragment_shader);
	
		//Attach the shaders to the program
		/* TODO: Figure out these lines carefully. Is the order of attaching
		 * shaders important?
		 */
		glAttachShader(shader_program, vertex_shader);
		glAttachShader(shader_program, fragment_shader);
	
		//Link the program
		glLinkProgram(shader_program);

		//Bind parameters to the shader.
		glBindAttribLocation(shader_program, 0, "in_position");	

		//Set this program as the active shader program
		glUseProgram(shader_program);
		
	}

	glutDisplayFunc(display);
	glutMainLoop();
	
	//Do cleanup.
	/*
	 * CAUTION: Assumes that all the things that are cleaned up exist in the first place. This may not be true.
	*/
	glUseProgram(0);
	glDetachShader(shader_program, vertex_shader);
	glDetachShader(shader_program, fragment_shader);
	glDeleteProgram(shader_program);
	glDeleteShader(vertex_shader);
	glDeleteShader(fragment_shader);
	glDisableVertexAttribArray(0);
	glDisableVertexAttribArray(1);
	glDeleteBuffers(2, vbo_names);
	glDeleteVertexArrays(1, &vao_name);

	delete vertex_source;
	delete fragment_source;	
	
	return 0;
}
Esempio n. 20
0
// Initialize GLUT & OpenSG and set up the scene
int main (int argc, char **argv)
{
    int i;
    float ca=-1,cb=-1,cc=-1;
    // OSG init
    osgInit(argc,argv);
    char *filename=NULL;

    // GLUT init
    glutInit(&argc, argv);
    glutInitDisplayMode( GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
    int winid = glutCreateWindow("OpenSG");
    glutReshapeFunc(reshape);
    glutDisplayFunc(display);
    glutMouseFunc(mouse);
    glutMotionFunc(motion);
    glutKeyboardFunc(key);

    // the connection between GLUT and OpenSG
    GLUTWindowPtr gwin= GLUTWindow::create();
    gwin->setId(winid);
    gwin->init();

    // create the scene
    float x,y,z;
    scene = Node::create();
    beginEditCP(scene);
    scene->setCore(Group::create());
    endEditCP(scene);

    NodePtr file;

    for(i=1;i<argc;++i)
    {
        if(argv[i][0] =='-')
        {
            switch(argv[i][1])
            {
                case 'd':
                    useFaceDistribution=true;
                    break;
                case 'v':
                    viewVolume=true;
                    break;
                case 's':
                    serverCount=atoi(&argv[i][2]);
                    break;
                case 'l':
                    loop=atoi(&argv[i][2]);
                    break;
                case 'S':
                    simulateRendering=true;
                    break;
            }
        }
        else
        {
            if(argv[i][0] >='0' &&
               argv[i][0] <='9')
            {
                if(ca==-1)
                    ca=atoi(argv[i]);
                else
                    if(cb==-1)
                        cb=atoi(argv[i]);
                    else
                        if(cc==-1)
                            cc=atoi(argv[i]);
            }
            else
            {
                filename=argv[1];
            }
        }
    }
    if(ca == -1 && filename)
    {
        file = OSG::SceneFileHandler::the().read(filename);
        beginEditCP(scene);
        scene->addChild(file);
        endEditCP(scene);
    }
    else
    {
        if(ca==-1)
            ca=4;
        if(cb==-1)
            cb=ca;
        if(cc==-1)
            cc=cb;
        if(file == NullFC)
        {
            GeometryPtr geo=makeBoxGeo(.6,.6,.6,20,20,20);
            beginEditCP(geo);
            SimpleMaterialPtr mat=SimpleMaterial::create();
            beginEditCP(mat);
            mat->setAmbient(Color3f(.4,.4,.4));
            mat->setSpecular(Color3f(0,0,0));
            mat->setDiffuse(Color3f(1,1,1));
            endEditCP(mat);
            geo->setMaterial(mat);
            endEditCP(geo);
            NodePtr node;
            NodePtr geoNode;
            TransformPtr trans;
            for(x=-ca/2 ; x<ca/2 ; x++)
                for(y=-cb/2 ; y<cb/2 ; y++)
                    for(z=-cc/2 ; z<cc/2 ; z++)
                    {
                        trans=Transform::create();
                        node=Node::create();
                        geoNode=Node::create();
                        
                        beginEditCP(geoNode);
                        beginEditCP(trans);
                        beginEditCP(node);
                        
                        node->setCore(trans);
                        trans->getMatrix().setTranslate(x,y,z);
                        if(!filename)
                        {
                            geoNode=Node::create();
                            geoNode->setCore(geo);
                        }
                        else
                        {
                            geoNode = OSG::SceneFileHandler::the().read(filename);
                        }
                        node->addChild( geoNode );
                        beginEditCP(scene);
                        scene->addChild(node);
                        
                        endEditCP(geoNode);
                        endEditCP(scene);
                        endEditCP(trans);
                        endEditCP(node);
                    }
        }
    }
    // create the SimpleSceneManager helper
    mgr = new MySceneManager;

    mgr->setWindow( gwin );
    mgr->setRoot( scene );

    mgr->showAll();

    // GLUT main loop
    if(loop)
        glutIdleFunc(display);
//    glutReshapeWindow(720,576);
    glutReshapeWindow(1152,864);
    glutMainLoop();

    return 0;
}
Esempio n. 21
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;
	    if (strstr(argv[i], "-f"))
		full_screen = 1;
	}
    } else {			/* user only entered program name, help them */

	printf("Usage: %s [-s] [-f] <obj filename>\n", argv[0]);
	exit(0);
    }


    glutInit(&argc, argv);

	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);

    glutInitWindowSize(1024, 768);	/*  Window Size If We Start In Windowed Mode */
    glutCreateWindow("Wavefront Obj File Viewer");
    if (full_screen)
	glutFullScreen();


    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);
    glutIdleFunc(NULL);

    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);

    if (lighting)
	glEnable(GL_LIGHTING);
    if (lighting)
	glEnable(GL_LIGHT0);
    glDepthFunc(GL_LESS);
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_NORMALIZE);
    glEnable(GL_TEXTURE_2D);

	glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);

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

    return 0;
}
Esempio n. 22
0
int main (int argc, char** argv) {
	// Standard stuff...
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_RGBA|GLUT_DOUBLE|GLUT_DEPTH);
	glutInitWindowSize(800, 600);
	glutCreateWindow("Index Buffers");
	glutReshapeFunc(changeViewport);
	
	glewInit();

	initMatrices(); // New <========================================
	vao=gen_particles();

/*#ifdef USING_INDEX_BUFFER


	
#endif*/

	// Make a shader
	char* vertexShaderSourceCode = readFile("vertexShader1.vsh");
	char* fragmentShaderSourceCode = readFile("fragmentShader1.fsh");
	GLuint vertShaderID = makeVertexShader(vertexShaderSourceCode);
	GLuint fragShaderID = makeFragmentShader(fragmentShaderSourceCode);
	shaderProgramID = makeShaderProgram(vertShaderID, fragShaderID);

	/*/ / Create the "remember all"
	glGenVertexArrays(1, &vao);
	glBindVertexArray(vao);
	
	glGenBuffers(1, &vbo);
	glBindBuffer(GL_ARRAY_BUFFER, vbo);
	// Create the buffer, but don't load anything yet
	//glBufferData(GL_ARRAY_BUFFER, 7*NUM_VERTICES*sizeof(GLfloat), NULL, GL_STATIC_DRAW);
	glBufferData(GL_ARRAY_BUFFER, 6*NUM_VERTICES*sizeof(GLfloat), NULL, GL_STATIC_DRAW);
	
	// Load the vertex points
	glBufferSubData(GL_ARRAY_BUFFER, 0, 3*NUM_VERTICES*sizeof(GLfloat), vertices);
	// Load the colors right after that
	//glBufferSubData(GL_ARRAY_BUFFER, 3*NUM_VERTICES*sizeof(GLfloat),4*NUM_VERTICES*sizeof(GLfloat), colors);
	glBufferSubData(GL_ARRAY_BUFFER, 3*NUM_VERTICES*sizeof(GLfloat),3*NUM_VERTICES*sizeof(GLfloat), normals);*/
	
	
/*#ifdef USING_INDEX_BUFFER
	glGenBuffers(1, &indexBufferID);
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBufferID);
	glBufferData(GL_ELEMENT_ARRAY_BUFFER, NUM_INDICES*sizeof(GLuint), indices, GL_STATIC_DRAW);
#endif*/
	

	// Find the position of the variables in the shader
	//ositionID = glGetAttribLocation(shaderProgramID, "v_i");
	//colorID = glGetAttribLocation(shaderProgramID, "elapsed_system_time");
	
	// ============ New! glUniformLocation is how you pull IDs for uniform variables===============
	perspectiveMatrixID = glGetUniformLocation(shaderProgramID, "P");
	viewMatrixID = glGetUniformLocation(shaderProgramID, "V");
	emitterID=glGetUniformLocation(shaderProgramID, "emitter_pos_wor");
	timeID=glGetUniformLocation(shaderProgramID, "elapsed_system_time");
	
	//=============================================================================================

	/*glVertexAttribPointer(positionID, 3, GL_FLOAT, GL_FALSE, 0, 0);
	//glVertexAttribPointer(colorID, 4, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(sizeof(vertices)));
	glVertexAttribPointer(colorID, 3, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(sizeof(vertices)));
	printf ("BUFFER_OFFSET is: %d\n", sizeof(vertices));*/

	glUseProgram(shaderProgramID);
	//glEnableVertexAttribArray(positionID);
	//glEnableVertexAttribArray(colorID);
	//glEnable(GL_DEPTH_TEST);
    //glClearColor( 0.0, 0.0, 0.0, 0.2 );

	//current_seconds=Timer();
	glutDisplayFunc(render);

	glutKeyboardFunc( keyboard );
	glutMainLoop();
	
	return 0;
}
Esempio n. 23
0
int main(int argc, char *argv[]) {
	double			pos;
    VideoState      *is;


    if(argc < 2) {
        fprintf(stderr, "Usage: test <file>\n");
        exit(1);
    }

#ifdef __MINGW32__
	ptw32_processInitialize();
	//ptw32_processTerminate();
#endif

	//XInitThreads();

    is = (VideoState *)av_mallocz(sizeof(VideoState));

	avcodec_register_all();
	//avdevice_register_all();
	avfilter_register_all();
    av_register_all();
	avformat_network_init();

	if (USE_EVENT_MULTI_THREAD)
	{
		if ( SDLMOD_StartEventLoop(SDLMOD_INIT_EVENTTHREAD) < 0 ) {
			fprintf(stderr, "Could not start SDLMOD event loop (multi thread)\n");
			exit(1);
		}
	}
	else
	{
		if ( SDLMOD_StartEventLoop(0) < 0 ) {
			fprintf(stderr, "Could not start SDLMOD event loop (main thread)\n");
			exit(1);
		}
	}
	if (SDLMOD_TimerInit() != 0)
	{
		fprintf(stderr, "SDLMOD_TimerInit failed\n");
		exit(1);
	}

	g_video_width = 640;
	g_video_height = 480;
	g_video_resized = 0;

	//screen = SDL_SetVideoMode(g_video_width, g_video_height, SDL_VIDEO_MODE_BPP, SDL_VIDEO_MODE_FLAGS);
	screen = SDLMOD_CreateRGBSurface(0,
		g_video_width, g_video_height, SDL_VIDEO_MODE_BPP,
		Rmask, Gmask, Bmask, Amask
		);
	if(!screen) {
		fprintf(stderr, "SDL: could not set video mode - exiting\n");
		exit(1);
	}

    screen_mutex = (pthread_mutex_t *)malloc(sizeof(pthread_mutex_t));
    pthread_mutex_init(screen_mutex, NULL);

    av_strlcpy(is->filename, argv[1], sizeof(is->filename));

	is->pictq_mutex = (pthread_mutex_t *)malloc(sizeof(pthread_mutex_t));
    pthread_mutex_init(is->pictq_mutex, NULL);
    is->pictq_cond = (pthread_cond_t *)malloc(sizeof(pthread_cond_t));
    pthread_cond_init(is->pictq_cond, NULL);
    
	schedule_refresh(is, 40);

	is->av_sync_type = AV_SYNC_VIDEO_MASTER;

    {
		int err;
		is->parse_tid = (pthread_t *)malloc(sizeof(pthread_t));
		err = pthread_create(is->parse_tid, NULL, decodeThread, is);
		if (err!=0)
		{
			free(is->parse_tid);
			printf("can't create thread: %s\n", strerror(err));
			exit(0);
		}
	}
    if (!is->parse_tid) {
        av_free(is);
        return -1;
    }

	av_init_packet(&flush_pkt);
	flush_pkt.data = (uint8_t*)"FLUSH";

#if USE_EVENT_LOOP_MT
	{
		pthread_t pid;
		pthread_create(&pid, NULL, event_loop, is);
		if (0)
		{
			pthread_join(pid, NULL);
		}
		else
		{
#if USE_GL
			glutInit(&argc, argv);
			glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGBA|GLUT_DEPTH);
			glutInitWindowSize(g_video_width, g_video_height);
			glutInitWindowPosition(0, 0);
			
			win = glutCreateWindow(TITLE);
			createMenu();

			glutDisplayFunc(display);
			glutReshapeFunc(reshape);
			glutMouseFunc(mouse);
			glutMotionFunc(motion);
			glutIdleFunc(idle);

			if (initEnvironment())
			{
				glutMainLoop();
			}
#else
			printf(">>>>>>Please input command (exit, quit, save):<<<<<<\n");
			char string[256];
			char* ret;
			while(1)
			{
				ret = gets(string);
				if (strcmp(string, "exit") == 0 || 
				    strcmp(string, "quit") == 0 ||
				    strcmp(string, "e") == 0 ||
				    strcmp(string, "q") == 0
				    )
				{
					break;
				}
				else if (strcmp(string, "save") == 0 ||
					strcmp(string, "s") == 0
				    )
				{
					save_bmp();
					printf("save_bmp() finish.\n");
				}
				else
				{
					printf("Please input command (exit, quit, save):\n");
				}
			}
#endif
		}
	}
#else
	event_loop(is);
#endif

    return 0;
}
Esempio n. 24
0
int main( int argc, char **argv )
{
	// Parse the arguments
	if (argc < 2) {
		printf("Missing arguments ... use:\n");
		printf("./raycast step_max <options>\n");
		return -1;
	}
	
	/*
	if (strcmp(argv[1], "-u") == 0) {  // user defined scene
		set_up_user_scene();
	} else { // default scene
		set_up_default_scene();
	}
	*/

	step_max = atoi(argv[1]); // maximum level of recursions

	// Optional arguments
	for(int i = 2; i < argc; i++)
	{
		if (strcmp(argv[i], "+s") == 0)	shadow_on = 1;
		if (strcmp(argv[i], "+l") == 0) reflect_on = 1;
		//if (strcmp(argv[i], "+c") == 0) chessboard_on = 1;
		if (strcmp(argv[i], "+r") == 0) refract_on = 1;
		if (strcmp(argv[i], "+f") == 0) difref_on = 1;
		if (strcmp(argv[i], "+p") == 0) antiAlias_on = 1;
		if (strcmp(argv[i], "+t") == 0) triangle_on = 1;
	}

	set_up_global_variable();

	if(chessboard_on = 1)
		set_up_chessboard();

	if(triangle_on)
		set_up_triangles();


	//printf("object Count : %d\n",objectCount);

	set_up_chessPiece();



	//printObjects();

	// ray trace the scene now
	// we have used so many global variables and this function is
	// happy to carry no parameters	
	printf("Rendering scene using my fantastic ray tracer ...\n");
	ray_trace();
	printf("After ray trace\n");

	// we want to make sure that intensity values are normalized
	histogram_normalization();

	// Show the result in glut via texture mapping
	glutInit( &argc, argv );
	glutInitDisplayMode( GLUT_RGBA | GLUT_DOUBLE );
	glutInitWindowSize( WIN_WIDTH, WIN_HEIGHT );
	glutCreateWindow( "Ray tracing" );
	glewInit();

	#ifndef __NO_DISPLAY__
	init();
	#endif
	printf("After init\n");

	glutDisplayFunc( display );
	glutKeyboardFunc( keyboard );
	glutMainLoop();

	return 0;
}
Esempio n. 25
0
int
main(int argc, char** argv)
{
  int buffering = GLUT_DOUBLE;
  struct dirent* direntp;
  DIR* dirp;
  int models;
    
  glutInitWindowSize(512, 512);
  glutInit(&argc, argv);
    
  while (--argc) {
    if (strcmp(argv[argc], "-sb") == 0)
      buffering = GLUT_SINGLE;
    else
      model_file = argv[argc];
  }
    
  if (!model_file) {
    model_file = "data/torus.obj";
  }
    
  glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | buffering);
  glutCreateWindow("Loop Subdivision");
    
  glutReshapeFunc(reshape);
  glutDisplayFunc(display);
  glutKeyboardFunc(keyboard);
  glutMouseFunc(mouse);
  glutMotionFunc(motion);
    
  models = glutCreateMenu(menu);
  dirp = opendir(DATA_DIR);
  if (!dirp) {
    fprintf(stderr, "%s: can't open data directory.\n", argv[0]);
  } else {
    while ((direntp = readdir(dirp)) != NULL) {
      if (strstr(direntp->d_name, ".obj")) {
	entries++;
	glutAddMenuEntry(direntp->d_name, -entries);
      }
    }
    closedir(dirp);
  }
    
  glutCreateMenu(menu);
  glutAddMenuEntry("Smooth", 0);
  glutAddMenuEntry("", 0);
  glutAddSubMenu("Models", models);
  glutAddMenuEntry("", 0);
  glutAddMenuEntry("[w]   Toggle wireframe/filled", 'w');
  glutAddMenuEntry("[c]   Toggle culling on/off", 'c');
  glutAddMenuEntry("[n]   Toggle face/smooth normals", 'n');
  glutAddMenuEntry("[b]   Toggle bounding box on/off", 'b');
  glutAddMenuEntry("[p]   Toggle frame rate on/off", 'p');
  glutAddMenuEntry("[t]   Toggle model statistics", 't');
  glutAddMenuEntry("[m]   Toggle color/material/none mode", 'm');
  glutAddMenuEntry("[r]   Reverse polygon winding", 'r');
  glutAddMenuEntry("[s]   Scale model smaller", 's');
  glutAddMenuEntry("[S]   Scale model larger", 'S');
  glutAddMenuEntry("[o]   Weld redundant vertices", 'o');
  glutAddMenuEntry("[+]   Increase smoothing angle", '+');
  glutAddMenuEntry("[-]   Decrease smoothing angle", '-');
  glutAddMenuEntry("[W]   Write model to file (out.obj)", 'W');
  glutAddMenuEntry("", 0);
  glutAddMenuEntry("[Esc] Quit", 27);
  glutAttachMenu(GLUT_RIGHT_BUTTON);
    
    
  init();
  glutMainLoop();
  return 0;
}
Esempio n. 26
0
int
main(int argc, char **argv)
{
    int i;
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH | GLUT_MULTISAMPLE);

    for (i=1; i<argc; i++) {
        if(!strcmp("-noms", argv[i])) {
            glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
            printf("forcing no multisampling\n");
        } else if(!strcmp("-nomipmaps", argv[i])) {
            useMipmaps = 0;
        } else if(!strcmp("-nearest", argv[i])) {
            linearFiltering = 0;
        }
    }
    glutInitWindowPosition(0, 0);
    glutInitWindowSize(600,300);
    glutCreateWindow("sprite blast");
    glutReshapeFunc(reshape);
    glutDisplayFunc(redraw);
    glutMouseFunc(mouse);
    glutMotionFunc(mouseMotion);
    glutVisibilityFunc(visible);
    glutKeyboardFunc(key);
    glutCreateMenu(menu);
    glutAddMenuEntry("Reset time", 0);
    glutAddMenuEntry("Constant", 1);
    glutAddMenuEntry("Linear", 2);
    glutAddMenuEntry("Quadratic", 3);
    glutAddMenuEntry("Blend on", 4);
    glutAddMenuEntry("Blend off", 5);
    glutAddMenuEntry("Threshold 1", 6);
    glutAddMenuEntry("Threshold 10", 7);
    glutAddMenuEntry("Point smooth on", 8);
    glutAddMenuEntry("Point smooth off", 9);
    glutAddMenuEntry("Point size 4", 10);
    glutAddMenuEntry("Point size 8", 11);
    glutAddMenuEntry("Point size 16", 12);
    glutAddMenuEntry("Toggle spin", 13);
    glutAddMenuEntry("200 points ", 14);
    glutAddMenuEntry("500 points ", 15);
    glutAddMenuEntry("1000 points ", 16);
    glutAddMenuEntry("2000 points ", 17);
    glutAddMenuEntry("Quit", 666);
    glutAttachMenu(GLUT_RIGHT_BUTTON);

    glShadeModel(GL_FLAT);
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_POINT_SMOOTH);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glPointSize(16.0);
#ifdef GL_ARB_point_parameters
    glPointParameterfvARB(GL_POINT_DISTANCE_ATTENUATION_ARB, theQuad);
#endif

    makePointList();
    makeSprite();

    glutMainLoop();
    return 0;             /* ANSI C requires main to return int. */
}
Esempio n. 27
0
static void InitializeGlutCallbacks()
{
    glutDisplayFunc(RenderSceneCB);
}
int main(int argc, char *argv[])
{
	// inicjalizacja biblioteki GLUT
	glutInit(&argc, argv);

	// inicjalizacja bufora ramki
	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);

	// rozmiary głównego okna programu
	glutInitWindowSize(500, 500);

	// utworzenie głównego okna programu
	glutCreateWindow("Zadanie 2");

	// dołączenie funkcji generującej scenę 3D
	glutDisplayFunc(DisplayScene);

	// dołączenie funkcji wywoływanej przy zmianie rozmiaru okna
	glutReshapeFunc(Reshape);

	// dołączenie funkcji obsługi klawiatury
	glutKeyboardFunc(Keyboard);

	// utworzenie podmenu - Filtr pomniejszający
	int MenuMinFilter = glutCreateMenu(Menu);
	glutAddMenuEntry("GL_NEAREST_MIPMAP_NEAREST", GL_NEAREST_MIPMAP_NEAREST);
	glutAddMenuEntry("GL_NEAREST_MIPMAP_LINEAR", GL_NEAREST_MIPMAP_LINEAR);
	glutAddMenuEntry("GL_LINEAR_MIPMAP_NEAREST", GL_LINEAR_MIPMAP_NEAREST);
	glutAddMenuEntry("GL_LINEAR_MIPMAP_LINEAR", GL_LINEAR_MIPMAP_LINEAR);

	// utworzenie podmenu - Aspekt obrazu
	int MenuAspect = glutCreateMenu(Menu);
#ifdef WIN32

	glutAddMenuEntry("Aspekt obrazu - całe okno", FULL_WINDOW);
#else

	glutAddMenuEntry("Aspekt obrazu - cale okno", FULL_WINDOW);
#endif

	glutAddMenuEntry("Aspekt obrazu 1:1", ASPECT_1_1);

	// menu główne
	glutCreateMenu(Menu);

#ifdef WIN32

	glutAddSubMenu("Filtr pomniejszający", MenuMinFilter);
	glutAddSubMenu("Aspekt obrazu", MenuAspect);
	glutAddMenuEntry("Wyjście", EXIT);
#else

	glutAddSubMenu("Filtr pomniejszajacy", MenuMinFilter);
	glutAddSubMenu("Aspekt obrazu", MenuAspect);
	glutAddMenuEntry("Wyjscie", EXIT);
#endif

	// określenie przycisku myszki obsługującego menu podręczne
	glutAttachMenu(GLUT_RIGHT_BUTTON);

	// sprawdzenie i przygotowanie obsługi wybranych rozszerzeñ
	ExtensionSetup();

	// utworzenie list wyświetlania
	GenerateDisplayLists();

	// wprowadzenie programu do obsługi pętli komunikatów
	glutMainLoop();
	return 0;
}
Esempio n. 29
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);
    glutInitWindowPosition(50,50);
    glutInitWindowSize(width,height);
	windowId = glutCreateWindow("Ray Cast Volume Rendering");
	
	glewInit();

    // Set GLUT callback functions
	glutDisplayFunc(renderScene);
	//glutIdleFunc(updateScene);
	glutKeyboardFunc(keypress);

    // Setup OpenGL state & scene resources 
    init();

	//GLUI
    glui = GLUI_Master.create_glui( "Controls", 0, 865, 50); 

	movement_panel = new GLUI_Panel( glui, "Movement Parameters" );
    
	view_rot = new GLUI_Rotation( movement_panel, "Rotate", view_rotate );
	view_rot->set_spin( 1.0 );

	trans_z = new GLUI_Translation( movement_panel, "Zoom", GLUI_TRANSLATION_Z, &zoom );
	trans_z->set_speed( .05 );

	raycastPGM = new GLUI_Checkbox(glui, "Raycast /w XToon & Alpha Interpolation", &raycastEnable, RAYCAST, controlCB);
	xtoonPGM = new GLUI_Checkbox(glui, "Raycast XToon Shader", &xtoonEnable, XTOONPGM, controlCB);
	gradientPGM = new GLUI_Checkbox(glui, "Gradient", &gradientEnable, GRADIENT, controlCB);
	dvrPGM = new GLUI_Checkbox(glui, "DVR", &dvrEnable, DVR, controlCB);
	rin = new GLUI_Checkbox(glui, "Show Ray Start", &rayinToggle, RAYIN, controlCB);
	rout = new GLUI_Checkbox(glui, "Show Ray Stop", &rayoutToggle, RAYOUT, controlCB);

	column_01 = new GLUI_Column( glui );

	GUIRayCastRoll = new GLUI_Rollout( glui, "Ray Cast Parameters", false);

	raycaster_panel = new GLUI_Panel( GUIRayCastRoll, "" );
	jittering = new GLUI_Checkbox( raycaster_panel, "Stippling", &j, JITTER, controlCB );
	jittering->set_alignment( GLUI_ALIGN_RIGHT );

    GUIsamples = new GLUI_Spinner( raycaster_panel, "N Samples", &nSamples );
	GUIsamples->set_int_limits( 0, 255 );
    GUIsamples->set_alignment( GLUI_ALIGN_RIGHT );

    GUInoise = new GLUI_Spinner( raycaster_panel, "Noise Delta", &noiseDelta );
	GUInoise->set_float_limits( 1.0, 10.0 );
    GUInoise->set_alignment( GLUI_ALIGN_RIGHT );

    GUIstep = new GLUI_Spinner( raycaster_panel, "Step Length", &stepLength );
	GUIstep->set_float_limits( 0.01f, 1.0f );
    GUIstep->set_alignment( GLUI_ALIGN_RIGHT );

    GUIt = new GLUI_Spinner( raycaster_panel, "Threshold", &threshold );
	GUIt->set_float_limits( 0.01f, 1.0f );
    GUIt->set_alignment( GLUI_ALIGN_RIGHT );

    GUIgscale = new GLUI_Spinner( raycaster_panel, "Gradient Scale", &gradientScale );
	GUIgscale->set_float_limits( 0.01f, 1.0f );
    GUIgscale->set_alignment( GLUI_ALIGN_RIGHT );

    GUIgdelta = new GLUI_Spinner( raycaster_panel, "Gradient Delta", &gradientDelta );
	GUIgdelta->set_float_limits( 0.01f, 1.0f );
    GUIgdelta->set_alignment( GLUI_ALIGN_RIGHT );

    GUIfmax = new GLUI_Spinner( raycaster_panel, "Histogram (Alpha) Max", &fMax );
	GUIfmax->set_float_limits( 0.01f, 255.0f );
    GUIfmax->set_alignment( GLUI_ALIGN_RIGHT );

    GUIfmin = new GLUI_Spinner( raycaster_panel, "Histogram (Alpha) Min", &fMin );
	GUIfmin->set_float_limits( 0.0f, 255.0f );
    GUIfmin->set_alignment( GLUI_ALIGN_RIGHT );

    GUIalpha = new GLUI_Spinner( raycaster_panel, "Alpha Value", &alpha );
	GUIalpha->set_float_limits( 0.01f, 1.0f );
    GUIalpha->set_alignment( GLUI_ALIGN_RIGHT );

    GUItscale = new GLUI_Spinner( raycaster_panel, "Transfer Scale", &transferScale );
	GUItscale->set_float_limits( 0.01f, 1.0f );
    GUItscale->set_alignment( GLUI_ALIGN_RIGHT );

    GUIthick = new GLUI_Spinner( raycaster_panel, "Thickness", &thickness );
	GUIthick->set_float_limits( 0.01f, 1.0f );
    GUIthick->set_alignment( GLUI_ALIGN_RIGHT );

	GUIXToonRoll = new GLUI_Rollout( glui, "XTOON Parameters", false );
	
	xtoon_panel = new GLUI_Panel( GUIXToonRoll, "" );

	toneDetailBox = new GLUI_Checkbox(xtoon_panel, "Tone Detail", &toneDetail, XTOONTYPE, controlCB );

    GUIr = new GLUI_Spinner( xtoon_panel, "Coarse Detail", &R );
	GUIr->set_float_limits( 1.0f, 25.0f );
    GUIr->set_alignment( GLUI_ALIGN_RIGHT );

	backlightBOX = new GLUI_Checkbox(xtoon_panel, "Backlighting", &backlight, XTOONTYPE, controlCB );

    GUIR = new GLUI_Spinner( xtoon_panel, "Backlight Detail", &backlight_detail );
	GUIR->set_float_limits( 0.0f, 25.0f );
    GUIR->set_alignment( GLUI_ALIGN_RIGHT );

	specularBOX = new GLUI_Checkbox(xtoon_panel, "Specular Highlight", &specHighlight, XTOONTYPE, controlCB );

    GUIs = new GLUI_Spinner( xtoon_panel, "Shine Factor", &S );
	GUIs->set_float_limits( 1.0f, 25.0f );
    GUIs->set_alignment( GLUI_ALIGN_RIGHT );

	xtoonBOX = new GLUI_Checkbox(xtoon_panel, "Enable / Disable", &xToonFlag, XTOON, controlCB );

	glui->set_main_gfx_window(windowId);
    
	glutInitWindowSize(300, 300);
	subWindowId = glutCreateWindow("Transfer Function 2D Texture");
	glutPositionWindow(865, 350);

	// Set GLUT callback functions
	glutReshapeFunc(setViewport);
	glutDisplayFunc(renderSub);
	glutKeyboardFunc(keypressSub);
	
	// Setup OpenGL state & scene resources 
	initSub();

	GLUI_Master.set_glutIdleFunc(updateScene); 

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

	return 0;
}
Esempio n. 30
-1
int main(int argc, char **argv) {
	atexit(cleanup);
    // parse arguments
    char *model_path = NULL;
    char *vertexshader_path = NULL;
    char *fragmentshader_path = NULL;
    char *texture_path = NULL;
    bool use_smoothed_normals;
    if (argc >= 6) {
        texture_path = argv[5];
        useTexture = 1;
    }
	if (argc >= 5) {
        model_path = argv[1];
        vertexshader_path = argv[2];
        fragmentshader_path = argv[3];
        use_smoothed_normals = *argv[4] != '0';
	} else {
        std::cerr << "Usage:" << std::endl;
        std::cerr << argv[0]
             << " <model::path> "
             << " <vertex-shader::path> "
             << " <fragment-shader::path> "
             << " <smooth-normals::{0,1}>"
             << " (<texture::path>)"
             << std::endl;
		exit(1);
	}
	// initialise OpenGL
	glutInit(&argc, argv);
	glutInitWindowSize(windowX, windowY);
	glutCreateWindow("CG-CW1");
	glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
    glEnable(GL_DEPTH_TEST);
    // set display and keyboard callbacks
	glutDisplayFunc(display_handler);
    glutKeyboardFunc(keyboard_handler);
	// initialise the OpenGL Extension Wrangler library for VBOs
	GLenum err = glewInit();
	if (err != GLEW_OK){
        std::cerr << "Error!" << std::endl;
		exit(1);
	}
	if (!GLEW_VERSION_2_1) {
        std::cerr << "Error 2.1!" << std::endl;
		exit(1);
	}
	// create shader, prepare data for OpenGL
    trig.LoadFile(model_path);
	shader.Init(vertexshader_path, fragmentshader_path);
    setup_texture(texture_path, &textureID);
	setup_vertex_position_buffer_object();
	setup_vertex_uv_buffer_object();
    setup_vertex_normal_buffer_object(use_smoothed_normals);
	// set up camera and object transformation matrices
	projectionMatrix = get_default_projectionMatrix();
	viewMatrix = get_default_viewMatrix();
	modelMatrix = get_default_modelMatrix();
    normalMatrix = get_default_normalMatrix();
	glutMainLoop();
}