void display ( void ) { if ( debugOpt != DRAW_WITHOUT_SHADERS && debugOpt != DRAW_WITHOUT_PHYSICS ) { runCollisionDetection () ; runPhysics () ; } /* Now render the scene using the results */ glViewport ( 0, 0, win_width, win_height ) ; drawCubes () ; /* All done! */ glutSwapBuffers () ; glutPostRedisplay () ; }
int main ( int argc, char** argv ) { if(Load_Wordlist()==-1) { printf( "Unable to load wordlist\n"); return 1; } // initialize SDL video if ( SDL_Init( SDL_INIT_VIDEO ) < 0 ) { printf( "Unable to init SDL: %s\n", SDL_GetError() ); return 1; } if (TTF_Init()==-1) { printf( "Unable to init SDL: %s\n", SDL_GetError() ); return 1; } // make sure SDL cleans up before exit atexit(SDL_Quit); // create a new window screen = SDL_SetVideoMode(480, 640, 16,SDL_HWSURFACE|SDL_DOUBLEBUF); if ( !screen ) { printf("Unable to set 640x480 video: %s\n", SDL_GetError()); return 1; } // *******************************************Load Resources********************************************/ //******************************************************************************************************/ //****************************************That's right, resources***************************************/ //******************************************************************************************************/ option=IMG_Load("option.png"); if (!option) { printf("Unable to load bitmap: %s\n", SDL_GetError()); return 1; } option2=IMG_Load("option2.png"); if (!option) { printf("Unable to load bitmap: %s\n", SDL_GetError()); return 1; } background=IMG_Load("background.png"); if (!background) { printf("Unable to load bitmap: %s\n", SDL_GetError()); return 1; } gamefont=TTF_OpenFont("Courier_New.ttf",25); gamefontsmall=TTF_OpenFont("Courier_New.ttf",16); if (gamefont==NULL||gamefontsmall==NULL) { printf("Unable to load font: %s\n", SDL_GetError()); return 1; } // *************************************Initialising some vars********************************************/ //********************************************************************************************************/ cur_rect.w=200; cur_rect.h=80; cur_rect.x=(480-200)/2; cur_text_rect.h=20; screen_rect.w=480; screen_rect.h=640; screen_rect.x=0; screen_rect.y=0; int i; for(i=0;i<6;i++){options[i].text=NULL;} textColor.r=0; textColor.g=0; textColor.b=0; milliseconds=SDL_GetTicks(); srand(time(NULL)); //**************************************************Main loop LOL*******************************************/ //**********************************************************************************************************/ //****************************************************Here we go...*****************************************/ //**********************************************************************************************************/ displayMainMenu(); //*********************************************************************************************************** //********************************************Event processing*********************************************** //*********************************************************************************************************** while (!done) { // message processing loop SDL_Event event; while (SDL_PollEvent(&event)) { // check for messages switch (event.type) { // exit if the window is closed case SDL_QUIT: done = true; break; // check for keypresses case SDL_KEYDOWN: { // exit if ESCAPE is pressed if (event.key.keysym.sym == SDLK_ESCAPE) done = true; break; } case SDL_MOUSEBUTTONDOWN: { handleClick(GetClickedOption(event.button.x,event.button.y)); } } // end switch } // end of message processing //*************************************************************************************** //*****************************Rendering************************************************* //*************************************************************************************** // clear screengetline SDL_BlitSurface(background, 0, screen, &screen_rect); if(gamestate>=1&&gamestate<=3) { SDL_BlitSurface(questiontext,0,screen,&screen_rect); } int i; for(i=0;i<optnum;i++) { displayOption(options[i]); } //Run the physics runPhysics(); // finally, update the screen :) SDL_Flip(screen); } // end main loop // free loaded bitmap SDL_FreeSurface(questiontext); SDL_FreeSurface(option2); SDL_FreeSurface(option); SDL_FreeSurface(background); TTF_CloseFont(gamefont); TTF_Quit(); for(i=0;i<numwords;i++) { Free_Word(Words[i]); } free(Words); // all is well ;) printf("Exited cleanly\n"); return 0; }
int main() { Display display = Display(WIDTH, HEIGHT, fullscreen); display.initShaders(); int num = 1024*40; //num = 1024; size_t size = num * sizeof(GLfloat) * 3; GLfloat* points = (GLfloat*) malloc(size); GLfloat* vels = (GLfloat*) malloc(size); GLfloat* accel = (GLfloat*) malloc(size); GLfloat* masses = (GLfloat*)malloc(num * sizeof(GLfloat)); srand(time(0)); for(int i = 0; i < num; i++) { int x = i*3; int y = i*3 +1; int z = i*3 +2; points[x] = (float)(rand() % 10000) / 1000.0f -5.0f; points[y] = (float)(rand() % 10000) / 10000.0f -5.0f; points[z] = (float)(rand() % 10000) / 1000.0f -5.0f; // points[y] = 0; // points[i*3+1] = 0; vels[i*3] = 0; vels[i*3+1] = 0; vels[i*3+2] = 0; /* if(points[x] < 0) { if(points[z]< 0) { points[x] +=10; // points[y] +=1; } else { points[z] -=19; // points[y] +=2; } } else { if(points[z]< 0) { points[z]+=10; // points[y] +=3; } else { points[x]-=10; // points[y] +=4; } } */ vels[x]/= 100.0f; vels[z]/=100.0f; masses[i] = 100000.0f + (float)(rand() % 1000000); //masses[i] = 10000000.0f + rand() - rand(); } //masses[0] = 1000000000.0f; display.setVertexData(points, vels, accel, masses, num); float3* p = 0; float3* v = 0; float3* a = 0; float* m = 0; display.registerCUDA(); Timer timer = Timer(); while(display.running()) { timer.start(); if(!display.paused()) { display.getDevicePointers(&p, &v, &a, &m); runPhysics(p, v, a, m, display.getNumPoints(), false, 1.0f); display.unmapCUDAResources(); } display.render(); timer.stop(); printf("%f\n", timer.getElapsed()); } display.unregisterCUDA(); return 0; }