LJ Archive

Listing 3. Drawing Large Amounts of Data to the Screen

#include <SDL/SDL.h>
#include <stdio.h>
#include <stdlib.h>
int main()
{
    SDL_Surface *screen;
    SDL_Surface *image;
    SDL_Rect src,dest;
    /* Initialization code, just like the
       previous example's. */
    /* Load the bitmap file. SDL_LoadBMP returns a
       pointer to a
       new surface containing the loaded image. */
    image = SDL_LoadBMP("tux.bmp");
    if (image == NULL) {
        printf("Unable to load bitmap.\n");
        return 1;
    };
    /* The SDL blitting function needs to know how
       much data to copy. We provide this with
       SDL_Rect structures, which define the
       source and destination rectangles. The
       areas should be the same; SDL does not
       currently handle image stretching. */
    src.x = 0; src.y = 0;
    src.w = image->w;    /* copy the entire image */
    src.h = image->h;
    dest.x = 0; dest.y = 0;
    dest.w = image->w;
    dest.h = image->h;
    /* Draw the bitmap to the screen. We are using
       a hicolor video mode, so we don't have to
       worry about colormap silliness. It is not
       necessary to lock surfaces before blitting;
       SDL will handle that. */
    SDL_BlitSurface(image,&src,screen,&dest);
    /* Ask SDL to update the entire screen. */
    SDL_UpdateRect(screen,0,0,0,0);
    /* Pause for a few seconds as the viewer gasps
       in awe. */
    SDL_Delay(3000);
    /* Free the memory that was allocated to the
       bitmap. */
    SDL_FreeSurface(image);
    return 0;
}
LJ Archive