Recommended Posts

firstly ... I am aware of the "Alternate Libraries" forum but I think this thread belongs in the Beginners area because of what I am asking ;)
anyways ...
I have a bunch of SDL_Surface pointer which hold a surface to be drawn, here is one of them:

SDL_Surface* Selection = SDL_LoadBMP("Data\\Selection.bmp");

Now, I want to have the initialisation of all of them in a seperate function, so I modified the code like so:

Share this post

Link to post

Share on other sites

so what happens when you run it..the surface is still null? you should check and see if everything went alright...because if they work like the first method..then they should also work with the second..

Share this post

Link to post

Share on other sites

Original post by xyuriWhat can I say except, errrr, that function works quite well ...

Is there a reason why my original (disfunctional) method doesnt work?

EDIT:

That still doesnt solve my problem though ... I want to pass a surface to a function and have it set the graphics and whatnot :(

Hrm. Well, I'm not entirely sure what you're trying to accomplish. I'm guessing you want to pass a null SDL_Surface pointer into a function, and have the function load the bmp file? I don't see any reason to do it like that, though. First off, you'de still need to pass a filename to the function so you can pass something to SDL_LoadBMP. My brain seems to be quite broken lately though, so its quite possible that I'm missing your point!

Share this post

Link to post

Share on other sites

Questions as to why you're doing it this way aside, your problem, if I understand you correctly, is that you are assigning the loaded bmp to the local copy of the pointer, which means you have a leak when the code exits. You need either a reference to the pointer (C++-style):

Share this post

Link to post

Share on other sites

Are you sure it doesn't load the bitmap?Be sure by if (Selection) (After InitSurfaces) or check for errors (i dont know SDL so i dont know how to check, but i'm sure there is a way).Edit: Or you can load the bitmap without InitSurfaces and see if now you can see the image in the window.(And I hope you didn't missed my reply!)

DrawSurface() and InitSDL() should be defined also, but I guess you know how to do that. As you said you had a white screen, don't forget to "Flip" your screen, that could be the problem (I know i had that a couple of times...)

Joshua

0

Share this post

Link to post

Share on other sites

If you are using the double pointer method then simple passing the pointer into the function work - it shouldn't even compile. Instead make sure you are passing the address of the pointer using the & operator like so:

SDL_Surface *Foo = NULL;InitSurfaces(&Foo);

0

Share this post

Link to post

Share on other sites

Another thing: Shouldn't you specify forward slashes for filenames, not an escaped backslash? I know Unix systems use the forward slashes and Windows the backslash, but I work on Windows and it doesn't seem to have any issues with paths with forward slashes - that said, I've only tried with SDL_LoadBMP, IMG_Load and fopen.

0

Share this post

Link to post

Share on other sites

Original post by benryvesAnother thing: Shouldn't you specify forward slashes for filenames, not an escaped backslash? I know Unix systems use the forward slashes and Windows the backslash, but I work on Windows and it doesn't seem to have any issues with paths with forward slashes - that said, I've only tried with SDL_LoadBMP, IMG_Load and fopen.

If it is up to the OS (Windows), then you can use both / or \\ (which mean, \).Well, at least in my XP.