Welcome! Log In Create A New Profile

Advanced

SDL Image

Posted by GabberNL 
SDL Image
May 18, 2009 11:16AM
Hello everybody,

Ive installed SDL and i can work with it on my PC, but i want to display a image on my wii. And that doesnt work. It says he cant fint background.bmp for its length. This is my code

//Necessary includes
#include 
#include 
#include 
#include  
#include 

//SDL includes
#include 
#include 
//#include 
//#include 
 
//Private includes
#include "exit.h"

////Variables

//Screen
SDL_Surface *screen = NULL;
SDL_Surface *background = NULL;

// Wiimote IR
ir_t ir;

////////////////////////////////////////////////////////////////////////////////
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 optimized image
      return optimizedImage;
}

////////////////////////////////////////////////////////////////////////////////
void apply_surface ( int x, int y, SDL_Surface* source, SDL_Surface* destination )
////////////////////////////////////////////////////////////////////////////////
{
     //Make a temporary rectangle to hold the offsets
     SDL_Rect offset;
     
     //Give the offsets tot the rectangle
     offset.x = x;
     offset.y = y;
     
     //Blit the surface
     SDL_BlitSurface( source, NULL, destination, &offset );
}

////////////////////////////////////////////////////////////////////////////////
void init() {
////////////////////////////////////////////////////////////////////////////////

	//VIDEO_Init();
	
	// initialize SDL video
    if ( SDL_Init( SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0 )
    {
        fprintf(stderr, "Unable to init SDL: %s\n", SDL_GetError() );
		SDL_Delay( 5000 );

        exit(EXIT_FAILURE);
    }
	
	/*
	if (!fatInitDefault()) { //for read files (level, serialized structs...)
		printf("Unable to initialise FAT subsystem, exiting");
		exit(EXIT_FAILURE);
	}
	*/
	
	WPAD_Init();
	WPAD_SetVRes(0, 640, 480);
	WPAD_SetDataFormat(WPAD_CHAN_0, WPAD_FMT_BTNS_ACC_IR); 

 
    // make sure SDL cleans up before exit
    atexit(SDL_Quit);
    SDL_ShowCursor(SDL_DISABLE);
 
    // create a new window
    screen = SDL_SetVideoMode(640, 480, 16, SDL_DOUBLEBUF);
    if ( !screen )
    {
        fprintf(stderr, "Unable to set video: %s\n", SDL_GetError());
		SDL_Delay( 5000 );
        exit(EXIT_FAILURE);
    }
}

////////////////////////////////////////////////////////////////////////////////
void state_in_game(SDL_Surface *screen)
////////////////////////////////////////////////////////////////////////////////
{
    int tick_count=0;
    int tick_trigger=15;
	bool done = false;
 
    SDL_EnableKeyRepeat(10,10);
 
 
    while (!done)
    {
        SDL_Event event;
 
        while (SDL_PollEvent(&event))
        {
            switch ( event.type )
            {
            case SDL_QUIT:
                done = true;
                break;
            }
        }
		
		// IR Movement
		WPAD_IR(0, &ir);
 
        //With SDL_Event, the wiimote is detected as a mouse, to use wiiuse/wpad to handle inputs
		WPAD_ScanPads();
		u32 held = WPAD_ButtonsHeld(0);
		
		//If home button is pressed, fillrect black screen and done=true
		if(held & WPAD_BUTTON_HOME){
			done=true;
			SDL_FillRect(screen, 0, SDL_MapRGB(screen->format, 0, 0, 0));
		}
		
		//Don't know what this is, but it works...
        tick_count = SDL_GetTicks();
        if (tick_count > tick_trigger)
        {
            tick_trigger = tick_count;
            //SDL_FillRect(screen, 0, SDL_MapRGB(screen->format, 255, 0, 0));
			SDL_Flip(screen);
            
        }//end tick
	
    }   //end while
 
	cleanup();
}

int cleanup(){

	SDL_Quit();
	SDL_FreeSurface(background);
	exit(EXIT_SUCCESS);
}

////////////////////////////////////////////////////////////////////////////////
int main(int argc, char** argv)
////////////////////////////////////////////////////////////////////////////////
{
	
    //srand(time(NULL));

	init();
	
	background = load_image("background.bmp");
	//background = SDL_LoadBMP("background.bmp");
	apply_surface( 0, 0, background, screen );
	SDL_Flip(screen);
	
	state_in_game(screen);
 
    return 0;
}

Can somebody help me?

GabberNL
Re: SDL Image
May 18, 2009 06:33PM
On wii you have to load from the root directory. So load the image by "/apps/yourapp/pic.bmp" or possibly "sd:/apps/yourapp/pic.bmp". Or in the meantime you can just throw those pics in the root of your SD and it should work fine.
Re: SDL Image
May 19, 2009 07:27PM
Ow ofcourse.. how stupid.. Thank you very much!

GabberNL
Re: SDL Image
May 20, 2009 12:17PM
Also, I think HBC passes the CWD (current working directory) as argv - you could use that, in case the folder that your app launches from changes (i.e. someone renames the folder on SD card).
Sorry, only registered users may post in this forum.

Click here to login