1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
   |  
#include "img.h"
#include <stdio.h>
#include <unistd.h>
#include "SDL.h"
 
void putPixel(SDL_Surface * surface, Uint16 x, Uint16 y, Uint32 color)
{
    /* Nombre de bits par pixels de la surface d'écran */
    Uint8 bpp = surface->format->BytesPerPixel;
    /* Pointeur vers le pixel à remplacer (pitch correspond à la taille
 *        d'une ligne d'écran, c'est à dire (longueur * bitsParPixel)
 *               pour la plupart des cas) */
    Uint8 * p = ((Uint8 *)surface->pixels) + y * surface->pitch + x * bpp;
     switch(bpp)
    {
          case 1:
                *p = (Uint8) color;
                break;
        case 2:
            *(Uint16 *)p = (Uint16) color;
            break;
        case 3:
            if (SDL_BYTEORDER == SDL_BIG_ENDIAN)
            {
                *(Uint16 *)p = ((color >> 8) & 0xff00) | ((color >> 8) & 0xff);
                *(p + 2) = color & 0xff;
            }
            else
            {
                *(Uint16 *)p = color & 0xffff;
                *(p + 2) = ((color >> 16) & 0xff) ;
            }
            break;
        case 4:
            *(Uint32 *)p = color;
            break;
    }
}
 
int main(int argc, char * argv[])
{
    unsigned long offset=0;
    SDL_Surface * screen;
    SDL_Surface * image, * tmp;
    SDL_Rect blitrect = {0, 0, 0, 0};
    int i, j;
     if (SDL_Init(SDL_INIT_VIDEO) == -1)
    {
        printf("Erreur lors de l'initialisation de SDL: %s\n", SDL_GetError());
        return 1;
    }
 
    #define SDL_VIDEO_FLAGS (SDL_HWSURFACE | SDL_DOUBLEBUF | SDL_ANYFORMAT)
 
    screen = SDL_SetVideoMode(800, 600, 24,
                              SDL_VIDEO_FLAGS);
 
    printf("Mode vidéo: dx%d\n", screen->w, screen->h,
           screen->format->BitsPerPixel);
   SDL_LockSurface(screen);
 
//   SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0x00, 0x00, 0xff));
 
   for (j = 0; j < screen->h; j++)
        for (i = 0; i < screen->w; i++)
            putPixel(screen, i, j, SDL_MapRGB(screen->format, bob_image[offset++], bob_image[offset++], bob_image[offset++]));
 
 
    SDL_UnlockSurface(screen);
    SDL_Flip(screen);
    sleep(5);
} | 
Partager