Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifdef __cplusplus
- #include <cstdlib>
- #else
- #include <stdlib.h>
- #endif
- #include <SDL.h>
- const int BOK = 10;
- const int N_SZER = 600;
- const int N_WYS = 600;
- int main ( int argc, char** argv )
- {
- // initialize SDL video
- if ( SDL_Init( SDL_INIT_VIDEO ) < 0 )
- {
- printf( "Unable to init SDL: %s\n", SDL_GetError() );
- return 1;
- }
- // make sure SDL cleans up before exit
- atexit(SDL_Quit);
- // create a new window
- SDL_Surface* screen = SDL_SetVideoMode(N_SZER, N_WYS, 16,
- SDL_HWSURFACE|SDL_DOUBLEBUF);
- if ( !screen )
- {
- printf("Unable to set 640x480 video: %s\n", SDL_GetError());
- return 1;
- }
- // load an image
- SDL_Surface* bmp = SDL_LoadBMP("cb.bmp");
- if (!bmp)
- {
- printf("Unable to load bitmap: %s\n", SDL_GetError());
- return 1;
- }
- // centre the bitmap on screen
- SDL_Rect dstrect;
- dstrect.x = (screen->w - bmp->w) / 2;
- dstrect.y = (screen->h - bmp->h) / 2;
- // program main loop
- bool done = false;
- while (!done)
- {
- // message processing loop
- SDL_Event event;
- while (SDL_PollEvent(&event))
- {
- // check for messages
- switch (event.type)
- {
- // exit if the window is closed
- case SDL_QUIT:
- done = true;
- break;
- // check for keypresses
- case SDL_KEYDOWN:
- {
- // exit if ESCAPE is pressed
- if (event.key.keysym.sym == SDLK_ESCAPE)
- done = true;
- break;
- }
- } // end switch
- } // end of message processing
- // DRAWING STARTS HERE
- // clear screen
- SDL_FillRect(screen, 0, SDL_MapRGB(screen->format, 80, 80, 80));
- Uint32 kolor = SDL_MapRGB( screen->format , 0 , 255 , 255 ) ;
- for( int y = 0 ; y < N_WYS ; y++ )
- {
- for( int x = 0 ; x < N_SZER ; x++ ){
- SDL_Rect klocek = { x * ( BOK + 1 ) , y * ( BOK + 1 ) , BOK , BOK };
- SDL_FillRect( screen , &klocek , kolor );
- }
- }
- // draw bitmap
- // DRAWING ENDS HERE
- // finally, update the screen :)
- SDL_Flip(screen);
- } // end main loop
- // free loaded bitmap
- SDL_FreeSurface(bmp);
- SDL_Delay( 50 );
- // all is well ;)
- printf("Exited cleanly\n");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement