Hello everyone. I know the book says it is for linux programming but since
SDL is a cross platform API I figured most of the examples would work with
little adjustment. Well on the first bliting example I have a problem. First
I am using, WinXP, MSVC-6, SDL 1.2.4. Here is the code:
// Example of simple blitting with SDL
#include “SDL.h”
#include <stdio.h>
#include <stdlib.h>
int main( int argc, char* argv[] ) // added the (int argc, char* argv[]) so
it would compile on Win32
{
SDL_Surface *screen;
SDL_Surface *image;
SDL_Rect src, dest;
// Initialize SDL's video system and check for errors.
if (SDL_Init(SDL_INIT_VIDEO) != 0 ) {
printf("Unable to initialize SDL: %s\n", SDL_GetError());
return 1;
}
// Make sure SDL_Quit gets called when the program exits
atexit(SDL_Quit);
// Attempt to set a 256 x 256 hicolor (16-bit) video mode.
// Since that is rarely a valid mode SDL with emulate
screen = SDL_SetVideoMode(256, 256, 16, 0);
if (screen == NULL) {
printf("Unable to set video mode: %s\n", SDL_GetError());
return 1;
}
// Load the bitmap file. SDL_LoadBMP returns a pointer to a
// new surface containing the loaded BMP
image = SDL_LoadBMP("test.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 currntly handle image
// stretching.
src.x = 0;
src.y = 0;
src.w = image->w;
src.y = 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
SDL_Delay(3000);
// Free the memory that was allocated to the bitmap
SDL_FreeSurface(image);
return 0;
}
Ok, the problem I have is this; the program runs without errors (initializes
the video system and loads the bmp). The screen is displayed in a 256 x 256
window but the bmp image does not display. I am using a 256 x 256 bmp image
created with GIMP. I am stumped as to why it wouldn’t be displaying. Any
suggestions out there are welcome. Thanks.
Steven Bradley
"Now that I have wasted this much of your time, you will have to code faster
to catch up!"