tags:

views:

61

answers:

1

I am new to C++ and SDL; I am trying to add a new SDL extension libary using instructions found here: http://www.lazyfoo.net/SDL_tutorials/lesson03/windows/devcpp/index.php

But I get these errors:

3 C:\Documents and Settings\Edmund\My Documents\C++\myprojects\SDL\SDLevent.cpp SDL/SDL_image.h: No such file or directory.

C:\Documents and Settings\Edmund\My Documents\C++\myprojects\SDL\SDLevent.cpp In function `SDL_Surface* load_image(std::string)':

28 C:\Documents and Settings\Edmund\My Documents\C++\myprojects\SDL\SDLevent.cpp `IMG_Load' undeclared (first use this function)

and then a bunch of unqualified ids.

This is my code:

#include "SDL/SDL.h"
#include "SDL/SDL_image.h"

#include <string>

//Screen attributes
const int SCREEN_WIDTH = 640;
const int SCREEN_HEIGHT = 480;
const int SCREEN_BPP = 32;

//The surfaces
SDL_Surface *image = NULL;
SDL_Surface *screen = NULL;

//The event structure that will be used
SDL_Event event;

SDL_Surface *load_image( std::string filename ) 
{
    //The image that's loaded
    SDL_Surface* loadedImage = NULL;

    //The optimized image that will be used
    SDL_Surface* optimizedImage = NULL;

    //Load the image
    loadedImage = IMG_Load( filename.c_str() );

    //If the image loaded
    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 )
{
    //Temporary rectangle to hold the offsets
    SDL_Rect offset;

    //Get the offsets
    offset.x = x;
    offset.y = y;

    //Blit the surface
    SDL_BlitSurface( source, NULL, destination, &offset );
}

bool init()
{
    //Initialize all SDL subsystems
    if( SDL_Init( SDL_INIT_EVERYTHING ) == -1 )
    {
        return false;    
    }

    //Set up the screen
    screen = SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_SWSURFACE );

    //If there was an error in setting up the screen
    if( screen == NULL )
    {
        return false;    
    }

    //Set the window caption
    SDL_WM_SetCaption( "Event test", NULL );

    //If everything initialized fine
    return true;
}

bool load_files()
{
    //Load the image
    image = load_image( "astyle.bmp" );

    //If there was an error in loading the image
    if( image == NULL )
    {
        return false;    
    }

    //If everything loaded fine
    return true;    
}

void clean_up()
{
    //Free the image
    SDL_FreeSurface( image );

    //Quit SDL
    SDL_Quit();    
}

   //Initialize
    if( init() == false )
    {
        return 1;    
    }

    //Load the files
    if( load_files() == false )
    {
        return 1;    
    }

//Apply the surface to the screen
    apply_surface( 0, 0, image, screen );

    //Update the screen
    if( SDL_Flip( screen ) == -1 )
    {
        return 1;    
    }

 //While the user hasn't quit
    while( quit == false )
    {

 //While there's an event to handle
        while( SDL_PollEvent( &event ) )
        {

    //If the user has Xed out the window
            if( event.type == SDL_QUIT )
            {
                //Quit the program
                quit = true;
            }    
        }
    }

 //Free the surface and quit SDL
    clean_up();

    return 0;    
}

It is pretty much identical to what is on the tutorial so it should not be a problem with the code. I have followed the Instructions on Lazy foo to the letter, I have put all of the files in the right place and linked to them so i do not know what I am doing wrong, Please help.

+4  A: 

Your compiler can't find the SDL/SDL_image.h header, that leads to all those 'undeclared' errors.

Maybe you skipped Step 2 in the linked instructions.

DerKuchen
+1 For linking to my favorite introductory game programming tutorial.
PigBen
I've done step 2 three times over but I will try again.
AHH!!! I've been trying to do this for DAYS. Exuse me but its driving me bonkers, I think its a problem in the linker, the include or libary link.
all right 2 days but its still innoying
The first error message clearly says "SDL/SDL_image.h: No such file or directory.". What IDE are you using?
DerKuchen
Dev-C++ but I just read an article saying its terrible
http://www.jasonbadams.net/20081218/why-you-shouldnt-use-dev-c/
however I have tried with code blocks and that has returned the same error I can only assume that there is a problem in the linker or some of the other files you have to browse for to include, either that or There is . configuraton error(lib to old/new)
I include: #include "SDL\SDL_image.h"
in the linker: -lmingw32 -lSDLmain -lSDL-lSDL SDL_image
and then i downloaded this file: SDL 1.2.14
Thanks for the help.
It's not a linker problem, the problem is that the compiler isn't finding the SDL_image.h header. Somewhere in the DevCPP (or code blocks) directory there should be a subdir named "include". Copy the SDL_image.h file in the SDL directory in the include directory. The path should look like "DevCPP\include\SDL\SDL_image.h".
DerKuchen
Thanks but that did not work; This is torchering me, the problem is so vauge it could be a dozen problems, I have linked to the libary and include locations in The cpp file _and_ copied the files.
I will try erasing everything and starting over