int main(int argc, char *argv[]) { SDL_Event event; SDL_TimerID timer = 0; /* nacteni modelu */ polymodel = modLoad((argc == 2) ? argv[1] : DEFAULT_MODEL); IZG_CHECK(polymodel, "Failed to read input model"); /* vytvoreni default SW rendereru */ #ifdef USE_STUDENT_RENDERER renderer = studrenCreate(); #else renderer = renCreate(); #endif /* USE_STUDENT_RENDERER */ /* pocatecni velikost bufferu */ renderer->createBuffersFunc(renderer, DEFAULT_WIDTH, DEFAULT_HEIGHT); /* inicializace SDL knihovny */ if( SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) == -1 ) { IZG_SDL_ERROR("Could not initialize SDL library"); } /* nastaveni titulku okna */ #ifdef USE_STUDENT_RENDERER SDL_WM_SetCaption(PROGRAM_TITLE_STUDENT, 0); #else SDL_WM_SetCaption(PROGRAM_TITLE, 0); #endif // USE_STUDENT_RENDERER /* screen */ screen = SDL_SetVideoMode(DEFAULT_WIDTH, DEFAULT_HEIGHT, 32, SDL_HWSURFACE | SDL_DOUBLEBUF | SDL_RESIZABLE); /* enable Unicode translation */ SDL_EnableUNICODE(1); /* dalsi inicializace */ onInit(renderer, polymodel); /* nastavime timer, ktery bude volat zadanou callback fci */ timer = SDL_AddTimer(TIMER_INTERVAL, timerCallback, NULL); /* kreslime dokud nenarazime na SDL_QUIT event */ while( !quit ) { /* vycteni udalosti */ while( SDL_PollEvent(&event) ) { switch( event.type ) { /* udalost klavesnice */ case SDL_KEYDOWN: onKeyboard(&event.key); break; /* zmena velikosti okna */ case SDL_VIDEORESIZE: onResize(&event.resize); break; /* udalost mysi - pohyb */ case SDL_MOUSEMOTION: onMouseMotion(&event.motion); break; /* udalost mysi - tlacitka */ case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONUP: onMouseButton(&event.button); break; /* tiknuti timeru */ case SDL_USEREVENT: if( event.user.code == IZG_TIMER_EVENT ) { onTimer((int)SDL_GetTicks()); } break; /* SDL_QUIT event */ case SDL_QUIT: quit = 1; break; default: break; } } /* vykresleni pres SDL knihovnu */ draw(); } /* ukonceni timeru */ SDL_RemoveTimer(timer); /* ukonceni SDL */ SDL_FreeSurface(screen); /* shutdown all SDL subsystems */ SDL_Quit(); /* zrusime co jsme vytvorili a ukoncime program */ modRelease(&polymodel); renderer->releaseFunc(&renderer); return 0; }
int main(int argc, char *argv[]) { SDL_Event event; /* nacteni modelu */ polymodel = modLoad((argc == 2) ? argv[1] : DEFAULT_MODEL); IZG_CHECK(polymodel, "Failed to read input model"); /* vytvoreni SW rendereru */ #ifdef USE_STUDENT_RENDERER renderer = studrenCreate(); #else renderer = renCreate(); #endif /* USE_STUDENT_RENDERER */ /* pocatecni velikost bufferu */ renderer->createBuffersFunc(renderer, DEFAULT_WIDTH, DEFAULT_HEIGHT); /* inicializace SDL knihovny */ if( SDL_Init(SDL_INIT_VIDEO) == -1 ) { IZG_SDL_ERROR("Could not initialize SDL library"); } /* nasteveni okna */ SDL_WM_SetCaption(PROGRAM_TITLE, 0); /* screen */ screen = SDL_SetVideoMode(DEFAULT_WIDTH, DEFAULT_HEIGHT, 32, SDL_HWSURFACE | SDL_DOUBLEBUF | SDL_RESIZABLE); /* enable Unicode translation */ SDL_EnableUNICODE(1); /* kreslime dokud nenarazime na SDL_QUIT event */ while( !quit ) { /* vycteni udalosti */ while( SDL_PollEvent(&event) ) { switch( event.type ) { /* udalost klavesnice */ case SDL_KEYDOWN: onKeyboard(&event.key); break; /* zmena velikosti okna */ case SDL_VIDEORESIZE: onResize(&event.resize); break; /* udalost mysi */ case SDL_MOUSEMOTION: onMouseMotion(&event.motion); break; /* SDL_QUIT event */ case SDL_QUIT: quit = 1; break; default: break; } } /* vykresleni pres SDL knihovnu */ draw(); } /* ukonceni SDL */ SDL_FreeSurface(screen); /* shutdown all SDL subsystems */ SDL_Quit(); /* zrusime co jsme vytvorili a ukoncime program */ modRelease(&polymodel); renderer->releaseFunc(&renderer); return 0; }
void onKeyboard(SDL_KeyboardEvent *key) { int width, height; /* test existence rendereru */ IZG_ASSERT(renderer); /* vetveni podle stisknute klavesy */ switch( key->keysym.sym ) { /* ukonceni programu - klavesa Esc nebo q */ case SDLK_ESCAPE: case SDLK_q: quit = 1; break; /* prepnuti do celoobrazovkoveho modu */ case SDLK_f: SDL_WM_ToggleFullScreen(screen); break; /* prepnuti na studentsky renderer */ case SDLK_p: /* zapamatovani aktualni velikosti frame bufferu */ width = renderer->frame_w; height = renderer->frame_h; /* zruseni a znovu vytvoreni rendereru */ renderer->releaseFunc(&renderer); renderer = studrenCreate(); renderer->createBuffersFunc(renderer, width, height); /* zmena titulku okna */ SDL_WM_SetCaption(PROGRAM_TITLE_STUDENT, 0); break; /* prepnuti na originalni renderer */ case SDLK_o: width = renderer->frame_w; height = renderer->frame_h; renderer->releaseFunc(&renderer); renderer = renCreate(); renderer->createBuffersFunc(renderer, width, height); SDL_WM_SetCaption(PROGRAM_TITLE, 0); break; /* posun kamery pomoci klaves */ case SDLK_DOWN: renSceneMoveXY(renderer, 0, 1); break; case SDLK_UP: renSceneMoveXY(renderer, 0, -1); break; case SDLK_LEFT: renSceneMoveXY(renderer, -1, 0); break; case SDLK_RIGHT: renSceneMoveXY(renderer, 1, 0); break; default: break; } }