loading a png with sdl + sdl_image.

Started by
24 comments, last by rakoon2 19 years, 6 months ago
This is likely to be an issue with your compiler and setup rather than the code. Try experimenting with the order of the libraries as gcc requires them to be in a certain order (which I forget).
Advertisement
Hmm. I tried 10 different orders.. still the same linker error.
Maybe my lib is broken? Where can I download it again? *forgot it*
Thank you..!
Visit http://www.devpaks.org for all your devpak needs.

GCC, in its usual sane fashion, requires libraries in reverse order. ie, if libSDL_net requires a function from libwsock32, then they must be ordered g++ ... -lSDL_net -lwsock32 .... (That one drove me bonkers for a while).

The gcc manual seems to agree with me, although the wording is a little confusing.
It works now! The lib was broken~! =3

Thank you! :)

Is this correct? ( texture loading ) XD :) ;)
bool Texture::loadImage( const char* filename ){    SDL_Surface* sprite = IMG_Load( filename );      if( !sprite )    {        LOG << "Could not load " << filename             << "   bool Texture::loadImage( const char* filename ) "            << ENDL;        return false;    }        else if( sprite->w != sprite->h )    {        LOG << "Texture w and h are not the same! Filename: " << filename             << " W: " << sprite->w << " H " << sprite->h << ENDL;        return false;        }    else if( sprite->w % 2 != 0 )    {        LOG << "Texture w/h are not a power of 2! w/h: " << sprite->w << ENDL;    }                 texture_wh = sprite->w;                  SDL_Surface*  conv;        // convert to 32-bit RGBA format  	conv = SDL_CreateRGBSurface( SDL_SWSURFACE, sprite->w, sprite->h, 32,                                 #if SDL_BYTEORDER == SDL_BIG_ENDIAN	                                 0xff000000, 0x00ff0000, 0x0000ff00, 0x000000ff);                                 #else                                     0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000);                                 #endif      SDL_BlitSurface( sprite, 0, conv, 0);        glGenTextures( 1, &texture );	glBindTexture( GL_TEXTURE_2D, texture );		glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR  );	glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );	    glPixelStorei( GL_UNPACK_ROW_LENGTH, conv->pitch / conv->format->BytesPerPixel );	glTexImage2D( GL_TEXTURE_2D, 0, 3, conv->w, conv->h, 0, GL_RGBA, GL_UNSIGNED_BYTE, conv->pixels);	glPixelStorei( GL_UNPACK_ROW_LENGTH, 0 );	SDL_FreeSurface(conv);            SDL_FreeSurface(sprite);        return true;}     

Thanks ;d
Your power of 2 checking is wrong.

I also don't believe you need the GL_UNPACK_ROW_LENGTH with a software surface that you've just created, but I don't see it doing any harm.
why dont you just make the file a bitmap using paint? it would be much simpler
____________________________"This just in, 9 out of 10 americans agree that 1 out of 10 americans will disagree with the other 9"- Colin Mochrie
PNG files have several advantages over BMPs when it comes to games - file size perhaps being the most important.
Quote:Original post by Spudder
PNG files have several advantages over BMPs when it comes to games - file size perhaps being the most important.

... and an alpha channel, required for transparency in sprites.
Most people using SDL will probably be using colour keying rather than alpha channels though.
Well, I am using OpenGl. I still have problems with those damn linker errors!

My engine lib (.a) has a texture class.

And as you can see this line in it:
SDL_Surface* sprite = IMG_Load( filename );

It compiles fine. But I get
  [Linker error] undefined reference to `IMG_Load' 

if I want to use the the Texture class in one of my other projects(editor) that use the lib!

Here the linker from my editor:
../sdl_ogl_engine_lib/ogl_sdl_2d_engine_lib.aE:/Programme/dev-c++/sdl_ming/libSDL.aE:/Programme/dev-c++/sdl_ming/libSDL.dll.aE:/Programme/dev-c++/sdl_ming/libSDLmain.aE:/Programme/dev-c++/sdl_ming/SDL_image.aE:/Programme/dev-c++/open_gl/libopengl32.aE:/Programme/dev-c++/f_mod/libfmod.a


I am using Dev-C++.


Help please! :((( (i hate link errors)
Thank you!

This topic is closed to new replies.

Advertisement