#include "renderer.h" #include #include GfxObject obj, background; void close(); int main( int argc, char* args[] ) { // If you want the program to not launch the terminal, then // go to Project->Settings->General->This program is a GUI application // and uncheck that flag. //Start up SDL and create window of width=800, height = 600 initRenderer(800, 600); // Create an object obj = createGfxObject( "../ship.png" ); obj.outputWidth = 200; obj.outputHeight = 200; background = createGfxObject( "../background.jpg" ); background.outputWidth = 800; background.outputHeight = 600; const Uint8 *state = SDL_GetKeyboardState(NULL); // get pointer to key states double angle = 0.0; while(true) // The real-time loop { //Handle events on the inqueue (e.g., mouse events) SDL_Event e; //Event handler while( SDL_PollEvent( &e ) != 0 ) { //User requests quit if( e.type == SDL_QUIT ) { close(); exit(0); } } // Check keyboard input // for scan codes, see here: https://wiki.libsdl.org/SDL_Scancode if (state[SDL_SCANCODE_A]) { printf("Key A is pressed.\n"); } if (state[SDL_SCANCODE_RIGHT] && state[SDL_SCANCODE_UP]) { printf("Arrow Right and Arrow Up Keys Pressed.\n"); } //Clear screen with a grey background color, red=0x33, blue=0x33, green=0x33, alpha=0xff. 0xff is maximum. SDL_SetRenderDrawColor( gRenderer, 0x33, 0x33, 0x33, 0xFF ); // alpha is transparency: 0 = fully transparent, 0xFF = fully opaque SDL_RenderClear( gRenderer ); //Render our object(s) - background objects first, and then forward objects (like a painter) angle = fmod( angle+0.02, 360 ); renderGfxObject(&background, 400, 300, angle, 1.8f+angle/50.0); renderGfxObject(&obj, 400, 300, 0, 1.0f); renderText("Hello World!", 300, 150); //Update screen. // This function also sleeps 16 ms or so (based on the screens refresh rate), because // we used the flag SDL_RENDERER_PRESENTVSYNC in function initRenderer() SDL_RenderPresent( gRenderer ); } //Free resources close(); return 0; } void close() { //Preferably, you should first free all your GfxObjects by calls to freeGfxObject(GfxObject* gfx) - but you don't have to // ... closeRenderer(); //Free resources and close SDL }