Archived

This topic is now archived and is closed to further replies.

SDL - loading bmp files

This topic is 5602 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites