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!
<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!