Yet _another_ Xcode/SDL Problem :(

Joined
Jun 11, 2009
Messages
5
Reaction score
0
Points
1
So I'm positive the following code is correct, as I can compile SDL on my mbp using the g++ gnu compiler. What I can't do is get it to work via Xcode.

<code/>
#include "SDL/SDL.h"
#include "SDL_image/SDL_image.h"

int main(int argc,char* args[]) {
SDL_Surface* window = NULL;
SDL_Surface* screen = NULL;

SDL_Init(SDL_INIT_EVERYTHING);
window = SDL_SetVideoMode(640,480,32,SDL_SWSURFACE);
SDL_WM_SetCaption("Why doesn't this work in XCode?!", NULL);
screen = IMG_Load("screen.png");
SDL_Rect tempRect;
tempRect.x = 0;
tempRect.y = 0;
SDL_BlitSurface(screen,NULL,window,&tempRect);
SDL_Flip(window);
SDL_Delay(2000);
SDL_Quit();
return 0;
}
</code>

Compiling with g++ yields a two second window popping up containing my screen.png (but the Caption doesn't load, nor do the window buttons...)
However, when I "build and go" in Xcode I get a two second window without contents nor caption, but the x - + buttons show up, (unlike the compiled version that 'works')
In Xcode I've made sure that I've linked SDL and SDL_image frameworks, and I've changed #include "SDL.h" to #include "SDL/SDL.h" and placed both SDLmain.h and SDLmain.m in the project directory.
I think it's a problem with IMG_Load, but I can't figure it out.

The command I'm using to compile is:
g++ -I/Library/Frameworks/SDL.framework/Headers main.cpp SDLmain.m -framework SDL -framework Cocoa -framework SDL_image

Any help is appreciated!
 
OP
Q
Joined
Jun 11, 2009
Messages
5
Reaction score
0
Points
1
Solved

So my problem is the default path Xcode uses when it looks for files.
The line:
screen = IMG_Load("screen.png");

should have been:
screen = IMG_Load("/ultimate/path/to/file/screen.png");

Note: using ("./screen.png") doesn't work either, and there is a way to tell Xcode where to search via the Project > Edit Active Target 'X' > SearchPaths section. But I'd rather be explicit about it.

And the caption problem is a noob mistake, SDL_WM_SetCaption has to be called before calling window=SDL_SetVideoMode. D'uh. <)
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top