swappo1
March 22nd, 2009, 04:34 AM
Hello,
I am working through the lazy foo sdl tutorial number 2. I know C but I am not familiar with C++ which is what the tutorials are written in. I am having trouble converting the following function to C. I am assuming that std::string filename takes a string(the file name) into the function and puts the string in SDL_LoadBMP(filename.c_str() ). Is there a simple way to re-write this function in C? I will have multiple files so I would like to use a function. I can do it with out a function but it would have redundant code.
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;
I am working through the lazy foo sdl tutorial number 2. I know C but I am not familiar with C++ which is what the tutorials are written in. I am having trouble converting the following function to C. I am assuming that std::string filename takes a string(the file name) into the function and puts the string in SDL_LoadBMP(filename.c_str() ). Is there a simple way to re-write this function in C? I will have multiple files so I would like to use a function. I can do it with out a function but it would have redundant code.
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;