Subversion Repositories Kolibri OS

Rev

Rev 9204 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. #include "SDL.h"
  2. #include <stdlib.h>
  3.  
  4. #define WIDTH 640
  5. #define HEIGHT 480
  6. #define BPP 4
  7. #define DEPTH 32
  8.  
  9. void setpixel(SDL_Surface* screen, int x, int y, Uint8 r, Uint8 g, Uint8 b)
  10. {
  11.     Uint32* pixmem32;
  12.     Uint32 colour;
  13.  
  14.     colour = SDL_MapRGB(screen->format, r, g, b);
  15.  
  16.     pixmem32 = (Uint32*)screen->pixels + y + x;
  17.     *pixmem32 = colour;
  18. }
  19.  
  20. void DrawScreen(SDL_Surface* screen, int h)
  21. {
  22.     int x, y, ytimesw;
  23.  
  24.     if (SDL_MUSTLOCK(screen)) {
  25.         if (SDL_LockSurface(screen) < 0)
  26.             return;
  27.     }
  28.  
  29.     for (y = 0; y < screen->h; y++) {
  30.         ytimesw = y * screen->pitch / BPP;
  31.         for (x = 0; x < screen->w; x++) {
  32.             setpixel(screen, x, ytimesw, (x * x) / 256 + 3 * y + h, (y * y) / 256 + x + h, h);
  33.         }
  34.     }
  35.     if (SDL_MUSTLOCK(screen))
  36.         SDL_UnlockSurface(screen);
  37.  
  38.     SDL_Flip(screen);
  39. }
  40.  
  41. int main(int argc, char* argv[])
  42. {
  43.     SDL_Surface* screen;
  44.     SDL_Event event;
  45.  
  46.     int keypress = 0;
  47.     int h = 0;
  48.  
  49.     if (SDL_Init(SDL_INIT_VIDEO) < 0)
  50.         return 1;
  51.  
  52.     if (!(screen = SDL_SetVideoMode(WIDTH, HEIGHT, DEPTH, SDL_FULLSCREEN | SDL_HWSURFACE))) {
  53.         SDL_Quit();
  54.         return 1;
  55.     }
  56.  
  57.     while (!keypress) {
  58.         DrawScreen(screen, h++);
  59.         while (SDL_PollEvent(&event)) {
  60.             switch (event.type) {
  61.             case SDL_QUIT:
  62.                 keypress = 1;
  63.                 break;
  64.             case SDL_KEYDOWN:
  65.                 keypress = 1;
  66.                 break;
  67.             }
  68.         }
  69.     }
  70.  
  71.     SDL_Quit();
  72.     return 0;
  73. }
  74.