Subversion Repositories Kolibri OS

Rev

Blame | 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. -- ashmew2
  12. */
  13.  
  14. // This sample get general protection fault
  15. #define WIDTH 640
  16. #define HEIGHT 480
  17. #define BPP 4
  18. #define DEPTH 32
  19.  
  20. void setpixel(SDL_Surface *screen, int x, int y, Uint8 r, Uint8 g, Uint8 b)
  21. {
  22.     Uint32 *pixmem32;
  23.     Uint32 colour;  
  24.  
  25.     colour = SDL_MapRGB( screen->format, r, g, b );
  26.  
  27.     pixmem32 = (Uint32*) screen->pixels  + y + x;
  28.     *pixmem32 = colour;
  29. }
  30.  
  31.  
  32. void DrawScreen(SDL_Surface* screen, int h)
  33. {
  34.     int x, y, ytimesw;
  35.  
  36.     if(SDL_MUSTLOCK(screen))
  37.     {
  38.         if(SDL_LockSurface(screen) < 0) return;
  39.     }
  40.  
  41.     for(y = 0; y < screen->h; y++ )
  42.     {
  43.         ytimesw = y*screen->pitch/BPP;
  44.         for( x = 0; x < screen->w; x++ )
  45.         {
  46.             setpixel(screen, x, ytimesw, (x*x)/256+3*y+h, (y*y)/256+x+h, h);
  47.         }
  48.     }
  49.     if(SDL_MUSTLOCK(screen)) SDL_UnlockSurface(screen);
  50.  
  51.     SDL_Flip(screen);
  52. }
  53.  
  54.  
  55. int main(int argc, char* argv[])
  56. {
  57.     SDL_Surface *screen;
  58.     SDL_Event event;
  59.  
  60.     int keypress = 0;
  61.     int h=0;
  62.  
  63.     if (SDL_Init(SDL_INIT_VIDEO) < 0 ) return 1;
  64.    
  65.     if (!(screen = SDL_SetVideoMode(WIDTH, HEIGHT, DEPTH, SDL_FULLSCREEN|SDL_HWSURFACE)))
  66.     {
  67.         SDL_Quit();
  68.         return 1;
  69.     }
  70.  
  71.     while(!keypress)
  72.     {
  73.          DrawScreen(screen,h++);
  74.          while(SDL_PollEvent(&event))
  75.          {      
  76.               switch (event.type)
  77.               {
  78.                   case SDL_QUIT:
  79.                       keypress = 1;
  80.                       break;
  81.                   case SDL_KEYDOWN:
  82.                        keypress = 1;
  83.                        break;
  84.               }
  85.          }
  86.     }
  87.  
  88.     SDL_Quit();
  89.     return 0;
  90. }
  91.