Subversion Repositories Kolibri OS

Rev

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