winapi - SDL Image Not Supported : cute2.png is not a PNG file, or PNG support is not available -
i trying tutorial, :
- http://lazyfoo.net/sdl_tutorials/lesson03/windows/msvsnet0508e/index.php
- http://lazyfoo.net/sdl_tutorials/lesson02/index.php
and tried load , display portable network graphics (.png
) files in application through simple code snippet:
#include "sdl.h" #include "sdl_image.h" #include "sdl_ttf.h" #include "sdl_mixer.h" #include <stdio.h> #include <string> //the attributes of screen const int screen_width = 640; const int screen_height = 480; const int screen_bpp = 32; //the surfaces used sdl_surface *background = null; sdl_surface *screen = null; sdl_surface *message = null; sdl_surface *load_image( std::string filename ) { //the image that's loaded sdl_surface* loadedimage = null; //the optimized image used sdl_surface* optimizedimage = null; sdl_rwops *rwop; rwop=sdl_rwfromfile(filename.c_str(), "rb"); if(img_ispng(rwop)) printf("%s png file.\n", filename.c_str()); else printf("%s not png file, or png support not available.\n", filename.c_str()); //load image using sdl_image loadedimage = img_load( filename.c_str() ); //if image loaded if( loadedimage != null ) { //create optimized image optimizedimage = sdl_displayformat( loadedimage ); //free old image sdl_freesurface( loadedimage ); } //return optimized image return optimizedimage; } void apply_surface(int x, int y, sdl_surface *source_surface, sdl_surface *destintion_surface) { //make temporary rectangle hold offsets sdl_rect rectangle; //give offsets rectangle rectangle.x = x; rectangle.y = y; //blit surface sdl_blitsurface(source_surface, null, destintion_surface, &rectangle); } int main(int argc, char** argv) { //initialize sdl subsystems if(sdl_init(sdl_init_everything) == -1) return 1; //set screen screen = sdl_setvideomode(screen_width, screen_height, screen_bpp, sdl_swsurface); //if there error in setting screen if(screen == null) return 1; //set window caption sdl_wm_setcaption("surface bliting", null); //load images background = load_image("cute2.png"); message = load_image("cute4.png"); //apply background screen apply_surface(0, 0, background, screen); apply_surface(320, 0, background, screen); apply_surface(0, 240, background, screen); apply_surface(320, 240, background, screen); //apply message screen apply_surface( 180, 140, message, screen ); //update screen if(sdl_flip(screen) == -1) return 1; sdl_delay(12000); sdl_freesurface(background); sdl_freesurface(message); //quit sdl sdl_quit(); return 0; }
now within visual stdio 2008, application running quite nicely.
but when trying run .exe
directly application:
e:\sdl_sample\sdl image extension libraries\release\"sdl image extension libraries.exe"
the stdout.txt
showing messages:
cute2.png not png file, or png support not available.
cute4.png not png file, or png support not available.
and window closes without displaying/rendering anything.
i don't understand how images loading when build/run application within visual studio 2008, when run .exe
, images not loading, image files, dll , every thing same in location.
it appears working directory
solution isn't same output directory
. \release
folder compiled executable output , doesn't seem contain dll
files sdl_image
looking load support png file format (probably libpng##.dll
).
an easy fix copy dynamic link libraries depend on output directory
, whatever is, when launch program, finds of them automatically.
Comments
Post a Comment