Sign in to follow this  
thedevil

SDL wont work

Recommended Posts

im working under mandrake 10.0 under kdevelop. my code will compile but for some reason tha is unknown to me it SDL_LoadBMP just wont work. heres my code: /* Simple blitting with SDL */ #include <SDL/SDL.h> #include <stdio.h> #include <stdlib.h> int main() { SDL_Surface *screen; SDL_Surface *image; SDL_Rect src, dest; /* Initialise and check for errors */ if (SDL_Init(SDL_INIT_VIDEO) != 0) { printf("Could not initialise SDL: %s\n", SDL_GetError()); exit(EXIT_FAILURE); } /* Ensure SDL_Quit is called when the program ends */ atexit(SDL_Quit); /* Attempt to set a 1024 x 768 32 bit video mode. */ screen = SDL_SetVideoMode(1024, 768, 32, 0); if (screen == NULL) { printf("Could not set video mode: %s\n", SDL_GetError()); exit(EXIT_FAILURE); } /* Load the bitmap file. */ puts("got to image load"); image = SDL_LoadBMP("camp.bmp"); if (image == NULL) { printf("Unable to load bitmap\n"); exit(EXIT_FAILURE); } /* Setting the Rect's */ src.x = 0; src.y = 0; src.w = image->w; // copy the entire image src.h = image->h; dest.x = 0; dest.y = 0; dest.w = image->w; dest.h = image->h; /* Blit the bitmap to the screen. */ SDL_BlitSurface(image, &src, screen, &dest); /* Ask SDL to update the entire screen */ SDL_UpdateRect(screen, 0, 0, 0, 0); /* Pause for a bit */ SDL_Delay(3000); /* Free memory */ SDL_FreeSurface(image); } it also gives mt the following error - Xlib: extension "GLX" missing on display ":0.0" Xlib: extension "GLX" missing on display ":0.0" any help ?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
What do you mean by "it won't work"?
If yout program doesn't start, you could try to replace this line:
screen = SDL_SetVideoMode(1024, 768, 32, 0);
with this one:
screen = SDL_SetVideoMode(1024, 768, 0, 0);

Share this post


Link to post
Share on other sites
what i mean by it dosen't work is that it dosent diplay the picture.

for output it write's :
got to image load
unable to load bitmap

which means that everything's good but the LoadBMP function.

Share this post


Link to post
Share on other sites
Is the bmp image RLE compressed? SDL doesn't support RLE compressed bitmaps. Try with another bitmap, or re-save your image and disable the RLE compression. If you're using gimp, this should be under "options" in the save image dialog.

-Richardo

Share this post


Link to post
Share on other sites
Try putting the BMP in the different folders in your project. That was the problem I had with KDevelope. It didn't work in having it in the same folder as the .c/cpp file. Basically, try them all. I am sure one will work.

Share this post


Link to post
Share on other sites
Yes, when using KDevelop, if you're making a debug build, your executable will be created in the /debug/src subfolder. You need to put your BMP in this subfolder, or wherever else you might move your executable.


Ryan

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this