void QtInterface::paintGL() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); glColor4f(1.0f, 1.0f, 1.0f, 1.0f); Engine()->Render(); if ( Input()->KeyPressed( KEY_F5 ) ) { #ifdef _WIN32 // TODO: Update DevIl installation on linux to match newest version ilutGLScreenie(); #endif } m_iFrameCount += 1; float curtime = Timer()->CurrentTime(); float dt = curtime - m_flLastTime; if ( dt >= 1.0f ) { m_flFPS = (m_iFrameCount / dt); m_flLastTime = curtime; m_iFrameCount = 0; } if ( m_flFPS != 0.0f ) { QString str; str.sprintf("%.2f fps (%.5f ms), time: %.2f", m_flFPS, (1.0f/m_flFPS), curtime); renderText(1, 10, str); } }
ILboolean ilOgl::Screenie() { return ilutGLScreenie(); }
int main( int argc, char *argv[]) { // this was a quick test of InetOpenURL #if 0 HINTERNET hnet = InternetOpen( "Game", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0 ); HINTERNET hfile = InternetOpenUrl( hnet, "http://www.yahoo.com", NULL, 0, INTERNET_FLAG_DONT_CACHE, 0); char buff[5000]; unsigned long nread; InternetReadFile( hfile, buff, 5000, &nread ); buff[nread] = 0; printf( buff ); #endif if ( SDL_Init(SDL_INIT_NOPARACHUTE | SDL_INIT_AUDIO|SDL_INIT_VIDEO |SDL_INIT_JOYSTICK) < 0 ) { fprintf(stderr, "Unable to init SDL: %s\n", SDL_GetError()); exit(1); } if( SDL_SetVideoMode( 800, 600, 16, SDL_OPENGL /*| SDL_FULLSCREEN */ ) == 0 ) { fprintf(stderr, "Unable to set video mode: %s\n", SDL_GetError()); exit(1); } SDL_WM_SetCaption( "The Halloween Machine", NULL ); // Init SDL_Mixer if (Mix_OpenAudio( 22050, AUDIO_S16, 2, 4096 )) { fprintf(stderr, "Unable to open audio\n"); exit(1); } // Initialize Joysticks/Gamepads printf("%d Controllers found.\n", SDL_NumJoysticks() ); for (int i=0; i < SDL_NumJoysticks(); i++) { printf( "Controller %d: %s\n", i, SDL_JoystickName(i) ); } gamepad.name = "No gamepad detected."; gamepad.sdlinfo = NULL; gamepad.stick = vec2f(0.0, 0.0 ); gamepad.stick2 = vec2f(0.0, 0.0 ); // Only use the first controller if (SDL_NumJoysticks() > 0 ) { gamepad.sdlinfo = SDL_JoystickOpen(0); } // init highscores readHighScores(); if (gamepad.sdlinfo) { gamepad.name = strdup( SDL_JoystickName(0) ); printf( "Gamepad: Number of axes: %d\n", SDL_JoystickNumAxes(gamepad.sdlinfo) ); printf( "Gamepad: Number of buttons: %d\n", SDL_JoystickNumButtons(gamepad.sdlinfo) ); printf( "Gamepad: Number of balls: %d\n", SDL_JoystickNumBalls(gamepad.sdlinfo) ); printf( "Gamepad: Number of hats: %d\n", SDL_JoystickNumHats(gamepad.sdlinfo) ); } // initialize DevIL ilInit(); ilutRenderer( ILUT_OPENGL ); // Setup glgameFont // Load the font image ilGenImages( 1, &ilFontId ); ilBindImage( ilFontId ); if (!ilLoadImage( "gamedata/magic.png" )) { printf("Loading font image failed\n"); } // Make a GL texture for it glFontTexId = ilutGLBindTexImage(); // Create a font by passing in an opengl texture id fntFontId = gfCreateFont( glFontTexId ); // A .finfo file contains the metrics for a font. These // are generated by the Fontpack utility. gfLoadFontMetrics( fntFontId, "gamedata/magic.finfo"); printf("font has %d chars\n", gfGetFontMetric( fntFontId, GF_FONT_NUMCHARS ) ); gfEnableFont( fntFontId, 25 ); sfx[0] = Mix_LoadWAV("gamedata/whiit.wav"); sfx[1] = Mix_LoadWAV("gamedata/didge.wav"); sfx[2] = Mix_LoadWAV("gamedata/sfx_boom.wav"); sfx[3] = Mix_LoadWAV("gamedata/harp.wav"); sfx[4] = Mix_LoadWAV("gamedata/secret.wav"); music_title = Mix_LoadMUS( "gamedata/AutumnLeft.ogg" ); music_gameover = Mix_LoadMUS( "gamedata/YouDiedLoser.ogg" ); music_ingame = Mix_LoadMUS( "gamedata/ingame.ogg" ); if (!music_title) { printf("Error loading music %s\n", Mix_GetError() ); } else { printf("Music loaded\n"); } Mix_PlayMusic( music_title, -1 ); // Start up the game g_game = new GameState(); g_game->init(); g_game->loadLevels( "gamedata/levels.txt" ); g_view = new ViewSimple2D( g_game ); g_game->setView( g_view ); ////////////////////// // Event Loop ////////////////////// while (1) { SDL_Event event; /* Grab all the events off the queue. */ while( SDL_PollEvent( &event ) ) { switch( event.type ) { case SDL_KEYDOWN: // are we reading highscore?? if (ndxGetName >=0 ) { char buff[10]; if ( ((event.key.keysym.sym >= SDLK_a) && (event.key.keysym.sym <= SDLK_z)) || ((event.key.keysym.sym >= SDLK_0) && (event.key.keysym.sym <= SDLK_9))) { sprintf( buff, "%c", (char)event.key.keysym.sym ); if (event.key.keysym.mod & (KMOD_LSHIFT|KMOD_RSHIFT)) { buff[0] = toupper(buff[0]); } if (!strcmp(g_highScoreTable[ndxGetName].m_name.c_str(), HISCORE_PROMPT)) { g_highScoreTable[ndxGetName].m_name = ""; } g_highScoreTable[ndxGetName].m_name.append( buff); } else if ( (event.key.keysym.sym==SDLK_BACKSPACE) ) { if (g_highScoreTable[ndxGetName].m_name.length()){ g_highScoreTable[ndxGetName].m_name.erase( g_highScoreTable[ndxGetName].m_name.end()-1 ); } } else if ( (event.key.keysym.sym==SDLK_RETURN) || (event.key.keysym.sym==SDLK_ESCAPE) ) { if (!g_highScoreTable[ndxGetName].m_name.length()) { g_highScoreTable[ndxGetName].m_name = "Anonymous"; } ndxGetName = -1; writeHighScores(); } break; } switch( event.key.keysym.sym ) { case SDLK_ESCAPE: if ( (g_state==STATE_TITLE) && (g_menuState == MENU_MAINMENU)) { do_quit(); } else { backToTitleScreen(); } break; case SDLK_a: g_view->toggleAnim(); break; case SDLK_p: paused = !paused; break; // Cheat codes.. enable for testing #if 0 case SDLK_z: if (g_state==STATE_GAMEOVER) { ndxGetName = 3; break; } case SDLK_1: g_game->dbgNextPumpkin( PUMPKIN ); break; case SDLK_2: g_game->dbgNextPumpkin( PUMPKIN_ORANGE ); break; case SDLK_3: g_game->dbgNextPumpkin( PUMPKIN_YELLOW ); break; case SDLK_4: g_game->dbgNextPumpkin( PUMPKIN_RED ); break; case SDLK_5: g_game->dbgNextPumpkin( SKULL ); break; case SDLK_6: g_game->dbgNextPumpkin( FISH_HEAD ); break; case SDLK_7: g_game->dbgNextPumpkin( BLACKBIRD ); break; case SDLK_8: g_game->dbgClearQueue(); break; #endif case SDLK_s: ilutGLScreenie(); break; case SDLK_d: bDrawGamepad = !bDrawGamepad; break; case SDLK_m: if (!musicOn) { printf("Playing\n"); if (g_state==STATE_TITLE) { Mix_PlayMusic( music_title, -1 ); } else if (g_state==STATE_PLAYING) { Mix_PlayMusic( music_ingame, -1 ); } else if (g_state==STATE_GAMEOVER) { // easter egg.. kindof.. you get to hear the // game over music again. woo. Mix_PlayMusic( music_gameover, 0 ); } musicOn = 1; } else { printf("Halting\n"); Mix_HaltMusic(); musicOn = 0; } case SDLK_LEFT: g_view->nextStation(); break; case SDLK_RIGHT: g_view->prevStation(); break; case SDLK_SPACE: case SDLK_RETURN: if (g_state == STATE_PLAYING) { doActivateStation(); } else { doStartButton(); } break; case SDLK_UP: if (g_state==STATE_PLAYING) { //g_view->activateStation(); doActivateStation(); } else if (g_state==STATE_TITLE ) { prevMenuItem(); } break; case SDLK_DOWN: if (g_state==STATE_TITLE ) { nextMenuItem(); } break; default: break; } break; case SDL_JOYAXISMOTION: /* Handle Joystick Motion */ if ( ( event.jaxis.value < -3200 ) || (event.jaxis.value > 3200 ) ) { switch(event.jaxis.axis) { case 0: gamepad.stick[0] = (float)(event.jaxis.value) / 32768.0f; break; case 1: gamepad.stick[1] = (float)(event.jaxis.value) / 32768.0f; break; case 2: gamepad.throttle = (float)(event.jaxis.value) / 32768.0f; break; case 3: gamepad.stick2[0] = (float)(event.jaxis.value) / 32768.0f; break; case 4: gamepad.stick2[1] = (float)(event.jaxis.value) / 32768.0f; break; } } else { // prevent jitter near the center positions switch(event.jaxis.axis) { case 0: gamepad.stick[0] = 0.0; break; case 1: gamepad.stick[1] = 0.0; break; case 2: gamepad.throttle = 0.0; break; case 3: gamepad.stick2[0] = 0.0; break; case 4: gamepad.stick2[1] = 0.0; break; } } break; case SDL_JOYBUTTONDOWN: /* Handle Joystick Button Presses */ gamepad.button[event.jbutton.button] = true; switch (event.jbutton.button) { case 0: //g_view->activateStation(); if (g_state==STATE_PLAYING) { doActivateStation(); } else { doStartButton(); } break; //case 1: // sfx_chan[1] = Mix_PlayChannel(-1, sfx[1], 0); // break; //case 2: // sfx_chan[2] = Mix_PlayChannel(-1, sfx[2], 0); // break; case 8: // start button doStartButton(); break; } break; case SDL_JOYBUTTONUP: /* Handle Joystick Button Release */ gamepad.button[event.jbutton.button] = false; break; case SDL_JOYHATMOTION: /* Handle Hat Motion */ gamepad.hat = event.jhat.value; if (g_state==STATE_PLAYING) { if (gamepad.hat & SDL_HAT_LEFT) { g_view->nextStation(); } if (gamepad.hat & SDL_HAT_RIGHT) { g_view->prevStation(); } } else { if (gamepad.hat & SDL_HAT_UP) { prevMenuItem(); } if (gamepad.hat & SDL_HAT_DOWN) { nextMenuItem(); } } break; case SDL_QUIT: /* Handle quit requests (like Ctrl-c). */ if ( (g_state==STATE_TITLE) && (g_menuState == MENU_MAINMENU)) { do_quit(); } else { backToTitleScreen(); } break; } } redraw(); } return 0; }
void TransIcelandicExpress::eventLoop() { while (1) { SDL_Event event; /* Grab all the events off the queue. */ while( SDL_PollEvent( &event ) ) { switch( event.type ) { case SDL_MOUSEMOTION: mouseMotion( event.motion.xrel, event.motion.yrel ); break; case SDL_KEYDOWN: switch( event.key.keysym.sym ) { case SDLK_ESCAPE: do_quit(); break; case SDLK_SPACE: printf("space\n"); break; case SDLK_1: sfx_chan[0] = Mix_PlayChannel(-1, sfx[0], 0); break; case SDLK_2: sfx_chan[1] = Mix_PlayChannel(-1, sfx[1], 0); break; case SDLK_3: sfx_chan[2] = Mix_PlayChannel(-1, sfx[2], 0); break; case SDLK_HOME: ilutGLScreenie(); break; case SDLK_h: showHelp = !showHelp; break; case SDLK_m: if (!musicOn) { printf("Playing\n"); Mix_PlayMusic( music, -1 ); musicOn = 1; } else { printf("Halting\n"); Mix_HaltMusic(); musicOn = 0; } default: break; } break; case SDL_QUIT: /* Handle quit requests (like Ctrl-c). */ do_quit(); break; } } // check non-instant keys cf_moveForward = 0.0; cf_moveSideways = 0.0; Uint8 *keys; keys = SDL_GetKeyState(NULL); if (keys[SDLK_w] && !keys[SDLK_s]) { cf_moveForward = 1.0; } if (!keys[SDLK_w] && keys[SDLK_s]) { cf_moveForward = -1.0; } if (keys[SDLK_a] && !keys[SDLK_d]) { cf_moveSideways = -1.0; } if (!keys[SDLK_a] && keys[SDLK_d]) { cf_moveSideways = 1.0; } computeTimeDelta(); simulate(); redraw(); } }