SDL - loading bmp files

Started by
1 comment, last by Dalik 21 years, 8 months ago
I ran into a problem that seems to work but it doesnt here is the code that tries to load the bmp file and sends it to be displayed // in process function display_bmp("data/blast.bmp"); // display_bmp function void display_bmp(char *file_name) { SDL_Surface *image; SDL_Surface *screen; /* Load the BMP file into a surface */ image = SDL_LoadBMP(file_name); if (image == NULL) { fprintf(stderr, "Couldn''t load %s: %s\n", file_name, SDL_GetError()); return; } /* * Palettized screen modes will have a default palette (a standard * 8*8*4 colour cube), but if the image is palettized as well we can * use that palette for a nicer colour matching */ if (image->format->palette && screen->format->palette) { SDL_SetColors(screen, image->format->palette->colors, 0, image->format->palette->ncolors); } /* Blit onto the screen surface */ if(SDL_BlitSurface(image, NULL, screen, NULL) < 0) { fprintf(stderr, "BlitSurface error: %s\n", SDL_GetError()); } SDL_UpdateRect(screen, 0, 0, image->w, image->h); /* Free the allocated BMP surface */ SDL_FreeSurface(image); } well what it should do is load the blast.bmp file then blit it to the screen, but the error log either says it cant open or load the file or gives me this : Fatal signal: Segmentation Fault (SDL Parachute Deployed) I dont know what that means any ideas?
Interested in being apart of a team of people that are developing a toolkit that can help anyone product an online game? Then click here http://tangle.thomson.id.au/
Advertisement
Well I have been going over my code and its not the loading of the bmp but the blit function its not finishing so I think I have to do something that I havent done yet.
Interested in being apart of a team of people that are developing a toolkit that can help anyone product an online game? Then click here http://tangle.thomson.id.au/
I think it''s the two NULLs in your SDL_BlitSurface. The first NULL should be the SDL_Rect of the image you want to blit. Here HAVE TO specify the width and height, and also you have to specify the x and y position. If you leave this NULL you do not indicate a area of imgaes that should be copied onto the screen surface.
The second NULL is the target area on the screen, where you only have to specify the x and y position (because the width and height has to be identical to the part of the images you copy). If you leave this NULL you do not indicate where the image should appear on the screen.

This topic is closed to new replies.

Advertisement