Sign in to follow this  
Gmp

Help with displaying images (SDL)

Recommended Posts

I'm using the apply_surfaces function found on lazyfoo.net, and it's been working fine for me. I've been making a pong clone, and it also was working fine, so i decided to break it up into separate header files and what not. But now the function is giving me errors. I have: img.h
#ifndef IMG_H
#define IMG_H
#include "SDL/SDL.h"
#include <time.h>
#include <string>

SDL_Surface *load_image( std::string filename );
void apply_surface( int x, int y, SDL_Surface* source, SDL_Surface* destination, SDL_Rect* clip = NULL );
int getRand(int min, int max); //Nothing to do with images, but who cares.

#endif
img.cpp
#include "SDL/SDL.h"
#include "SDL/SDL_image.h"
#include "img.h"

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

    //The optimized surface 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 surface
        optimizedImage = SDL_DisplayFormat( loadedImage );

        //Free the old surface
        SDL_FreeSurface( loadedImage );

        //If the surface was optimized
        if( optimizedImage != NULL )
        {
            //Color key surface
            SDL_SetColorKey( optimizedImage, SDL_RLEACCEL | SDL_SRCCOLORKEY, SDL_MapRGB( optimizedImage->format, 0, 0xFF, 0xFF ) );
        }
    }

    //Return the optimized surface
    return optimizedImage;
}

void apply_surface( int x, int y, SDL_Surface* source, SDL_Surface* destination, SDL_Rect* clip = NULL )
{
    //Holds offsets
    SDL_Rect offset;

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

    //Blit
    SDL_BlitSurface( source, clip, destination, &offset );
}

int getRand(int min, int max)
{
    time_t seconds;
    time(&seconds);
    srand((unsigned int) seconds);
    return (rand() % (max - min + 1) + min)
}
And the error i'm getting is:
Quote:
img.cpp:38: error: default argument given for parameter 5 of `void apply_surface(int, int, SDL_Surface*, SDL_Surface*, SDL_Rect*)' img.h:8: error: after previous specification in `void apply_surface(int, int, SDL_Surface*, SDL_Surface*, SDL_Rect*)' :: === Build finished: 2 errors, 0 warnings ===
Can someone help me here?

Share this post


Link to post
Share on other sites
It's complaining that you gave a default argument to the "clip" parameter in both the header and the cpp. You should only set default arguments in the function's declaration (in the .h), not in its implementation.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this