Ejemplo n.º 1
1
int main( int argc, char *argv[] )
{
   glutInit( &argc, argv );
   glutInitWindowPosition( 200, 200 );
   glutInitWindowSize( 800, 500 );
   glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH );
   glutCreateWindow("World of Awesome");
   glutReshapeFunc( ReshapeGL );
   glutDisplayFunc( Draw );
   glutKeyboardFunc( keyboard );
   glutMouseFunc( mouse );
   glutMotionFunc( mouseMove );
   glutPassiveMotionFunc( passiveMove );
   glutTimerFunc(TIMER_DELAY, tock, 0);

   g_width = g_height = 200;

#ifdef _WIN32 
   GLenum err = glewInit();
   if (GLEW_OK != err)
   {
      std::cerr << "Error initializing glew! " << glewGetErrorString(err) << std::endl;
      return 1;
   }
#endif
#ifdef __APPLE__
   glutSetCursor(GLUT_CURSOR_NONE); 
#endif

   backShade = glm::vec3(0.2,0.5,0.9);

   Initialize();
   
   //test the openGL version
   getGLversion();
   //install the shader
   if (!InstallShader(textFileRead((char *)"shaders/vert.glsl"), textFileRead((char *)"shaders/frag.glsl")))   {
      printf("Error installing shader!\n");
      return 0;
   }

   InitGeom();


   g_shadeType = PHONG;

   g_pitch = 0;
   g_yaw = M_PI / 2;
   float tx = cos(g_pitch)*cos(g_yaw);
   float ty = sin(g_pitch);
   float tz = cos(g_pitch)*cos(M_PI/2 - g_yaw);
   eye = glm::vec3(0, 2.5, 0);
   target = eye + glm::vec3(tx, ty, tz);
   sunDir = normalize(vec3(-0.2, -1.0, 0.0));


   sunShade = glm::vec3(1.0, 1.0, 0.9);

   glutMainLoop();
   return 0;
}
Ejemplo n.º 2
0
void timer(int value) {
	display();
	glutTimerFunc(50, timer, 0);
}
Ejemplo n.º 3
0
void showTimer(int value){
	glutTimerFunc(32, showTimer, 0);
	display();
}
Ejemplo n.º 4
0
void OnTimer(int value)
{
    glutPostRedisplay();
    glutTimerFunc(20, &OnTimer, value);
}
Ejemplo n.º 5
0
void MyWindow::displayTimer(int _val) 
{
	timeStepping();
	glutPostRedisplay();
	glutTimerFunc(mDisplayTimeout, refreshTimer, _val);
}
Ejemplo n.º 6
0
void onTimer(int value)
{
    glutPostRedisplay();
    glutTimerFunc(5, &onTimer, value);
}
Ejemplo n.º 7
0
void tock(int value) {
   updateBoidPos();
   glutPostRedisplay();
   glutTimerFunc(TIMER_DELAY, tock, 0);
}
Ejemplo n.º 8
0
void MainWindow::callback_timer (int value)
{
    glutPostRedisplay();
    glutTimerFunc(15, callback_timer, 0);
}
Ejemplo n.º 9
0
void TimerFunction(int value){
	GlobalWindow.UpdateTitle(value);
	glutTimerFunc(250, TimerFunction, 1); //Fps oppdatert 4x i sekundet, antar jeg
}
Ejemplo n.º 10
0
void glutTimer( int data)
{
	glutPostRedisplay();
	glutTimerFunc(10,glutTimer,0);
}
Ejemplo n.º 11
0
void freeglutManager_RenderTimer(int value) {
    glutSetWindow(value);
    freeglutManager->windows[value]->OnRender();
    glutTimerFunc(15, freeglutManager_RenderTimer, value);
}
Ejemplo n.º 12
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;
}
Ejemplo n.º 13
0
 static void timer(int value) {
   glutTimerFunc(30, timer, 1);
   glutPostRedisplay();
 }
Ejemplo n.º 14
0
void timer(int value)
{
	glutPostRedisplay();
	glutTimerFunc(16, timer, 0);
}
Ejemplo n.º 15
0
// This is used to control the frame rate (60Hz).
void Timer(int)
{
	glutSetWindow(mainWindow);
	glutPostRedisplay();
	glutTimerFunc(framePeriod, Timer, 0);
}
Ejemplo n.º 16
0
void display() {
  GLfloat cx, cy, cz = 0.0;      // X, Y, Z position of planet
  int i;

  glClear(GL_COLOR_BUFFER_BIT | 
	  GL_DEPTH_BUFFER_BIT);  // clear color and depth buffer


  glEnable(GL_COLOR_MATERIAL);   // Using glColorMaterial allows planets
                                 // to just use the color set by
                                 // glColor as a material setting

  glPushMatrix();                   // Sun
  emit[0] = red.r;
  emit[1] = red.g;
  emit[2] = red.b;
  glMaterialfv(GL_FRONT_AND_BACK, 
	       GL_EMISSION, emit);
  glutSolidSphere(0.20, 20, 16); 
  emit[0] = 0.0;
  emit[1] = 0.0;
  emit[2] = 0.0;
  glMaterialfv(GL_FRONT_AND_BACK, 
	       GL_EMISSION, emit); // Reset Emission
  glPopMatrix();


  glPushMatrix();                       // Planet 1

                                        // Compute position along an ellipse as:
                                        // x = xc + (a * cos(degree))
                                        // y = yc + (b * sin(degree))

                                        // xc, xy are center of ellipse on
                                        //        both x and y axis
                                        // a is radius along x axis of ellipse
                                        // b is radius along y axis of ellipse 
                                        // degree is 0...360, 

  cx = 0.0 + (0.5 * cos(p1*d2r));       // x postion of planet
  cy = 0.0 + (1.0 * sin(p1*d2r));       // y position of planet
  glTranslatef(cx, cy, cz);             // move to location of planet
  glColor3f(lightSkyBlue.r,             // Color the planet
	    lightSkyBlue.g, 
	    lightSkyBlue.b);
  glutSolidSphere(0.13, 20, 16);        // Make the planet
                                        // 0.13 = radius
                                        // 20 = slices (vertical)
                                        // 16 = stackes (horizontal)
  glPopMatrix();

  glPushMatrix();                       // Planet 2
  cx = 0.0 + (1.0 * cos(p2*d2r));
  cy = 0.0 + (1.5 * sin(p2*d2r));
  glTranslatef(cx, cy, cz);
  glColor3f(green.r, green.g, green.b); 
  glutSolidSphere(0.15, 20, 16); 
  glPopMatrix();

  glPushMatrix();                       // Planet 3
  cx = 0.0 + (1.5 * cos(p3*d2r));
  cy = 0.0 + (2.0 * sin(p3*d2r));
  glTranslatef(cx, cy, cz);
  glColor3f(white.r, white.g, white.b); 
  glutSolidSphere(0.14, 20, 16); 
  glPopMatrix();

  glPushMatrix();                       // Planet 4
  cx = 0.0 + (2.0 * cos(p4*d2r));
  cy = 0.0 + (2.5 * sin(p4*d2r));
  glTranslatef(cx, cy, cz);
  glColor3f(yellow.r, yellow.g, yellow.b);
  glutSolidSphere(0.14, 20, 16); 
  glPopMatrix();


  glPushMatrix();                       // Planet 5
  cx = 0.0 + (2.5 * cos(p5*d2r));
  cy = 0.0 + (3.0 * sin(p5*d2r));
  glTranslatef(cx, cy, cz);
  glColor3f(violet.r, violet.g, violet.b);
  glutSolidSphere(0.15, 20, 16); 
  glPopMatrix();


  glPushMatrix();                       // Planet 6
  cx = 0.0 + (3.0 * cos(p6*d2r));
  cy = 0.0 + (3.5 * sin(p6*d2r));
  glTranslatef(cx, cy, cz);
  glColor3f(coral.r, coral.g, coral.b);
  glutSolidSphere(0.19, 20, 16); 
  glPopMatrix();


  if (SPOT_LIGHT) {
    glPushMatrix();                       // Spot Light Direction
    glTranslatef(spot_direction[0], spot_direction[1], spot_direction[2]);
    glColor3f(0.0, 1.0, 0.0);
    glutSolidSphere(0.45, 20, 16); 
    glPopMatrix();

  }



  glDisable(GL_COLOR_MATERIAL);         // Turn off glColorMaterial

  glutSwapBuffers();
  glutTimerFunc(70, move, 0);
}
Ejemplo n.º 17
0
void Timer::start()
	{
	enabled( true );
	glutTimerFunc( 0, Timer::trigger, timerID );
	}
Ejemplo n.º 18
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();
}
Ejemplo n.º 19
-1
void timer(int i)
{
	glutTimerFunc(20, &timer, i);
	glutPostRedisplay();
}
Ejemplo n.º 20
-1
///////////////////////////////////////////////////////////
// Called by GLUT library when idle (window not being
// resized or moved)
void TimerFunction(int value)
{
	// Redraw the scene with new coordinates
	glutPostRedisplay();
	glutTimerFunc(3,TimerFunction, 1);
}