SDL_image Error (SDL)

  • (2 Pages)
  • +
  • 1
  • 2

16 Replies - 2925 Views - Last Post: 10 January 2011 - 08:15 PM Rate Topic: -----

#1 kaaie  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 3
  • View blog
  • Posts: 93
  • Joined: 22-June 09

SDL_image Error (SDL)

Post icon  Posted 03 August 2009 - 01:25 PM

Well, for the past few days I've been following a tutorial on-line for SDL and for some reason this program wont compile, and I have no clue why!

I'm pretty sure I set up SDL like I was supposed to(I also included the library extension SDL_image.h), but then again I am pretty noobish at this, so please bear with me as it is probably a dumb mistake. :rolleyes:

Anyway, here is the relevant code, the rest of the code, and the error:

SDL_Surface *load_image( std::string filename )
{
	//The image that's loaded
	SDL_Surface* loadedImage = NULL;

	//The optimized image that will be used
	SDL_Surface* optimizedImage = NULL;

	//Load the image
	loadedImage = IMG_Load( filename.c_str() );

	//If the image loaded
	if( loadedImage != NULL )
	{
		//Create an optimized image
		optimizedImage = SDL_DisplayFormat( loadedImage );

		//Free the old image
		SDL_FreeSurface( loadedImage );
	}

	//Return the optimized image
	return optimizedImage;
}


//The headers
#include "SDL/SDL.h"
#include "SDL/SDL_image.h"
#include <string>

//Screen attributes
const int SCREEN_WIDTH = 640;
const int SCREEN_HEIGHT = 480;
const int SCREEN_BPP = 32;

//The surfaces
SDL_Surface *image = NULL;
SDL_Surface *screen = NULL;

//The event structure that will be used
SDL_Event event;

SDL_Surface *load_image( std::string filename )
{
	//The image that's loaded
	SDL_Surface* loadedImage = NULL;

	//The optimized image that will be used
	SDL_Surface* optimizedImage = NULL;

	//Load the image
	loadedImage = IMG_Load( filename.c_str() );

	//If the image loaded
	if( loadedImage != NULL )
	{
		//Create an optimized image
		optimizedImage = SDL_DisplayFormat( loadedImage );

		//Free the old image
		SDL_FreeSurface( loadedImage );
	}

	//Return the optimized image
	return optimizedImage;
}

void apply_surface( int x, int y, SDL_Surface* source, SDL_Surface* destination )
{
	//Temporary rectangle to hold the offsets
	SDL_Rect offset;

	//Get the offsets
	offset.x = x;
	offset.y = y;

	//Blit the surface
	SDL_BlitSurface( source, NULL, destination, &offset );
}

bool init()
{
	//Initialize all SDL subsystems
	if( SDL_Init( SDL_INIT_EVERYTHING ) == -1 )
	{
		return false;
	}

	//Set up the screen
	screen = SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_SWSURFACE );

	//If there was an error in setting up the screen
	if( screen == NULL )
	{
		return false;
	}

	//Set the window caption
	SDL_WM_SetCaption( "Event test", NULL );

	//If everything initialized fine
	return true;
}

bool load_files()
{
	//Load the image
	image = load_image( "x.png" );

	//If there was an error in loading the image
	if( image == NULL )
	{
		return false;
	}

	//If everything loaded fine
	return true;
}

void clean_up()
{
	//Free the surface
	SDL_FreeSurface( image );

	//Quit SDL
	SDL_Quit();
}

int main( int argc, char* args[] )
{
	//Make sure the program waits for a quit
	bool quit = false;

	//Initialize
	if( init() == false )
	{
		return 1;
	}

	//Load the files
	if( load_files() == false )
	{
		return 1;
	}

	//Apply the surface to the screen
	apply_surface( 0, 0, image, screen );

	//Update the screen
	if( SDL_Flip( screen ) == -1 )
	{
		return 1;
	}

	//While the user hasn't quit
	while( quit == false )
	{
		//While there's an event to handle
		while( SDL_PollEvent( &event ) )
		{
			//If the user has Xed out the window
			if( event.type == SDL_QUIT )
			{
				//Quit the program
				quit = true;
			}
		}
	}

	//Free the surface and quit SDL
	clean_up();

	return 0;
}


obj/Debug/main.o||.........................................In function `load_image(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)':|
/home/nathan/Desktop/C++/SDLTest/main.cpp..................|31|undefined reference to `IMG_Load'|
||=== Build finished: 1 errors, 0 warnings ===|


By the way, if this helps, im running Ubuntu 9.04 with Code::blocks
Also "IMG_Load" is part of "SDL/SDL_image.h"

As always, any help would be appreciated :)
Thank you in advance,

Kaaie

This post has been edited by kaaie: 03 August 2009 - 03:24 PM


Is This A Good Question/Topic? 0
  • +

Replies To: SDL_image Error (SDL)

#2 ladyinblack  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 9
  • View blog
  • Posts: 419
  • Joined: 08-April 09

Re: SDL_image Error (SDL)

Posted 03 August 2009 - 02:07 PM

VS or devcpp?
Was This Post Helpful? 0
  • +
  • -

#3 kaaie  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 3
  • View blog
  • Posts: 93
  • Joined: 22-June 09

Re: SDL_image Error (SDL)

Posted 03 August 2009 - 02:14 PM

@ladyinblack:

View Postkaaie, on 3 Aug, 2009 - 12:25 PM, said:

By the way, if this helps, im running Ubuntu 9.04 with Code::blocks

Was This Post Helpful? 0
  • +
  • -

#4 mono15591  Icon User is offline

  • D.I.C Regular

Reputation: 12
  • View blog
  • Posts: 406
  • Joined: 05-November 08

Re: SDL_image Error (SDL)

Posted 03 August 2009 - 04:37 PM

I had the same problem when I was using that tutorial
I don't know what to tell you

I just kept on using bmp files since the kind of things I was trying to accomplish weren't that big
Was This Post Helpful? 0
  • +
  • -

#5 kaaie  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 3
  • View blog
  • Posts: 93
  • Joined: 22-June 09

Re: SDL_image Error (SDL)

Posted 03 August 2009 - 08:07 PM

Thanks for the reply, but unfortunately it does not solve the problem... It is really bugging me that this little speed bump is hindering me from continuing my progress towards a high level of accomplishment! <-- Notice the complicated words :P(it probably has sum errors in it but watevr :rolleyes: ).

Does anyone know anything about SDL, or is it kind of like a dead library?

BTW: Sorry for bumping.

Edit: Sorry for being rude, I'm just tired.

This post has been edited by kaaie: 03 August 2009 - 08:40 PM

Was This Post Helpful? 0
  • +
  • -

#6 no2pencil  Icon User is online

  • Toubabo Koomi
  • member icon

Reputation: 5224
  • View blog
  • Posts: 26,990
  • Joined: 10-May 07

Re: SDL_image Error (SDL)

Posted 03 August 2009 - 08:11 PM

View Postkaaie, on 3 Aug, 2009 - 09:07 PM, said:

Does anyone here know anything about SDL, or is it kind of like a dead library?
(Or maybe its because hardly anyone's on-line?)

I know that you are frustrated, but this is the wrong way to get help...

You have to load another library to get pngs to load. http://www.libsdl.or...ects/SDL_image/
Was This Post Helpful? 0
  • +
  • -

#7 kaaie  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 3
  • View blog
  • Posts: 93
  • Joined: 22-June 09

Re: SDL_image Error (SDL)

Posted 03 August 2009 - 08:37 PM

View Postno2pencil, on 3 Aug, 2009 - 07:11 PM, said:

You have to load another library to get pngs to load. http://www.libsdl.or...ects/SDL_image/


Well, I did load that library(notice the includes at the top of the file) and the compiler found it and everything, that's what baffles me: Even though everything is fine, it doesn't work :blink: !

BTW, sorry for being frustrated.
Was This Post Helpful? 0
  • +
  • -

#8 ladyinblack  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 9
  • View blog
  • Posts: 419
  • Joined: 08-April 09

Re: SDL_image Error (SDL)

Posted 04 August 2009 - 02:47 AM

View Postkaaie, on 3 Aug, 2009 - 01:14 PM, said:

@ladyinblack:

View Postkaaie, on 3 Aug, 2009 - 12:25 PM, said:

By the way, if this helps, im running Ubuntu 9.04 with Code::blocks


Sorry about that, my brain was asleep at that time, the fingers were still working, though.

Have no idea if this would help, but why not give mono15591 using bmp a try, if you haven't already, to figure out the root to your problem, process of elimination. That is what I usually do. If your bmp's or any other formats don't work, then something is obviously wrong otherwise. I don't use Linux, so can't help further than that. I understand your frustration, felt that way yesterday, something in java, so won't discuss here.
Was This Post Helpful? 0
  • +
  • -

#9 stayscrisp  Icon User is offline

  • フカユ
  • member icon

Reputation: 998
  • View blog
  • Posts: 4,173
  • Joined: 14-February 08

Re: SDL_image Error (SDL)

Posted 04 August 2009 - 03:23 AM

This code works fine for me, you must not have set up SDL_image correctly,

and also don't include like this
#include "SDL/SDL_image.h"



Just like this
#include "SDL_image.h"


This post has been edited by stayscrisp: 04 August 2009 - 03:24 AM

Was This Post Helpful? 0
  • +
  • -

#10 kaaie  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 3
  • View blog
  • Posts: 93
  • Joined: 22-June 09

Re: SDL_image Error (SDL)

Posted 04 August 2009 - 04:23 PM

View Poststayscrisp, on 4 Aug, 2009 - 02:23 AM, said:

This code works fine for me, you must not have set up SDL_image correctly,


Well I installed libsdl-image1.2-dev + libsdl-image1.2 through Synaptic Package Manager and code::blocks doesn't complain about anything, so maybe its because I'm using Linux or my IDE?

But thanks for the replies any ways!
Was This Post Helpful? 0
  • +
  • -

#11 kaaie  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 3
  • View blog
  • Posts: 93
  • Joined: 22-June 09

Re: SDL_image Error (SDL)

Posted 05 August 2009 - 07:01 AM

Anyone have a clue(bump)?
Was This Post Helpful? 0
  • +
  • -

#12 stayscrisp  Icon User is offline

  • フカユ
  • member icon

Reputation: 998
  • View blog
  • Posts: 4,173
  • Joined: 14-February 08

Re: SDL_image Error (SDL)

Posted 05 August 2009 - 07:56 AM

Did you adjust the include lines like I suggested?

And also check that your version of SDL is compatible with your IDE and operating system. If it still doesn't work try compiling SDL_image from source and linking that.

This post has been edited by stayscrisp: 05 August 2009 - 08:08 AM

Was This Post Helpful? 0
  • +
  • -

#13 kaaie  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 3
  • View blog
  • Posts: 93
  • Joined: 22-June 09

Re: SDL_image Error (SDL)

Posted 05 August 2009 - 07:07 PM

View Poststayscrisp, on 5 Aug, 2009 - 06:56 AM, said:

Did you adjust the include lines like I suggested?

yes

View Poststayscrisp, on 5 Aug, 2009 - 06:56 AM, said:

And also check that your version of SDL is compatible with your IDE and operating system. If it still doesn't work try compiling SDL_image from source and linking that.

I'm pretty sure its the right version and my IDE supports it(I mean its really only a compiler attached to a text editor right?). And compiling from source? I'm guessing that means taking the header file and sticking it in my project directory? Well I did that and the same thing happened.

Heh.
Well I appreciate the tips!
Was This Post Helpful? 0
  • +
  • -

#14 eker676  Icon User is offline

  • Software Engineer
  • member icon

Reputation: 378
  • View blog
  • Posts: 1,833
  • Joined: 18-April 09

Re: SDL_image Error (SDL)

Posted 05 August 2009 - 07:31 PM

http://lazyfoo.net/S...son03/index.php

Try that.
Was This Post Helpful? 0
  • +
  • -

#15 kaaie  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 3
  • View blog
  • Posts: 93
  • Joined: 22-June 09

Re: SDL_image Error (SDL)

Posted 05 August 2009 - 07:39 PM

View Posteker676, on 5 Aug, 2009 - 06:31 PM, said:



But that's exactly the tutorial I'm using! :D
(and the step I'm stuck at.)

This post has been edited by kaaie: 05 August 2009 - 07:49 PM

Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2