Advertisement
Guest User

Untitled

a guest
Nov 21st, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.58 KB | None | 0 0
  1. #ifdef __cplusplus
  2. #include <cstdlib>
  3. #else
  4. #include <stdlib.h>
  5. #endif
  6.  
  7. #include <SDL.h>
  8.  
  9. const int BOK = 10;
  10. const int N_SZER = 600;
  11. const int N_WYS = 600;
  12.  
  13.  
  14.  
  15. int main ( int argc, char** argv )
  16. {
  17. // initialize SDL video
  18. if ( SDL_Init( SDL_INIT_VIDEO ) < 0 )
  19. {
  20. printf( "Unable to init SDL: %s\n", SDL_GetError() );
  21. return 1;
  22. }
  23.  
  24. // make sure SDL cleans up before exit
  25. atexit(SDL_Quit);
  26.  
  27. // create a new window
  28. SDL_Surface* screen = SDL_SetVideoMode(N_SZER, N_WYS, 16,
  29. SDL_HWSURFACE|SDL_DOUBLEBUF);
  30. if ( !screen )
  31. {
  32. printf("Unable to set 640x480 video: %s\n", SDL_GetError());
  33. return 1;
  34. }
  35.  
  36. // load an image
  37. SDL_Surface* bmp = SDL_LoadBMP("cb.bmp");
  38. if (!bmp)
  39. {
  40. printf("Unable to load bitmap: %s\n", SDL_GetError());
  41. return 1;
  42. }
  43.  
  44. // centre the bitmap on screen
  45. SDL_Rect dstrect;
  46. dstrect.x = (screen->w - bmp->w) / 2;
  47. dstrect.y = (screen->h - bmp->h) / 2;
  48.  
  49. // program main loop
  50. bool done = false;
  51. while (!done)
  52. {
  53. // message processing loop
  54. SDL_Event event;
  55. while (SDL_PollEvent(&event))
  56. {
  57. // check for messages
  58. switch (event.type)
  59. {
  60. // exit if the window is closed
  61. case SDL_QUIT:
  62. done = true;
  63. break;
  64.  
  65. // check for keypresses
  66. case SDL_KEYDOWN:
  67. {
  68. // exit if ESCAPE is pressed
  69. if (event.key.keysym.sym == SDLK_ESCAPE)
  70. done = true;
  71. break;
  72. }
  73. } // end switch
  74. } // end of message processing
  75.  
  76. // DRAWING STARTS HERE
  77.  
  78. // clear screen
  79. SDL_FillRect(screen, 0, SDL_MapRGB(screen->format, 80, 80, 80));
  80. Uint32 kolor = SDL_MapRGB( screen->format , 0 , 255 , 255 ) ;
  81.  
  82. for( int y = 0 ; y < N_WYS ; y++ )
  83. {
  84. for( int x = 0 ; x < N_SZER ; x++ ){
  85. SDL_Rect klocek = { x * ( BOK + 1 ) , y * ( BOK + 1 ) , BOK , BOK };
  86. SDL_FillRect( screen , &klocek , kolor );
  87.  
  88. }
  89. }
  90.  
  91.  
  92.  
  93.  
  94. // draw bitmap
  95.  
  96.  
  97. // DRAWING ENDS HERE
  98.  
  99. // finally, update the screen :)
  100. SDL_Flip(screen);
  101. } // end main loop
  102.  
  103. // free loaded bitmap
  104. SDL_FreeSurface(bmp);
  105. SDL_Delay( 50 );
  106. // all is well ;)
  107. printf("Exited cleanly\n");
  108. return 0;
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement