Subversion Repositories Kolibri OS

Rev

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

  1. /* Instructions to compile this file with newlib (Assuming you have set up environment
  2.  
  3. kos32-gcc -c -I/home/bob/kolibrios/contrib/sdk/sources/newlib/libc/include -I/home/bob/kolibrios/contrib/sdk/sources/libpng/ -I/home/bob/kolibrios/contrib/sdk/sources/zlib -I/home/bob/kolibrios/contrib/sdk/sources/freetype/include -I/home/bob/kolibrios/contrib/sdk/sources/freetype/include -I/home/bob/kolibrios/contrib/sdk/sources/SDL-1.2.2/include/ -std=c99 -D_KOLIBRIOS -Dnskolibrios -g   -Wundef   -U_Win32 -U_WIN32 -U__MINGW32__ SDLTest.c
  4.  
  5.   kos32-ld SDLTest.o -T/home/bob/kolibrios/contrib/sdk/sources/newlib/libc/app.lds -nostdlib -static --image-base 0 -lgcc -L/home/autobuild/tools/win32/mingw32/lib /home/autobuild/tools/win32/lib/libdll.a /home/autobuild/tools/win32/lib/libapp.a /home/autobuild/tools/win32/lib/libSDL.a /home/autobuild/tools/win32/lib/libc.dll.a -static -o sdltest
  6.  
  7. objcopy -O binary sdltest
  8.  
  9. Now sdltest is your binary to run on Kolibri for SDL Demo.
  10.  
  11. */
  12.  
  13. #include <stdio.h>
  14. #include <SDL.h>
  15.  
  16. #define WIDTH 640
  17. #define HEIGHT 480
  18. #define BPP 4
  19. #define DEPTH 32
  20.  
  21. void setpixel(SDL_Surface *screen, int x, int y, Uint8 r, Uint8 g, Uint8 b)
  22. {
  23.     Uint32 *pixmem32;
  24.     Uint32 colour;  
  25.  
  26.     colour = SDL_MapRGB( screen->format, r, g, b );
  27.  
  28.     pixmem32 = (Uint32*) screen->pixels  + y + x;
  29.     *pixmem32 = colour;
  30. }
  31.  
  32.  
  33. void DrawScreen(SDL_Surface* screen, int h)
  34. {
  35.     int x, y, ytimesw;
  36.  
  37.     if(SDL_MUSTLOCK(screen))
  38.     {
  39.         if(SDL_LockSurface(screen) < 0) return;
  40.     }
  41.  
  42.     for(y = 0; y < screen->h; y++ )
  43.     {
  44.         ytimesw = y*screen->pitch/BPP;
  45.         for( x = 0; x < screen->w; x++ )
  46.         {
  47.             setpixel(screen, x, ytimesw, (x*x)/256+3*y+h, (y*y)/256+x+h, h);
  48.         }
  49.     }
  50.     if(SDL_MUSTLOCK(screen)) SDL_UnlockSurface(screen);
  51.  
  52.     SDL_Flip(screen);
  53. }
  54.  
  55.  
  56. int main(int argc, char* argv[])
  57. {
  58.     SDL_Surface *screen;
  59.     SDL_Event event;
  60.  
  61.     int keypress = 0;
  62.     int h=0;
  63.  
  64.     if (SDL_Init(SDL_INIT_VIDEO) < 0 ) return 1;
  65.    
  66.     if (!(screen = SDL_SetVideoMode(WIDTH, HEIGHT, DEPTH, SDL_FULLSCREEN|SDL_HWSURFACE)))
  67.     {
  68.         SDL_Quit();
  69.         return 1;
  70.     }
  71.  
  72.     while(!keypress)
  73.     {
  74.          DrawScreen(screen,h++);
  75.          while(SDL_PollEvent(&event))
  76.          {      
  77.               switch (event.type)
  78.               {
  79.                   case SDL_QUIT:
  80.                       keypress = 1;
  81.                       break;
  82.                   case SDL_KEYDOWN:
  83.                        keypress = 1;
  84.                        break;
  85.               }
  86.          }
  87.     }
  88.  
  89.     SDL_Quit();
  90.  
  91.     return 0;
  92. }
  93.