This is probably amateur-ish, but I've been going through the Lazy Foo Productions tutorials to learn how to use SDL, but since I'm such a stubborn programmer I decided to write my code in C rather than C++, everything I've been doing up unitl a certain point, works. But then I got tired of writing the same functions and variables, over and over again, so I decided to create a header to declare my global Macros and functions and intialized those in a C source file, problem is, I get some weird compiling errors now:
Code:
#ifndef SDL_TUTORIAL_HANDLER_H_INCLUDED
#define SDL_TUTORIAL_HANDLER_H_INCLUDED
#include "SDL/SDL.h"
#include "SDL/SDL_image.h"
#define SCREEN_WIDTH 640
#define SCREEN_HEIGHT 480
#define SCREEN_BPP 32
#define TRUE 1
#define FALSE 0
SDL_Surface *load_image( char* filename );
void apply_surface( int Pos_X, int Pos_Y, SDL_Surface* source, SDL_Surface* destination );
typedef int Bool;
Bool init();
Bool load_files();
void clean_up();
#endif // SDL_TUTORIAL_HANDLER_H_INCLUDED
This is all fine, but depending on where my pointers are for the C file:
Code:
#include "SDL/SDL.h"
#include "SDL/SDL_image.h"
#include "SDL_Tutorial_Handler.h"
SDL_Surface *image = NULL;
SDL_Surface *screen = NULL;
SDL_Surface *load_image( char* filename ){
SDL_Surface* loaded_image = NULL;
SDL_Surface* optimized_image = NULL;
loaded_image = IMG_Load( filename );
if ( loaded_image != NULL ){
optimized_image = SDL_DisplayFormat( loaded_image );
SDL_FreeSurface( loaded_image );
}
return *optimized_image; \* There is a return error here *\
}
void apply_surface( int Pos_X, int Pos_Y, SDL_Surface* source, SDL_Surface* destination ){
SDL_Rect offset;
offset.x = Pos_X;
offset.y = Pos_Y;
SDL_BlitSurface( source, NULL, destination, &offset );
}
Bool init(){
if ( SDL_Init( SDL_INIT_EVERYTHING ) == -1 ){
return FALSE;
}
screen = SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_SWSURFACE );
if ( screen == NULL ){
return FALSE;
}
SDL_WM_SetCaption( "Image Library Tutorial", NULL );
return TRUE;
}
Bool load_files(){
image = load_image( "Hello.png" );
if ( image == NULL ){
return FALSE;
}
return TRUE;
}
void clean_up(){
SDL_FreeSurface( image );
SDL_Quit();
}
I get slapped with a multiple definitions error, so I changed those pointers and now I get a single error telling me that the return type for the *load_image function is incompatible for the function, even though they are both SDL_Surface. For anyone who can understand what I'm talking about, any advice?