// Hello world in SDL
#include <SDL.h>
int main(int argc, char* argv[]) {
// Initialize the SDL and video subsystem
if (SDL_Init( SDL_INIT_VIDEO ) < 0) {
return -1;
}
// Signal SDL to change main window text to "Hello World"
SDL_WM_SetCaption("Hello World","Hello World");
// Create SDL surface to represent game window
SDL_Surface* screen = SDL_SetVideoMode(640,480,0,0);
// Load the logo to temporary surface
SDL_Surface* temp = SDL_LoadBMP("data\\textures\\sdl_logo.bmp");
// Create working SDL_Surface to match temp display format
SDL_Surface* bg = SDL_DisplayFormat(temp);
// Free temp memory allocated to temp SDL_Surface
SDL_FreeSurface(temp);
SDL_Event event;
bool quit = false;
// Main message loop of the game
while (!quit) {
// Check message queue for an event
if (SDL_PollEvent(&event)) {
// If event was found
switch (event.type) {
case SDL_QUIT: quit = true;
break;
case SDL_KEYDOWN: switch (event.key.keysym.sym) {
case SDLK_ESCAPE: quit = true;
break;
}
break;
}
}
// Draw background sprite
SDL_BlitSurface(bg,NULL,screen,NULL);
// Update current window
SDL_UpdateRect(screen,0,0,0,0);
}
// Free allocated memory for background surface
SDL_FreeSurface(bg);
// Quit SDL and allow it to do clean up
SDL_Quit();
// Return control to windows with no errors
return 0;
}
It compiles fine, the issue appears when it tries to link. I'm using VC6 on windows, and VC express 2008. Both give the same problem.
I think its something to do with directories or what and I've added the libraries and header files to the directories but I just dont know what to do to get it to work.
I have started with SDL yesterday, so i dont can help you any further. My guess is that you arent referring to... well, i dont know to what exactly :). I use dev-cpp on windows, and i have to create a project and add "-lmingw32 -lSDLmain -lSDL" to the parameters of the project, as dicribed in the second link.
Yea, I'm not sure where I went wrong but I added the SDL. files to the folders where the .exe was and re-linked the files in directory following the links. It seems to work now; not sure which one the problem was but for now I'm happy with it working.