使用SDL打造游戏世界之入门篇 - 图文 联系客服

发布时间 : 星期五 文章使用SDL打造游戏世界之入门篇 - 图文更新完毕开始阅读

// Initialize SDL's subsystems - in this case, only video. if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, \to init SDL: %s\\n\SDL_GetError()); exit(1); } // Register SDL_Quit to be called at exit; makes sure things are // cleaned up when we quit. atexit(SDL_Quit); // Attempt to create a 640x480 window with 32bit pixels. screen = SDL_SetVideoMode(640, 480, 32, SDL_SWSURFACE); // If we fail, return error. if ( screen == NULL ) { fprintf(stderr, \video: %s\\n\ exit(1); } // Main loop: loop forever. while (1) { // Render stuff render(); // Poll for events, and handle the ones we care about. SDL_Event event; while (SDL_PollEvent(&event)) { switch (event.type) { case SDL_KEYDOWN: break; case SDL_KEYUP: // If escape is pressed, return (and thus, quit) if (event.key.keysym.sym == SDLK_ESCAPE) return 0; break; case SDL_QUIT: return(0); } } } return 0; } (责任编辑:尹聪颖)