[SDL] grief loading/getting xpm in function with char *
Ulrich Eckhardt
doomster at knuut.de
Sat Mar 8 08:21:35 PST 2008
On Saturday 08 March 2008 09:23, neil at cloudsprinter.com wrote:
> SDL_Surface *getimage(int mask , char *name )
> {
> /snip/
> strcat(name, "_xpm");
> surface=IMG_ReadXPMFromArray(name);
> /snip/
> };
^ wrong!
> >> which gives warning: passing argument 1 of ?IMG_ReadXPMFromArray?
> >> from incompatible pointer type
> i have a .h file being loaded/used with the arrays like this
>
>
> static char *backg3_xpm[] = {
> /* columns rows colors chars-per-pixel */
> "200 200 256 2",
> " c #151417",
> ". c #071835",
This looks like an XPM, which actually is a snippet of C code! Now, what you
want to do is pass this (backg3_xpm) to IMG_ReadXPMFromArray(). Note that
this is an array of pointers while you 'name' variable is a pointer. I'm
pretty sure you also couldn't call getimage(backg3_xpm[n]) either and with a
similar error.
> i appended the _xpm because some of the image names are the same as thier
> surfaces
This doesn't make sense to me either. FYI, IMG_ReadXPMFromArray() requires
that you pass it an array, just like the one of the XPM. If you want to read
a file and 'name' is the filename, then you want to use IMG_Load() instead.
In no case can I imagine that you have to add anything anywhere, and
particularly not at runtime.
> if i use IMG_ReadXPMFromArray( backg3_xpm ); it will load fine, but i need
> to make a function that i can use custom names, which i am failing on
What is 'custom names'? The question what is correct simply depends on whether
you embed the XMP (remember, it's C code!) or if you want to load it from
file.
BTW: there is too much guessing going on here, and that is the result of not
having the relevant info. What you should have done is create a minimal
program that only loads your bitmap, outputs success/failure and exits. There
should not be a single line that could still be removed. Then, you firstly
have the problem pinned down to the smallest possible amount of code (which
is helpful for you to understand it) and secondly you have exactly the amount
of code that you should post here so others can try it and give you precise
help without guessing.
One last thing: Your initial mail was written by answering a totally unrelated
mail and then erasing the subject line. This is called "stealing threads" and
a bad thing (do a websearch). Now, this mail of yours seems to be not a reply
at all, which is also bad for the same reasons.
cheers!
Uli
More information about the SDL
mailing list