/* Example of simple blitting with SD>. */ #include #include #include int main() { SDL_Surface *screen; SDL_Surface *image; SDL_Rect src, dest; /* init and check for errors*/ if (SDL_Init(SDL_INIT_VIDEO) != 0) { printf("Unable to init SDL: %s\n", SDL_GetError()); return 1; } atexit(SDL_Quit); /* 256x256 hicolor (16-bit) */ screen = SDL_SetVideoMode(512, 512, 32, 0); // finding BMPs is hard // Doesn't work anyway... //I seem to remem ber having htis problem before if (screen == NULL) { printf("Setting video mode failed: %s\n", SDL_GetError()); return 1; } /* Load bitmap file. SDL_LoadBMP returns a pointer to a new surface containing * the loaded image. */ image = SDL_LoadBMP("test-image.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 * shoul be the same; SDL does not currently handle image * stretching. */ src.x = 0; src.y = 0; src.w = image->w; /* copy entire image */ src.h = image->h; /* Draw the bitmap to the screen. It is not necessary to lock surfaces * before blitting; SDL will handle that. */ SDL_BlitSurface(image, &src, screen, &dest); SDL_Delay(3000); /* Free memory allocated to the bitmap. */ SDL_FreeSurface(image); return 0; }