Welcome! Log In Create A New Profile

Advanced

Wii SDL not showing ,png images?

Posted by Cypri 
Wii SDL not showing ,png images?
August 11, 2010 03:22AM
Okay so the program compiles, and runs like normal except that it doesn't display the PNG image. I tried it as a BMP and it worked by loading it like so:

player=SDL_LoadBMP("sd:/pngmove/data/graphics/player.bmp");

But loading a PNG like this

rwop=SDL_RWFromFile("sd:/pngmove/data/graphics/player.png", "rb");
	
player=IMG_Load(rwop);

doesn't give me a compileing error, and the program runs fine, but the PNG doesn't show up.

so I tried loading it like this

player=IMG_Load("sd:/pngmove/data/graphics/player.png");

and it still didn't work. I'm not getting any errors though, SDL must be compiled to use pngs.

Why isn't my png showing up? and how can I load a PNG in a way that it will show up?

Here is the full code:

// normal includes
#include 
#include 
#include 
#include  
#include 
 
// SDL includes
#include 
#include 
 
// screen surface, the place where everything will get print onto
SDL_Surface *screen = NULL;
SDL_Surface *player = NULL;

int playerX = 50;
int playerY = 50;

SDL_RWops *rwop;
 
void init(){
 
    // initialize SDL video. If there was an error SDL shows it on the screen
    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);
    }
 
    // button initialization
    WPAD_Init();
 
    // 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);
    }
}
 
// this will be used in further lessons, not in lesson 1
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 to the rectangle
     offset.x = x;
     offset.y = y;
 
     // blit the surface
     SDL_BlitSurface( source, NULL, destination, &offset );
}
 
void cleanup(){
 
     // we have to quit SDL
     SDL_Quit();
     exit(EXIT_SUCCESS);
}
 
int main(int argc, char** argv){
	// main function. Always starts first
 
	// to stop the while loop
	bool done = false;
 
	// start init() function
	init();
	
	fatInitDefault();

	player=SDL_LoadBMP("sd:/pngmove/data/graphics/player.bmp");
	
	if(player == NULL)
		printf("error!");
 
	// this is the endless while loop until done = true
	while (!done)
        {
		// scans if a button was pressed
        WPAD_ScanPads();
		u32 held = WPAD_ButtonsHeld(0);
 
		SDL_FillRect(screen, 0, SDL_MapRGB(screen->format, 0, 33, 33));
		apply_surface(playerX, playerY, player, screen);
		
		if(held){
			if(WPAD_BUTTON_HOME){
				done=true;
				SDL_FillRect(screen, 0, SDL_MapRGB(screen->format, 0, 0, 0));
			}
			
			if(WPAD_BUTTON_UP){
				playerY-=2;
			}
			
			if(WPAD_BUTTON_DOWN){
				playerY+=2;
			}
			
			if(WPAD_BUTTON_LEFT){
				playerX-=2;
			}
			
			if(WPAD_BUTTON_RIGHT){
				playerX+=2;
			}
		}
		
		
 
		// SDL_Flip refreshes the screen so it will show the updated screen
		SDL_Flip(screen);
        }
 
	// start cleanup() function
	cleanup();
 
    return 0;
}
Re: Wii SDL not showing ,png images?
August 11, 2010 05:15AM
Make sure the width and height of your png image is a multiple of 4.
Re: Wii SDL not showing ,png images?
August 11, 2010 07:48AM
Quote
Arikado
Make sure the width and height of your png image is a multiple of 4.

For SDL that doesn't matter. We're not talking about PNGU here.
Re: Wii SDL not showing ,png images?
August 11, 2010 11:27AM
im using sdl and i blit png with

SDL_Rect offset;
SDL_Surface *image;
SDL_Surface *screen;
image = IMG_Load("image.png");
offset.x = 1;
offset.y = 1;
SDL_BlitSurface(image, NULL, screen, &offset );
SDL_Flip(screen);
SDL_FreeSurface(image);
Re: Wii SDL not showing ,png images?
August 11, 2010 06:44PM
Are you sure that image.png is where you think it is? try sd:/image.png if it's on the sd card.

You can test like so:

SDL_Surface *image = 0;
image = IMG_Load("image.png");
if(!image) exit(0);

Also what happens if you do this :-

offset.x = 1;
offset.y = 1;
offset.w = image->w;
offset.h = image->h;
Re: Wii SDL not showing ,png images?
August 11, 2010 07:01PM
Thank you all for your replies. Using the method of testing suggested by scanff I have figured out that my player image is null. I have looked in the sd cards path and confirmed that the image is there, and loaded a .bmp from the same path, so that is not the problem.

Also I would like to point out that the bliting I use in my program worked perfectly fine for the .bmp, so I don't think it's a blit problem.
Re: Wii SDL not showing ,png images?
August 11, 2010 10:41PM
What program are you using to create the png?

I had issues with an older version of paint shop pro creating png's but after running them through gimp everything worked.

Also the png IMG_Load is part of SDL image which is different from loading a bitmap, the SDL_LoadBMP is in the main SDL library. If libpng is not installed I'd expect link errors but who knows.
Re: Wii SDL not showing ,png images?
August 12, 2010 09:38PM
I'm using Photoshop. I figured out with some logging that SDL_errorGet (getError?) is returning "can not allocate memory for png, or using incompatable png dll." Now the .png is only 32x32 so I know it's not the allocated memory thing. I'm trying to reinstall libpng from the portlibs section of devkitpro's site, but I am running into oddities and errors. First off I have no DRIVE:\devkitPro\portlibs folder, but I have libpng installed because I'm not getting linker errors. Second is I heard that the libs in devkitPro's site were precompiled, but the one I found of libpng (for PPC) had make and install files, and no include and lib folders. Third is that the make file for libpng has a lot of errors in it, so I can't make it.

I can't reinstall devkitPro because my PC doesn't have internet access anymore.

So can anyone help me?
Re: Wii SDL not showing ,png images?
August 13, 2010 08:14AM
Here's the current portlib png [sourceforge.net]

Yes you should not need to compile, just copy to the include and lib folders under libogc.
Re: Wii SDL not showing ,png images?
August 13, 2010 10:03AM
Okay, thank you. I tried that and it still didn't work. :(/
I first put the lib and include folders straight into the respective folders (inside the libogc folder), and tried it and it didn't work. Than I went in and deleted the lib png files (and found out I was suppose to put then in lib\wii and not just lib) and tried to compile it, and it sai libpng wasn't found (to test if I got all the lib png out) than I reinstalled the libpng files again (with the lib folders contents in lib/wii) and tried it and it still didn't work. I get the same "can not allocate memory for png, or using incompatable png dll." error. The only thing I can think of is installing the newest zlib (which I think I already have) but my hopes are very low...

Edit: reinstalling zlib didn't work either...

edit2: creating a PNG in GIMP didn't work at all



Edited 2 time(s). Last edit at 08/13/2010 09:17PM by Cypri.
Re: Wii SDL not showing ,png images?
August 15, 2010 01:38AM
The only other thing I can think of is download another HB project that loads pngs and build it to see if they load on it.

My projects wiiradio and bash the castle both use SDL and load png's from the SD card.
Re: Wii SDL not showing ,png images?
August 16, 2010 12:18AM
Okay, it finally worked! ^_^

I guess I had to install the latest SVN for Wii SDL and not the .zip one. Thank you for all your help scanff, and everyone else! ^_^
Sorry, only registered users may post in this forum.

Click here to login