This sucks...SDL

Started by
19 comments, last by JBourrie 17 years, 11 months ago
#include <sdl.h> #include <string> //The attributes of the window const int SCREEN_WIDTH = 640; const int SCREEN_HEIGHT = 480; const int SCREEN_BPP = 32; //The surfaces that will be used SDL_Surface *message = NULL;
SDL_Surface *background = NULL;
SDL_Surface *screen = NULL;

SDL_Surface *load_image( std::string filename ) 
{
    //Temporary storage for the image that's loaded
    SDL_Surface* loadedImage = NULL;
    
    //The optimized image that will be used
    SDL_Surface* optimizedImage = NULL;
    
    //Load the image
    loadedImage = SDL_LoadBMP( filename.c_str() );
    
    //If nothing went wrong in loading the image
    if( loadedImage != NULL )
    {
        //Create an optimized image
        optimizedImage = SDL_DisplayFormat( loadedImage );
        
        //Free the old image
        SDL_FreeSurface( loadedImage );
    }
    
    //Return the optimized image
    return optimizedImage;
}

void apply_surface( int x, int y, SDL_Surface* source, SDL_Surface* destination )
{
    //Make a temporary rect to hold the offsets
    SDL_Rect Offset;
    
    //Give the offsets to the rect
    Offset.x = x;
    Offset.y = y;
    
    //Blit the surface
    SDL_BlitSurface( source, NULL, destination, &Offset );
}

int main( int argc, char* args[] )
{
    //Initialize all SDL sub systems
    if( SDL_Init( SDL_INIT_EVERYTHING ) == -1 )
    {
        return 1;    
    }
    
    //Set up the screen
    screen = SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_SWSURFACE );
    
    //if there was in error in setting up the screen
    if( screen == NULL )
    {
        return 1;    
    }
    
    //Set the window caption
    SDL_WM_SetCaption( "C:\Dev-CPP\lessson02\Hello World", NULL );
    
    //Load the images
    message = load_image( "C:\Dev-CPP\lessson02\hello_world.bmp" );
    background = load_image( "C:\Dev-CPP\lessson02\background.bmp" );
    
    //Apply the background to the screen
    apply_surface( 0, 0, background, screen );
    
    //Apply the message to the screen
    apply_surface( 180, 140, message, screen );
    
    //Update the screen
    if( SDL_Flip( screen ) == -1 )
    {
        return 1;    
    }
    
    //Wait 4 seconds
    SDL_Delay( 4000 );
    
    //Free the images
    SDL_FreeSurface( message );
    SDL_FreeSurface( background );
    
    //Quit SDL
    SDL_Quit();
    
    return 0;    
}
I have all the linkers in there. I set it up just how lazyfooproductions tutorials said, but it always says "C:\Dev-Cpp\Makefile.win [Build Error] [2sdl.exe] Error 1" If someone will please help, it will be great.
cout<<"cout<<'' this is my siggy''";
Advertisement
Quote:Original post by quagmire
#include <sdl.h>


I have to put:
#include "SDL/SDL.h"

Try that.
What is the full error?
No, it didn't work. I am using DEV C++ unless that could be useful for anyones input. By the way, thanks for trying. Here are the linkers I used:
SDL-1.2.9/lib/libSDL.a
SDL-1.2.9/lib/libSDL.dll.a
SDL-1.2.9/lib/libSDLmain.a
"-lmingw32 -lSDLmain -lSDL"
SDL-1.2.9/include/begin_code.h
SDL-1.2.9/include/close_code.h
SDL-1.2.9/include/SDL.h
SDL-1.2.9/include/SDL_active.h
SDL-1.2.9/include/SDL_audio.h
SDL-1.2.9/include/SDL_byteorder.h
SDL-1.2.9/include/SDL_cdrom.h
SDL-1.2.9/include/SDL_copying.h
SDL-1.2.9/include/SDL_cpuinfo.h
SDL-1.2.9/include/SDL_endian.h
SDL-1.2.9/include/SDL_error.h
SDL-1.2.9/include/SDL_events.h
SDL-1.2.9/include/SDL_getenv.h
SDL-1.2.9/include/SDL_joystick.h
SDL-1.2.9/include/SDL_keyboard.h
SDL-1.2.9/include/SDL_keysym.h
SDL-1.2.9/include/SDL_loadso.h
SDL-1.2.9/include/SDL_main.h
SDL-1.2.9/include/SDL_mouse.h
SDL-1.2.9/include/SDL_mutex.h
SDL-1.2.9/include/SDL_name.h
SDL-1.2.9/include/SDL_opengl.h
SDL-1.2.9/include/SDL_quit.h
SDL-1.2.9/include/SDL_rwops.h
SDL-1.2.9/include/SDL_syswm.h
SDL-1.2.9/include/SDL_thread.h
SDL-1.2.9/include/SDL_timer.h
SDL-1.2.9/include/SDL_types.h
SDL-1.2.9/include/SDL_version.h
SDL-1.2.9/include/SDL_video.h

Thanks.
cout<<"cout<<'' this is my siggy''";
I tried compiling it. It worked once I had changed the linker mentioned above and double back-slashed all your load_images, like below.

message = load_image( "C:\\Dev-CPP\\lessson02\\hello_world.bmp" );

See if it works on yours.

[Edit:]I used this linker: -lmingw32 -lSDLmain -lSDL
You are trying so thanks. But no, it isn't working. What compiler are you using? I don't know if that could have anything to do with it. Thanks.
cout<<"cout<<'' this is my siggy''";
I'm using Dev C++ 4.9.8.5 on windows XP. Is this your first SDL project? You might want to check if you have it installed properly.
I don't know. I think I do. But, you never know. I will check.
cout<<"cout<<'' this is my siggy''";
As well as setting up SDL development, you need to have the SDL.dll file which is a seperate download on the same webpage as where you downloaded the development package. If you did download this then make sure the dll is actually in your debug folder or where you are developing the program.

Just mentioning this in case this is your first SDL program
Is your project set to multithreaded dll? Not sure how to do that in Dev C++.
SDBradley
CGP
"A person who won't read has no advantage over one who can't read." ~Mark Twain

This topic is closed to new replies.

Advertisement