Bool player(char *fn) { Bool ret = GF_FALSE; GF_Err e; GF_User user; GF_Terminal *term = NULL; GF_Config *cfg_file; memset(&user, 0, sizeof(user)); cfg_file = gf_cfg_init(NULL, NULL); user.modules = gf_modules_new(NULL, cfg_file); e = manually_register_opengl_shared_module(user.modules); if (e != GF_OK) goto exit; set_cfg_option(cfg_file, "Video:DriverName=" OPENGL_SHARED_MODULE_NAME_STR); user.config = cfg_file; user.opaque = &user; user.EventProc = event_proc; term = gf_term_new(&user); if (!term) goto exit; gf_term_connect(term, fn); while (!connected) gf_sleep(1); while ( connected) { gf_term_process_step(term); check_keyboard(term); } ret = GF_TRUE; exit: gf_term_disconnect(term); gf_term_del(term); gf_modules_del(user.modules); gf_cfg_del(cfg_file); return ret; }
// this is what is done at every time step independently of the game state static void step() { // copy pointer to ball position values if (ball_translation) ball_pos = wb_supervisor_field_get_sf_vec3f(ball_translation); int i; for (i = 0; i < NUM_ROBOTS; i++) { // copy pointer to robot position values if (robot_translation[i]) robot_pos[i] = wb_supervisor_field_get_sf_vec3f(robot_translation[i]); if (robot_rotation[i]) robot_rot[i] = wb_supervisor_field_get_sf_rotation(robot_rotation[i]); } if (message_steps) message_steps--; // yield control to simulator wb_robot_step(TIME_STEP); // every 480 milliseconds if (step_count++ % 12 == 0) sendGameControlData(); //checkFalling(); // did I receive a message ? //read_incoming_messages(); // read key pressed check_keyboard(); }
void opener(int xsize, int ysize) { int scale; int frames=0,keyspressed=0; int triangle,done=0,original_msecs=0,current_msecs=0; float time_passed,i; char alpha; GLfloat light_position[]={0.0,0.0,10.0,0.0 }; GLfloat lmodel_ambient[]={0.9,0.9,0.9,1.0 }; GLfloat white_light[]={1.0,1.0,1.0,1.0 }; GLfloat red_material[2][4]={ {0.2,0.0,0.0,1.0}, /* Ambient */ {0.9,0.1,0.1,1.0} /* Diffuse */ }; GLfloat green_material[2][4]={ {0.0,0.2,0.0,1.0}, /* Ambient */ {0.1,0.9,0.1,1.0} /* Diffuse */ }; GLfloat blue_material[2][4]={ {0.0,0.0,0.2,1.0}, /* Ambient */ {0.1,0.1,0.9,1.0} /* Diffuse */ }; GLfloat no_mat[]={0.0,0.0,0.0,1.0 }; GLfloat no_shiny[]={0.0 }; scale=xsize/320; if (scale<=1) scale=1; else (scale=2); /* Look in the right direction */ glLoadIdentity(); gluLookAt(-0.00,0.0,15.0, 0.0,0.0,0.0, 0.0,1.0,1.0); /* Setup triangle display list */ triangle=glGenLists(1); glNewList(triangle,GL_COMPILE); /* Front */ glBegin(GL_TRIANGLES); glNormal3f(0.0,0.0,1.0); glVertex3f(-2.0,2.0,0.5); glVertex3f( 2.0,2.0,0.5); glVertex3f( 0.0,-2.0,0.5); glEnd(); /* Sides */ glBegin(GL_QUADS); glNormal3f(0.0,1.0,0.0); glVertex3f(-2.0, 2.0, 0.5); glVertex3f(-2.0, 2.0,-0.5); glVertex3f( 2.0, 2.0,-0.5); glVertex3f( 2.0, 2.0, 0.5); glNormal3f( 1.4142,-1.4142,0.0); glVertex3f( 2.0, 2.0, 0.5); glVertex3f( 2.0, 2.0,-0.5); glVertex3f( 0.0,-2.0,-0.5); glVertex3f( 0.0,-2.0, 0.5); glNormal3f(-1.4142,-1.4142,0.0); glVertex3f( 0.0,-2.0, 0.5); glVertex3f( 0.0,-2.0,-0.5); glVertex3f(-2.0, 2.0,-0.5); glVertex3f(-2.0, 2.0, 0.5); glEnd(); /* Back */ glBegin(GL_TRIANGLES); glNormal3f(0.0,0.0,-1.0); glVertex3f(-2.0, 2.0, -0.5); glVertex3f( 2.0, 2.0, -0.5); glVertex3f( 0.0, -2.0, -0.5); glEnd(); glEndList(); if (use_lighting) { glLightfv(GL_LIGHT0, GL_POSITION, light_position); glLightfv(GL_LIGHT0, GL_DIFFUSE, white_light); glLightfv(GL_LIGHT0, GL_SPECULAR,white_light); /* glLightfv(GL_LIGHT1, GL_AMBIENT, light_ambient); glLightfv(GL_LIGHT1, GL_POSITION, light_position2); glLightfv(GL_LIGHT1, GL_SPECULAR,white_light); */ glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); } glEnable(GL_DEPTH_TEST); /* Attempt to calculate FPS */ original_msecs=SDL_GetTicks(); i=180; #define TIME_TO_TAKE 3.0 while (!done) { /* hack! why does my machine need this!?! */ usleep(1); current_msecs=SDL_GetTicks(); if (show_fps) { frames++; if (frames%20==0) { printf("FPS=%f\n",((float) frames)/((current_msecs-original_msecs)/1000.0)); } } time_passed=((float)(current_msecs-original_msecs))/1000.0; // printf("%.2f\n",time_passed); i=180+(time_passed*(180.0/TIME_TO_TAKE)); if (i>360.0) i=360.0; // printf("%i %i %f %f\n",current_msecs,original_msecs,time_passed,i); if (time_passed>TIME_TO_TAKE) done=1; glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); /* Red */ glColor3f(1.0,0.0,0.0); glMaterialfv(GL_FRONT,GL_AMBIENT, red_material[0]); glMaterialfv(GL_FRONT,GL_DIFFUSE, red_material[1]); glMaterialfv(GL_FRONT,GL_SPECULAR, no_mat); glMaterialfv(GL_FRONT,GL_SHININESS, no_shiny); glMaterialfv(GL_FRONT,GL_EMISSION, no_mat); glPushMatrix(); glTranslatef(-4 - ((360.0-i)/18.0),0,0.0); glRotatef(i,1,1,1); glCallList(triangle); glPopMatrix(); /* Blue */ glColor3f(0.0,0.0,1.0); glMaterialfv(GL_FRONT,GL_AMBIENT, blue_material[0]); glMaterialfv(GL_FRONT,GL_DIFFUSE, blue_material[1]); glMaterialfv(GL_FRONT,GL_SPECULAR, no_mat); glMaterialfv(GL_FRONT,GL_SHININESS, no_shiny); glMaterialfv(GL_FRONT,GL_EMISSION, no_mat); glPushMatrix(); glTranslatef(0,((360.0-i)/18.0),0.0); glRotatef(i,1,1,1); glCallList(triangle); glPopMatrix(); glPushMatrix(); glTranslatef(4+((360.0-i)/18.0),0+((360.0-i)/18.0),0.0); glRotatef(i,1,1,1); glCallList(triangle); glPopMatrix(); /* Green */ glColor3f(0.0,0.0,1.0); glMaterialfv(GL_FRONT,GL_AMBIENT, green_material[0]); glMaterialfv(GL_FRONT,GL_DIFFUSE, green_material[1]); glMaterialfv(GL_FRONT,GL_SPECULAR, no_mat); glMaterialfv(GL_FRONT,GL_SHININESS, no_shiny); glMaterialfv(GL_FRONT,GL_EMISSION, no_mat); glPushMatrix(); glTranslatef(-2,-((360.0-i)/18.0),0.0); glRotatef(180,1,0,0); glRotatef(i,1,1,1); glCallList(triangle); glPopMatrix(); glPushMatrix(); glTranslatef(2+((360.0-i)/18.0),-((360.0-i)/18.0),0.0); glRotatef(180,1,0,0); glRotatef(i,1,1,1); glCallList(triangle); glPopMatrix(); glFlush(); SDL_GL_SwapBuffers(); } if (use_lighting) { glDisable(GL_LIGHTING); } glDisable(GL_LIGHTING); glViewport(0,0,xsize,ysize); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(0,320,0,200); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glColor3f(1.0,1.0,1.0); glRasterPos3f(60,50,0); vmwGLString("A VMW SOFTWARE PRODUCTION",font); glFlush(); SDL_GL_SwapBuffers(); done=0; /* cleak keyboard buffer */ keyspressed=check_keyboard(&alpha,1); original_msecs=SDL_GetTicks(); /* Wait 4 seconds or until keypressed */ while( ((SDL_GetTicks()-original_msecs)<4000) && (!done)) { keyspressed=check_keyboard(&alpha,0); if (keyspressed) { done=1; } /* sleep so we don't use 100% of CPU */ usleep(100); } /* add code to pause for a few minutes here */ /* plus play some music */ /* Don't need this anymore? */ glDeleteLists(triangle,1); }
int do_credits(game_state_type *gs) { char key_alpha; int frames=0,new_msecs,old_msecs,fps_msecs=0,old_fps_msecs=0; int keyspressed; float scale,camerax=10,cameray=-10,cameraz=10,camera_direction=0; int right_elbow=0; GLfloat light_position[]={5.0,5.0,100.0,0.0}; GLfloat lmodel_ambient[]={0.9,0.9,0.9,1.0}; GLfloat white_light[]={1.0,1.0,1.0,1.0}; printf("ENTERING DO CREDITS\n"); fflush(stdout); /* Init screen and keyboard */ reshape(gs->xsize,gs->ysize); check_keyboard(&key_alpha,1); printf("ABOUT TO SETUP TFV\n"); fflush(stdout); setup_tfv(); setup_tfe(); printf("ABOUT TO ENTER MAIN LOOP\n"); fflush(stdout); while (1) { frames++; new_msecs=SDL_GetTicks(); /* * how far to go in 1s */ scale=(new_msecs-old_msecs)/50.0; old_msecs=new_msecs; if (frames%100==0) { old_fps_msecs=fps_msecs; fps_msecs=SDL_GetTicks(); printf("FPS=%.2f\n", frames/((fps_msecs-old_fps_msecs)/1000.0)); frames=0; } /* Check for input events */ keyspressed=check_keyboard(&key_alpha,0); if (keyspressed&MENU_PRESSED) { return 0; } if (keyspressed&PAN_LEFT_PRESSED) { camera_direction-=(10.0*PI)/180; if (camera_direction<0.0) camera_direction+=2*PI; camerax=10*sin(camera_direction); cameray=10*cos(camera_direction); } if (keyspressed&PAN_RIGHT_PRESSED) { camera_direction+=(10.0*PI)/180; if (camera_direction>2*PI) camera_direction-=2*PI; camerax=10*sin(camera_direction); cameray=10*cos(camera_direction); } if (keyspressed&UP_PRESSED) { cameraz+=0.5; } if (keyspressed&DOWN_PRESSED) { cameraz-=0.5; } if (keyspressed&RIGHT_PRESSED) { right_elbow+=10; } glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); gluLookAt(camerax,cameray,cameraz, 0.0,0.0,0.0, 0.0,0.0,1.0); glLightfv(GL_LIGHT0, GL_POSITION, light_position); glLightfv(GL_LIGHT0, GL_DIFFUSE, white_light); glLightfv(GL_LIGHT0, GL_SPECULAR,white_light); glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); { GLfloat default_a[]={0.6,0.6,0.6,1.0}; GLfloat default_d[]={0.8,0.8,0.8,1.0}; GLfloat default_s[]={0.0,0.0,0.0,1.0}; GLfloat default_e[]={0.0,0.0,0.0,1.0 }; glMaterialfv(GL_FRONT,GL_AMBIENT,default_a); glMaterialfv(GL_FRONT,GL_DIFFUSE,default_d); glMaterialfv(GL_FRONT,GL_SPECULAR,default_s); glMaterialfv(GL_FRONT,GL_EMISSION,default_e); } glBegin(GL_QUADS); glVertex3f(-5,-5,0); glVertex3f(5,-5,0); glVertex3f(5,5,0); glVertex3f(-5,5,0); glVertex3f(-5,5,0); glVertex3f(5,5,0); glVertex3f(5,5,5); glVertex3f(-5,5,5); glVertex3f(-5,-5,0); glVertex3f(-5,5,0); glVertex3f(-5,5,5); glVertex3f(-5,-5,5); glEnd(); glEnable(GL_TEXTURE_2D); glPushMatrix(); glTranslatef(0,0,6.5); glRotatef(90,0,1,0); draw_tfv(0,0,0,0, 0,right_elbow,0, 0,0,0, 0, 1); glPopMatrix(); /* Flush it out to the device */ glFlush(); SDL_GL_SwapBuffers(); glDisable(GL_LIGHTING); glDisable(GL_TEXTURE_2D); /* Emulate low frame-rates */ //usleep(100000); } (void) scale; return 1; }
void refresh() { // SDL (and Xlib) don't handle threads well, so we do both of these check_keyboard(); display_image(); }
void display(void) { check_keyboard(); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); t += 0.02; i = 0; glUniform1i(glGetUniformLocation(program, "i"), i); //Camera placement up[0]= 0.0f; up[1]= 1.0f; up[2] = 0.0f; glUniform1f(glGetUniformLocation(program, "tid"), t); lookAt(&cam_pos, &lookAt_pos, up[0],up[1],up[2], cam); for(int i = 0; i < 16; i++) { if(i != 3 && i != 7 && i != 11) { cam_mod[i] = cam[i]; } else { cam_mod[i] = 0; } } IdentityMatrix(total); T(0.0, -0.5f, 0.0f, total); glUniformMatrix4fv(glGetUniformLocation(program, "mdlMatrix"), 1, GL_TRUE, total); glUniformMatrix4fv(glGetUniformLocation(program, "CameraMatrix"), 1, GL_TRUE, cam_mod); printError("pre display"); glDisable(GL_DEPTH_TEST); // glDisable(GL_CULL_FACE); glUniform1i(glGetUniformLocation(program, "texUnit"), 1); // Texture unit 1 DrawModel(skybox, program, "in_Position", "in_Normal", "in_TexCoord"); //glEnable(GL_CULL_FACE); glEnable(GL_DEPTH_TEST); glUniformMatrix4fv(glGetUniformLocation(program, "CameraMatrix"), 1, GL_TRUE, cam); // Marken glUniform1i(glGetUniformLocation(program, "texUnit"), 0); // Texture unit 0 T(0.0, -7.0, -.0f, total); glUniformMatrix4fv(glGetUniformLocation(program, "mdlMatrix"), 1, GL_TRUE, total); unsigned int groundBufferObjID; unsigned int groundTexCoordBufferObjID; unsigned int gNormalBufferObjID; glGenVertexArrays(1, &groundVertexArrayObjID); glGenVertexArrays(1, &gNormalArrayObjID); glBindVertexArray(groundVertexArrayObjID); glGenBuffers(1, &groundBufferObjID); // Vertices glBindBuffer(GL_ARRAY_BUFFER, groundBufferObjID); glBufferData(GL_ARRAY_BUFFER, 6*3*sizeof(GLfloat), ground, GL_STATIC_DRAW); glVertexAttribPointer(glGetAttribLocation(program, "in_Position"), 3, GL_FLOAT, GL_FALSE, 0, 0); glEnableVertexAttribArray(glGetAttribLocation(program, "in_Position")); // Texturen glGenBuffers(1, &groundTexCoordBufferObjID); glBindBuffer(GL_ARRAY_BUFFER, groundTexCoordBufferObjID); glBufferData(GL_ARRAY_BUFFER, 12*sizeof(GLfloat), ground_tex_coord, GL_STATIC_DRAW); glVertexAttribPointer(glGetAttribLocation(program, "in_TexCoord"), 2, GL_FLOAT, GL_FALSE, 0, 0); glEnableVertexAttribArray(glGetAttribLocation(program, "in_TexCoord")); // Normalen till ground glBindVertexArray(gNormalArrayObjID); glGenBuffers(1, &gNormalBufferObjID); glBindBuffer(GL_ARRAY_BUFFER, gNormalBufferObjID); glBufferData(GL_ARRAY_BUFFER, 6*3*sizeof(GLfloat), gNormal, GL_STATIC_DRAW); glVertexAttribPointer(glGetAttribLocation(program, "in_Normal"), 3, GL_FLOAT, GL_FALSE, 0, 0); glEnableVertexAttribArray(glGetAttribLocation(program, "in_Normal")); // Draw the ground glBindVertexArray(groundVertexArrayObjID); glDrawArrays(GL_TRIANGLES, 0, 6); printError("Display ground"); i = 1; // Sluta rita med textures glUniform1i(glGetUniformLocation(program, "i"), i); i = 0; // Använd i som en räknare igen... // vingarna T(wing_x, wing_y, wing_z, trans); Ry(M_PI/12, total); Rz(0, total); Rx(t / 2, rot); Mult(rot, total, total); Mult(trans, total, total); glUniformMatrix4fv(glGetUniformLocation(program, "mdlMatrix"), 1, GL_TRUE, total); DrawModel(wings, program,"in_Position","in_Normal", NULL); T(wing_x, wing_y, wing_z, trans); Ry(M_PI/12, total); Rz(0, total); Rx(M_PI/2 + t / 2, rot); Mult(rot, total, total); Mult(trans, total, total); glUniformMatrix4fv(glGetUniformLocation(program, "mdlMatrix"), 1, GL_TRUE, total); DrawModel(wings, program,"in_Position","in_Normal", NULL); T(wing_x, wing_y, wing_z, trans); Ry(M_PI/12, total); Rx(M_PI + t / 2, rot); Mult(rot, total, total); Mult(trans, total, total); glUniformMatrix4fv(glGetUniformLocation(program, "mdlMatrix"), 1, GL_TRUE, total); DrawModel(wings, program,"in_Position","in_Normal", NULL); T(wing_x, wing_y, wing_z, trans); Ry(M_PI/12, total); Rx(3*M_PI/2 + t / 2, rot); Mult(rot, total, total); Mult(trans, total, total); glUniformMatrix4fv(glGetUniformLocation(program, "mdlMatrix"), 1, GL_TRUE, total); DrawModel(wings, program,"in_Position","in_Normal", NULL); // Möllan T(0,-8,-25, trans); Ry(i, rot); Mult(trans, rot, total); glUniformMatrix4fv(glGetUniformLocation(program, "mdlMatrix"), 1, GL_TRUE, total); DrawModel(walls, program,"in_Position","in_Normal", NULL); // Taket T(0.0, -8.0, -25, trans); Ry(0, rot); Mult(trans, rot, total); glUniformMatrix4fv(glGetUniformLocation(program, "mdlMatrix"), 1, GL_TRUE, total); DrawModel(roof, program,"in_Position","in_Normal", NULL); // Balkongen T(0.0, -8.2, -25, trans); Ry(i, rot); Mult(trans, rot, total); glUniformMatrix4fv(glGetUniformLocation(program, "mdlMatrix"), 1, GL_TRUE, total); DrawModel(balcony, program,"in_Position","in_Normal", NULL); printError("display"); glutSwapBuffers(); }
int main(int argc, char *argv[]){ int input_waiting = 0; char *dev, *fn; FILE *outfile; mut_connection *conn; if (argc <=2){ printf("Usage: perf_logger device log-file\n"); return -1; } dev = argv[1]; fn = argv[2]; printf("libM U T logger for Engine Peformance:\n"); printf("--------------------------------------\n"); printf("Opening log file :%s\n", fn); /* FIXME: At some point in the future, atexit should close this file*/ if( (outfile = fopen(fn, "w+")) == NULL){ perror("Log open failed"); return -1; } printf("MUT device:%s\n", dev); /* FIXME: At some point in the future, atexit should close this file*/ printf("Press [return] to start:"); fflush(stdout); while(input_waiting == 0){ input_waiting = check_keyboard(1,0); if(input_waiting){ char buf; scanf("%c", &buf); input_waiting=0; break; } } printf("Connecting...\n"); conn = mut_connect_posix(dev,0); if(conn == NULL){ perror("Failed"); return -1; } if(mut_init(conn) != 0){ printf("Init failed.\n"); mut_free(conn); return -1; } printf("Logging, press [return] to quit."); while(input_waiting == 0){ char *line; /* Log a line */ line = get_data_line(conn); if(line == NULL){ printf("data timed out"); break; } fprintf(outfile, line); free(line); input_waiting = check_keyboard(0,250); if(input_waiting){ char buf; scanf("%c", &buf); input_waiting=0; break; } } mut_free(conn); return 0; }