int main( int argc, char* args[] ) { //Start up SDL and create window if( !init() ) { printf( "Failed to initialize!\n" ); } else { //Load media if( !loadMedia() ) { printf( "Failed to load media!\n" ); } else { //Main loop flag bool quit = false; //Event handler SDL_Event e; //While application is running while( !quit ) { //Handle events on queue while( SDL_PollEvent( &e ) != 0 ) { //User requests quit if( e.type == SDL_QUIT ) { quit = true; } //Handle window events gWindow.handleEvent( e ); } //Only draw when not minimized if( !gWindow.isMinimized() ) { //Clear screen SDL_SetRenderDrawColor( gRenderer, 0xFF, 0xFF, 0xFF, 0xFF ); SDL_RenderClear( gRenderer ); //Render text textures gSceneTexture.render( ( gWindow.getWidth() - gSceneTexture.getWidth() ) / 2, ( gWindow.getHeight() - gSceneTexture.getHeight() ) / 2 ); //Update screen SDL_RenderPresent( gRenderer ); } } } } //Free resources and close SDL close(); return 0; }
LuaProxy::Graphics::LuaImageResource* LuaProxy::Graphics::loadImage(const std::string& filename, lua_State* L) { /* std::wstring full_path; if (!isAbsolutePath(filename)) { full_path = getCustomFolderPath() + Str2WStr(filename); } else { full_path = Str2WStr(filename); } std::shared_ptr<BMPBox> img = std::make_shared<BMPBox>(full_path, gLunaRender.GetScreenDC()); if (img->ImageLoaded() == false) { // If image loading failed, return null return NULL; } */ std::shared_ptr<BMPBox> img = loadMedia(filename); if (img == NULL)return NULL; // Allocate a LuaImageResource to allow us to automatically garbage collect the image when no longer referenced in Lua return new LuaProxy::Graphics::LuaImageResource(img); }
int main( int argc, char* args[] ) { //Start up SDL and create window if( !init() ) { printf( "Failed to initialize!\n" ); } else { //Load media if( !loadMedia( tileSet ) ) { printf( "Failed to load media!\n" ); } else { #ifdef __EMSCRIPTEN__ emscripten_set_main_loop(loop, 0, 1); #else //While application is running while (!quit) { loop(); } SDL_Delay(100); #endif } //Free resources and close SDL close( tileSet ); } return 0; }
void ColorKeyingApp::run() { SDL_Event e; bool quit = false; if (!initApp()) { std::cout << "Failed to initialize!\n" << std::endl; } else { // Load Media if (!loadMedia()) { std::cout << "Failed to load media!\n" << std::endl; } else { //Clear screen SDL_SetRenderDrawColor( gCurrentRenderer, 0xFF, 0xFF, 0xFF, 0xFF ); SDL_RenderClear( gCurrentRenderer ); //Set rendering space and render to screen SDL_Rect renderQuad = { 0, 0, gBackgroundTexture.getWidth(), gBackgroundTexture.getHeight()}; // SDL_RenderCopy( gCurrentRenderer, gBackgroundTexture.getTexture(), NULL, &renderQuad ); // renderToScreen(gBackgroundTexture, &renderQuad); gBackgroundTexture.renderTexture(gCurrentRenderer, &renderQuad); renderQuad.x = 200; renderQuad.y =200; renderQuad.w = gCharacterTexture.getWidth(); renderQuad.h = gCharacterTexture.getHeight(); // renderToScreen(gCharacterTexture, &renderQuad); gCharacterTexture.renderTexture(gCurrentRenderer, &renderQuad); //Update screen SDL_RenderPresent( gCurrentRenderer ); while (!quit) { while (SDL_PollEvent(&e) != 0) { if (e.type == SDL_QUIT) { quit = true; std::cout << "Program quit after "<< e.quit.timestamp << " ticks!" << std::endl; } } } } } close(); }
LuaProxy::Graphics::LuaMovieResource* LuaProxy::Graphics::loadMovie(const std::string& filename, lua_State* L) { std::shared_ptr<BMPBox> img = loadMedia(filename); if (img == NULL)return NULL; // Allocate a LuaImageResource to allow us to automatically garbage collect the image when no longer referenced in Lua return new LuaProxy::Graphics::LuaMovieResource(img); }
int main(int argc, char **argv) { if (!init()) { printf("Failed to initialize \n"); } else { if (!loadMedia()) { printf("Failed to load media \n"); } else { bool quit = false; SDL_Event e; gHelloWorld = gKeyPressSurfaces[KEY_PRESS_SURFACE_DEFAULT]; while (!quit) { while (SDL_PollEvent(&e) != 0) { if (e.type == SDL_QUIT) { quit = true; } else if (e.type == SDL_KEYDOWN) { switch (e.key.keysym.sym) { case SDLK_UP: gHelloWorld = gKeyPressSurfaces[KEY_PRESS_SURFACE_UP]; break; case SDLK_DOWN: gHelloWorld = gKeyPressSurfaces[KEY_PRESS_SURFACE_DOWN]; break; case SDLK_LEFT: gHelloWorld = gKeyPressSurfaces[KEY_PRESS_SURFACE_LEFT]; break; case SDLK_RIGHT: gHelloWorld = gKeyPressSurfaces[KEY_PRESS_SURFACE_RIGHT]; break; default: gHelloWorld = gKeyPressSurfaces[KEY_PRESS_SURFACE_DEFAULT]; break; } } } SDL_BlitSurface(gHelloWorld, NULL, gScreenSurface, NULL); SDL_UpdateWindowSurface(gWindow); } } } close(); return 0; }
int main( int argc, char* args[] ) { //Start up SDL and create window if( !init() ) { printf( "Failed to initialize!\n" ); } else { //Load media if( !loadMedia() ) { printf( "Failed to load media!\n" ); } else { //Main loop flag bool quit = false; //Event handler SDL_Event e; //While application is running while( !quit ) { //Handle events on queue while( SDL_PollEvent( &e ) != 0 ) { //User requests quit if( e.type == SDL_QUIT ) { quit = true; } } //Clear screen SDL_SetRenderDrawColor( gRenderer, 0xFF, 0xFF, 0xFF, 0xFF ); SDL_RenderClear( gRenderer ); //Render background texture to screen gBackgroundTexture.render( 0, 0 ); //Render Foo' to the screen gFooTexture.render( 240, 190 ); //Update screen SDL_RenderPresent( gRenderer ); } } } //Free resources and close SDL close(); return 0; }
int main( int argc, char* args[] ) { //Start up SDL and create window if( !init() ) { printf( "Failed to initialize!\n" ); } else { //Load media if( !loadMedia() ) { printf( "Failed to load media!\n" ); } else { //Main loop flag bool quit = false; //Event handler SDL_Event e; //The dot that will be moving around on the screen Dot dot( 0, 0 ); //The dot that will be collided against Dot otherDot( SCREEN_WIDTH / 4, SCREEN_HEIGHT / 4 ); //While application is running while( !quit ) { //Handle events on queue while( SDL_PollEvent( &e ) != 0 ) { //User requests quit if( e.type == SDL_QUIT ) { quit = true; } //Handle input for the dot dot.handleEvent( e ); } //Move the dot and check collision dot.move( otherDot.getColliders() ); //Clear screen SDL_SetRenderDrawColor( gRenderer, 0xFF, 0xFF, 0xFF, 0xFF ); SDL_RenderClear( gRenderer ); //Render dots dot.render(); otherDot.render(); //Update screen SDL_RenderPresent( gRenderer ); } } } //Free resources and close SDL close(); return 0; }
Animation::Animation(int nframes,float frmHeight,float frmWidth,std::string path,SDL_Renderer* gRenderer){ gSpriteSheetTexture.loadFromFile(path,gRenderer); frame=0; numframes = nframes; frameHeight = frmHeight; frameWidth = frmWidth; timer = 0; loadMedia(); }
int main( int argc, char* args[] ) { //Start up SDL and create window if( !init() ) { printf( "Failed to initialize!\n" ); } else { //Load media if( !loadMedia() ) { printf( "Failed to load media!\n" ); } else { //Main loop flag bool quit = false; //Event handler SDL_Event e; //Current animation frame int frame = 0; //While application is running while( !quit ) { //Handle events on queue while( SDL_PollEvent( &e ) != 0 ) { //User requests quit if( e.type == SDL_QUIT ) { quit = true; } } //Clear screen SDL_SetRenderDrawColor( gRenderer, 0xFF, 0xFF, 0xFF, 0xFF ); SDL_RenderClear( gRenderer ); //Render current frame SDL_Rect* currentClip = &gSpriteClips[ frame / 4 ]; gSpriteSheetTexture.render( ( SCREEN_WIDTH - currentClip->w ) / 2, ( SCREEN_HEIGHT - currentClip->h ) / 2, currentClip ); //Update screen SDL_RenderPresent( gRenderer ); //Go to next frame ++frame; //Cycle animation if( frame / 4 >= WALKING_ANIMATION_FRAMES ) { frame = 0; } } } } //Free resources and close SDL close(); return 0; }
int main( int argc, char* args[] ) { //Start up SDL and create window if( !init() ) { printf( "Failed to initialize!\n" ); } else { //Load media if( !loadMedia() ) { printf( "Failed to load media!\n" ); } else { //Main loop flag bool quit = false; //Event handler SDL_Event e; //While application is running while( !quit ) { //Handle events on queue while( SDL_PollEvent( &e ) != 0 ) { //User requests quit if( e.type == SDL_QUIT ) { quit = true; } } //Clear screen SDL_SetRenderDrawColor( gRenderer, 0xFF, 0xFF, 0xFF, 0xFF ); SDL_RenderClear( gRenderer ); //Render test text gBitmapFont.renderText( 0, 0, "Bitmap Font:\nABDCEFGHIJKLMNOPQRSTUVWXYZ\nabcdefghijklmnopqrstuvwxyz\n0123456789" ); gBitmapFont.renderText( 0, 240, "Lazy Foo tutorials!" ); //Update screen SDL_RenderPresent( gRenderer ); } } } //Free resources and close SDL close(); return 0; }
int main( int argc, char* args[] ) { //Start up SDL and create window if( !init() ) { printf( "Failed to initialize!\n" ); } else { //Load media if( !loadMedia() ) { printf( "Unable to load media!\n" ); return 2; } //Main loop flag bool quit = false; //Event handler SDL_Event e; //Enable text input SDL_StartTextInput(); //While application is running while( !quit ) { //Handle events on queue while( SDL_PollEvent( &e ) != 0 ) { //User requests quit if( e.type == SDL_QUIT ) { quit = true; } } //Render quad render(); //Update screen SDL_GL_SwapWindow( gWindow ); } //Disable text input SDL_StopTextInput(); } //Free resources and close SDL close(); return 0; }
int main(int argc, char* args[]) { //Start up SDL and create window if (!init()) { printf("Failed to initialize!\n"); } else { //Load media if (!loadMedia()) { printf("Failed to load media!\n"); } else { //Main loop flag bool quit = false; //Event handler SDL_Event e; //While application is running while (!quit) { //Handle events on queue while (SDL_PollEvent(&e) != 0) { //User requests quit if (e.type == SDL_QUIT) { quit = true; } } //Apply the image stretched SDL_Rect stretchRect; stretchRect.x = 0; stretchRect.y = 0; stretchRect.w = SCREEN_WIDTH; stretchRect.h = SCREEN_HEIGHT; SDL_BlitScaled(gStretchedSurface, NULL, gScreenSurface, &stretchRect); //Update the surface SDL_UpdateWindowSurface(gWindow); } } } //Free resources and close SDL close(); return 0; }
int main( int argc, char* args[] ) { //Start up SDL and create window if( !init() ) { printf( "Failed to initialize!\n" ); } else { //Load media if( !loadMedia() ) { printf( "Failed to load media!\n" ); } else { //Main loop flag bool quit = false; //Event handler SDL_Event e; //While application is running while( !quit ) { //Handle events on queue while( SDL_PollEvent( &e ) != 0 ) { //User requests quit if( e.type == SDL_QUIT ) { quit = true; } } //Clear screen SDL_SetRenderDrawColor( gRenderer, 0xFF, 0xFF, 0xFF, 0xFF ); SDL_RenderClear( gRenderer ); //Render current frame gTextTexture.render( ( SCREEN_WIDTH - gTextTexture.getWidth() ) / 2, ( SCREEN_HEIGHT - gTextTexture.getHeight() ) / 2 ); //Update screen SDL_RenderPresent( gRenderer ); } } } //Free resources and close SDL close(); return 0; }
int main(int argc, char* args[]) { //Start up SDL and create window if (!init()) { printf("Failed to initialize!\n"); } else { //Load media if (!loadMedia()) { printf("Failed to load media!\n"); } else { //Main loop flag bool quit = false; //Event handler SDL_Event e; //set callback SDL_TimerID timerID = SDL_AddTimer(3 * 1000, callback, "3 seconds waited !"); while (!quit) { //Handle events on queue while (SDL_PollEvent(&e) != 0) { //User requests quit if (e.type == SDL_QUIT) { quit = true; } } //clear the screen SDL_SetRenderDrawColor(gRenderer, 0xFF, 0xFF, 0xFF, 0xFF); SDL_RenderClear(gRenderer); //render splash gSplashTexture.render(0, 0); //Update screen SDL_RenderPresent(gRenderer); } SDL_RemoveTimer(timerID); } close(); } }
int main( int argc, char* args[] ) { //Start up SDL and create window if( !init() ) { printf( "Failed to initialize!\n" ); } else { //Load media if( !loadMedia() ) { printf( "Failed to load media!\n" ); } else { //Main loop flag bool quit = false; //Event handler SDL_Event e; //While application is running while( !quit ) { //Handle events on queue while( SDL_PollEvent( &e ) != 0 ) { //User requests quit if( e.type == SDL_QUIT ) { quit = true; } } //Clear screen SDL_RenderClear( gRenderer ); //Render texture to screen SDL_RenderCopy( gRenderer, gTexture, NULL, NULL ); //Update screen SDL_RenderPresent( gRenderer ); } } } //Free resources and close SDL close(); return 0; }
int main( int argc, char* args[] ) { if (!init()) { printf("Failed to initialize!\n"); } else { //Load Media if (!loadMedia()) { printf("Failed to load media!\n"); } else { //Apply the image SDL_BlitSurface(gHelloWorld, NULL, gScreenSurface, NULL); //Update the surface SDL_UpdateWindowSurface(gWindow); //Main loop flag bool quit = false; //Event handler SDL_Event e; while (!quit) { //Handle events on queue while (SDL_PollEvent(&e) != 0) { //user Requests quit if (e.type == SDL_QUIT) { quit = true; } } //Apply the image SDL_BlitSurface(gHelloWorld, NULL, gScreenSurface, NULL); //Update the surface SDL_UpdateWindowSurface( gWindow ); } } } //Free resources and close SDL close(); return 0; }
int main(int argc, char** args) { if (init()) { if (loadMedia()) { SDL_BlitSurface(image, NULL, surface, NULL); SDL_UpdateWindowSurface(window); SDL_Delay(2000); } } // Quit SDL close(); return 0; }
int main(int argc, char* argv[]) { if (init() != true) { printf("Failed to initialize.\n"); SDL_Delay(2000); return -1; } if (loadMedia() != true) { printf("Failed to load media.\n"); SDL_Delay(2000); return -1; } // Main Loop bool quit = false; SDL_Event e; currentImageSurface = keyPressSurfaces[KEY_PRESS_SURFACE_DEFAULT]; while (!quit) { while (SDL_PollEvent(&e) != 0) { if (e.type == SDL_QUIT) { quit = true; } else if (e.type = SDL_KEYDOWN) { switch (e.key.keysym.sym) { case SDLK_UP: currentImageSurface = keyPressSurfaces[KEY_PRESS_SURFACE_UP]; break; case SDLK_DOWN: currentImageSurface = keyPressSurfaces[KEY_PRESS_SURFACE_DOWN]; break; case SDLK_LEFT: currentImageSurface = keyPressSurfaces[KEY_PRESS_SURFACE_LEFT]; break; case SDLK_RIGHT: currentImageSurface = keyPressSurfaces[KEY_PRESS_SURFACE_RIGHT]; break; default: currentImageSurface = keyPressSurfaces[KEY_PRESS_SURFACE_DEFAULT]; break; } } } SDL_BlitSurface(currentImageSurface, NULL, screenSurface, NULL); SDL_UpdateWindowSurface(window); } close(); return 0; }
int main( int argc, char* args[] ) { //Initialize FreeGLUT glutInit( &argc, args ); //Create OpenGL 2.1 context glutInitContextVersion( 2, 1 ); //Create Double Buffered Window glutInitDisplayMode( GLUT_DOUBLE ); glutInitWindowSize( SCREEN_WIDTH, SCREEN_HEIGHT ); glutCreateWindow( "textured-terrain | iquilezles.org" ); //Do post window/context creation initialization if( !initGL() ) { printf( "Unable to initialize graphics library!\n" ); return 1; } //Load graphics programs if( !loadGP() ) { printf( "Unable to load shader programs!\n" ); return 1; } //Load media if( !loadMedia() ) { printf( "Unable to load media!\n" ); return 2; } //Check for keyboard input glutKeyboardFunc( scan_keys ); glutSpecialFunc( pressKey ); glutIgnoreKeyRepeat( 1 ); glutSpecialUpFunc( releaseKey ); //Set rendering function glutDisplayFunc( render ); //Set main loop glutTimerFunc( 1000 / SCREEN_FPS, runMainLoop, 0 ); //Start GLUT main loop glutMainLoop(); return 0; }
int main( int argc, char* args[] ) { //Initialize FreeGLUT glutInit( &argc, args ); //Create OpenGL 2.1 context glutInitContextVersion( 2, 1 ); //Create Double Buffered Window glutInitDisplayMode( GLUT_DOUBLE ); glutInitWindowSize( SCREEN_WIDTH, SCREEN_HEIGHT ); glutCreateWindow( "OpenGL" ); //Do post window/context creation initialization if( !initGL() ) { printf( "Unable to initialize graphics library!\n" ); return 1; } //Load graphics programs if( !loadGP() ) { printf( "Unable to load shader programs!\n" ); return 1; } //Load media if( !loadMedia() ) { printf( "Unable to load media!\n" ); return 2; } //Set rendering function glutDisplayFunc( render ); #ifdef __AVM2__ AS3_GoAsync(); return 0; #endif //Set main loop glutTimerFunc( 1000 / SCREEN_FPS, runMainLoop, 0 ); //Start GLUT main loop glutMainLoop(); return 0; }
int main(int argc, char* args[]) { if (!init()) { printf("Failed to initialize!\n"); } else { if (!loadMedia()) { printf("Failed to load Letters!\n"); } } close(); return 0; }
int main( int argc, char* args[] ) { //Start up SDL and create window if( !init() ) { printf( "Failed to initialize!\n" ); } else { //Load media if( !loadMedia() ) { printf( "Failed to load media!\n" ); } else { //Main loop flag bool quit = false; //Event handler SDL_Event e; //While application is running while( !quit ) { //Handle events on queue while( SDL_PollEvent( &e ) != 0 ) { //User requests quit if( e.type == SDL_QUIT ) { quit = true; } //Joystick button press else if( e.type == SDL_JOYBUTTONDOWN ) { //Play rumble at 75% strenght for 500 milliseconds if( SDL_HapticRumblePlay( gControllerHaptic, 0.75, 500 ) != 0 ) { printf( "Warning: Unable to play rumble! %s\n", SDL_GetError() ); } } } //Clear screen SDL_SetRenderDrawColor( gRenderer, 0xFF, 0xFF, 0xFF, 0xFF ); SDL_RenderClear( gRenderer ); //Render splash image gSplashTexture.render( 0, 0 ); //Update screen SDL_RenderPresent( gRenderer ); } } } //Free resources and close SDL close(); return 0; }
int main( int argc, char* args[] ) { //Start up SDL and create window if( !init() ) { printf( "Failed to initialize!\n" ); } else { //Load media if( !loadMedia() ) { printf( "Failed to load media!\n" ); } else { //Main loop flag bool quit = false; //The dot that will be moving around on the screen Dot dot; //While application is running while( !quit ) { //Handle events on queue //Move the dot dot.move(); //Clear screen SDL_SetRenderDrawColor( gRenderer, 0xFF, 0xFF, 0xFF, 0xFF ); SDL_RenderClear( gRenderer ); //Render objects dot.render(); //Update screen SDL_RenderPresent( gRenderer ); } } } //Free resources and close SDL close(); return 0; }
int sdl3Main() { //Start up SDL and create window if( !init() ) { printf( "Failed to initialize!\n" ); } else { //Load media if( !loadMedia() ) { printf( "Failed to load media!\n" ); } else { //Main loop flag bool quit = false; //Event handler SDL_Event e; //While application is running while( !quit ) { //Handle events on queue while( SDL_PollEvent( &e ) != 0 ) { //User requests quit if( e.type == SDL_QUIT ) { quit = true; } } //Apply the image SDL_BlitSurface( gHelloWorld, NULL, gScreenSurface, NULL ); //Update the surface SDL_UpdateWindowSurface( gWindow ); } } } //Free resources and close SDL close(); return 0; }
int main(int argc, const char * argv[]) { init(); loadMedia(); bool quit = false; SDL_Event e; int frame = 0; int scrollingOffset = gameState.scrollingOffset; while (!quit) { while (SDL_PollEvent(&e) != 0) { if (e.type == SDL_QUIT) { quit = true; } batman->handleEvent(e); } SDL_SetRenderDrawColor(gRenderer, 0xFF, 0xFF, 0xFF, 0xFF); SDL_RenderClear(gRenderer); // load background first with offset if (batman->isMovingFwd()) { -- scrollingOffset; if (scrollingOffset < -gBackGroundTexture.getWidth()) { scrollingOffset = 0; } } gBackGroundTexture.render(scrollingOffset, 0, gRenderer); gBackGroundTexture.render(scrollingOffset + gBackGroundTexture.getWidth(), 0, gRenderer); batman->render(50, SCREEN_HEIGHT - 60); SDL_RenderPresent(gRenderer); } // save game state gameState.scrollingOffset = scrollingOffset; printf("saving game state: scrolling offset %d\n", gameState.scrollingOffset); // close close(); return 0; }
// add "int argc, char *args[]" for cross-compat int main (void) { if (!initSDL()) { fprintf(stderr, "Failed to initialize SDL!\n"); } else { if (!loadMedia()) { fprintf(stderr, "Failed to load media!\n"); } else { mainLoop(); } } closeSDL(); return 0; }
int engine_init(SDL_Window** window, SDL_Renderer** renderer, Resources** resources) { int flags; //{ region init flags = SDL_INIT_EVERYTHING; if(SDL_Init(flags) != 0) { LOG("SDL init error: %s", SDL_GetError()); return 1; } flags = IMG_INIT_PNG; if(IMG_Init(flags) & flags != flags) { LOG("IMG init error: %s", IMG_GetError()); return 1; } if(TTF_Init() != 0) { LOG("TTF init error %s", TTF_GetError()); return 1; } //} random_init(); (*window) = SDL_CreateWindow("Lines", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN); if((*window) == NULL) { LOG("Window could not be created! SDL_Error: %s\n", SDL_GetError()); return 1; } (*renderer) = SDL_CreateRenderer((*window),-1,SDL_RENDERER_ACCELERATED); if((*renderer) == NULL) { LOG("Renderer could not be created! SDL Error: %s\n", SDL_GetError() ); return 1; } (*resources) = loadMedia(*renderer); return 0; }
bool MainState::init(Game* game) { mFont = NULL; mPaddleHitSound = NULL; mWallHitSound = NULL; mPlayer1Score = 0; mPlayer2Score = 0; mLockBallCollisionCheck = false; loadMedia(game); loadObjects(); return true; }
bool init() { if (SDL_Init(SDL_INIT_VIDEO)<0) { printf("SDL init failure.\n"); return false;} if (SDLNet_Init()<0) printf("SDL net init failure.\n"); int initFlags = IMG_INIT_PNG; if (!(IMG_Init(initFlags) & initFlags)) { printf("IMG init failure.\n"); return false;} if (!loadMedia()) { printf("Couldn't load meida.\n"); return false;} udpSendSock = SDLNet_UDP_Open(0); udpRecvSock = SDLNet_UDP_Open(0); if (udpSendSock == NULL || udpRecvSock == NULL) { printf("Couldn't open UDP sockets.\n"); return false;} IPaddress serverIP; SDLNet_ResolveHost(&serverIP, NULL, 4444); TCPsock = SDLNet_TCP_Open(&serverIP); if (TCPsock==NULL) { printf("Couldn't open TCP socket.\n"); return false;} packetOut = SDLNet_AllocPacket(1024); //packetOut->data=gameData; return true; }