Okay as far as I can tell this code should work, but
for some reason it doesnt. I can’t find anything wrong
with it but I can get it to work if I take it in
pieces. What am I doing that is wrong? Thank you for
helping.
Jared
– BEGIN SOURCE CODE –
#include <stdio.h>
#include <sdl.h>
SDL_Surface
*image,*surface,*pic,*background,*screen;
SDL_Event event;
Uint8 *buffer,*keys;
int x,y;
char *filename;
int width,height;
int fps,i,r,g,b;
SDL_Color *colors;
SDL_Rect dest;
int speed,quit;
int posy,posx;
void startUp ()
{
printf(“StartUp Begin\n”);
speed = 5;
fps = 50;
pic = loadPic(“spout.bmp”);
background = loadPic(“background.bmp”);
if (SDL_Init(SDL_INIT_VIDEO) < 0 ) {
fprintf(stderr,“Problem:
%s\n”,SDL_GetError());
}
screen = SDL_SetVideoMode(640, 480, 0,
SDL_HWSURFACE|SDL_FULLSCREEN);
if ( screen == NULL ) {
fprintf(stderr, “Couldn’t set 640x480x8 video mode:
%s\n”,SDL_GetError());
exit(1);
}
if ( pic->format->palette != NULL) {
SDL_SetColors(screen, pic->format->palette->colors,
0,
pic->format->palette->ncolors);
}
pic = SDL_DisplayFormat(pic);
if (pic == NULL) {
fprintf(stderr,“Problem: %s\n”,SDL_GetError());
}
if ( SDL_MUSTLOCK(screen) ) {
if ( SDL_LockSurface(screen) < 0 )
fprintf(stderr,“Problem:
%s\n”,SDL_GetError());
}
buffer=(Uint8 )screen->pixels;
for ( i=0; ih; ++i ) {
memset(buffer,(i255)/screen->h,
screen->w*screen->format->BytesPerPixel);
buffer += screen->pitch;
}
if ( SDL_MUSTLOCK(screen) ) {
SDL_UnlockSurface(screen);
}
for ( i=0; iw; i += background->w ) {
dest.x = i;
dest.y = 0;
dest.w = background->w;
dest.h = background->h;
SDL_BlitSurface(background, NULL, screen,
&dest);
}
SDL_UpdateRect(screen, 0, 0, 0, 0);
x = (screen->w - pic->w)/2;
y = (screen->h - pic->h)/2;
setX(x,y);
printf(“Startup finished\n”);
}
SDL_Surface *loadPic(char *newName)
{
printf(“SetBMP Begin\n”);
filename = newName;
image = SDL_LoadBMP(filename);
if (image == NULL) {
fprintf(stderr,“Couldn’t load bitmap %s:
%s\n”,newName,SDL_GetError());
return NULL;
}
surface = SDL_DisplayFormat(image);
SDL_FreeSurface(image);
printf(“setBMP finished\n”);
return(surface);
}
void setX(int x2, int y2)
{
printf(“SetX:%d Y:%d Begin\n”,x2, y2);
x = x2;
y = y2;
dest.x = (x - pic->w);
dest.y = (y - pic->h);
dest.w = pic->w;
dest.h = pic->h;
if (SDL_BlitSurface(pic, NULL, screen, &dest) < 0 )
{
SDL_FreeSurface(pic);
fprintf(stderr,“Problem: %s\n”,
SDL_GetError());
}
SDL_UpdateRects(screen, 1, &dest);
printf(“setX:Y: finished\n”);
}
void shutDown ()
{
SDL_FreeSurface(pic);
SDL_FreeSurface(background);
SDL_UpdateRects(screen, 1, &dest);
SDL_Delay(3000);
exit(0);
}
main (int argc, char *argv[])
{
startUp();
transPic();
shutDown();
}
– END SOURCE CODE --__________________________________________________
Do You Yahoo!?
Talk to your friends online with Yahoo! Messenger.