Jump to content
  • Advertisement
Sign in to follow this  
quagmire

This sucks...SDL

This topic is 4450 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

#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.

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!