So, I'm playing around with SDL and I've come across a bit of a bump. I have one image and I am trying to "free" that image to put on another one. Here is what my code looks like..

// I did get a good section of this code from LazyFoo productions. I have modified it
// I don't take credit for the parts that LazyFoo productions did. :P

int main( int argc, char* args[] )
{
    //Make sure the program waits for a quit
    bool quit = false;

    //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;
  }

  SDL_Delay (2000);

  SDL_FreeSurface( image ); // get rid of the first image

  image = load_image("conan.jpg"); // load the second

  apply_surface( 0, 0, image, screen ); // apply it to the screen

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

// and.. it's ontop of the other image instead of replacing it

  SDL_Delay (2000);

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

    return 0;
}

So, what actually happens is the "conan.jpg" is simply placed over the original image that is loaded in the load_files() function. Just incase my query wasn't clear, what I want to do is get rid of the first image and replace it with a second.

Any help would be appreciated.

Thank you,

- TZ

Edited 5 Years Ago by TotalZombie: n/a

What's the problem? Is this all of your code?

I don't see you initialize SDL anywhere.

No, that's not all my code. This was just the section that I was working on; posting the entire code seemed a little excessive. I found a solution to this already, thanks for posting though.

- TZ

This question has already been answered. Start a new discussion instead.