SDL LoadBMP Problem

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

RandomDever
Chaos Rift Regular
Chaos Rift Regular
Posts: 198
Joined: Thu Mar 26, 2009 8:42 pm
Current Project: My Engine
Programming Language of Choice: C++

SDL LoadBMP Problem

Post by RandomDever »

Code: Select all

SDL_Surface *image;
image = LoadBMP("mount.bmp");
But every time I compile it it says:
error C3861: 'LoadBMP': identifier not found
WTF? :(
User avatar
Bakkon
Chaos Rift Junior
Chaos Rift Junior
Posts: 384
Joined: Wed May 20, 2009 2:38 pm
Programming Language of Choice: C++
Location: Indiana

Re: SDL LoadBMP Problem

Post by Bakkon »

Code: Select all

SDL_Surface *image;
image = SDL_LoadBMP("mount.bmp");
;)
User avatar
MarauderIIC
Respected Programmer
Respected Programmer
Posts: 3406
Joined: Sat Jul 10, 2004 3:05 pm
Location: Maryland, USA

Re: SDL LoadBMP Problem

Post by MarauderIIC »

You might consider SDL_LoadPNG(), but you need sdl_image headers and stuff.
I realized the moment I fell into the fissure that the book would not be destroyed as I had planned.
User avatar
eatcomics
ES Beta Backer
ES Beta Backer
Posts: 2528
Joined: Sat Mar 08, 2008 7:52 pm
Location: Illinois

Re: SDL LoadBMP Problem

Post by eatcomics »

PNGs are a better format. I would definately advise you to at least get the SDL_image stuff... Just follow these instructions if you havn't:
http://lazyfoo.net/SDL_tutorials/lesson03/index.php
Image
RandomDever
Chaos Rift Regular
Chaos Rift Regular
Posts: 198
Joined: Thu Mar 26, 2009 8:42 pm
Current Project: My Engine
Programming Language of Choice: C++

Re: SDL LoadBMP Problem

Post by RandomDever »

I am only testing (I normally use PNG) and SDL_LoadBMP doesn't work.
BTW Where does the BMP have to be for it to load and what X,Y Coord? :|
Last edited by RandomDever on Mon Jun 29, 2009 10:39 am, edited 1 time in total.
User avatar
eatcomics
ES Beta Backer
ES Beta Backer
Posts: 2528
Joined: Sat Mar 08, 2008 7:52 pm
Location: Illinois

Re: SDL LoadBMP Problem

Post by eatcomics »

The bmp has to be in the same folder, unless you tell the compiler its somewhere else... but it'll be easier just to put it in the project folder ;)
Image
RandomDever
Chaos Rift Regular
Chaos Rift Regular
Posts: 198
Joined: Thu Mar 26, 2009 8:42 pm
Current Project: My Engine
Programming Language of Choice: C++

Re: SDL LoadBMP Problem

Post by RandomDever »

ok everything loads by my bmp isn't showing up.

Code: Select all

#include "SDL.h"
#include "SDL_image.h" 
#include <string> 

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 );
}


int main( int argc, char* args[] ) 
{ 
	//Start SDL
	SDL_Init( SDL_INIT_EVERYTHING ); 

	SDL_Surface *image;
	image = IMG_Load("mount.bmp");
	SDL_Surface *buffer;
	bool fullscreen = false;
	if ( fullscreen == true ) // For fullscreen
	buffer = SDL_SetVideoMode( 640, 480, 32, SDL_SWSURFACE |
	SDL_FULLSCREEN );
	else // For windowed
	buffer = SDL_SetVideoMode( 640, 480, 32, SDL_SWSURFACE );
	// Set window caption
	SDL_WM_SetCaption( "My Program : )", NULL );
/* End Initialization */

/* Game loop and such would go here */

apply_surface(20, 20, image, buffer );
SDL_Flip(buffer);
while(1){}
/* Free up space afterwards */

SDL_FreeSurface( buffer );

	//Quit SDL
	SDL_Quit();
	return 0;
} 
User avatar
Bakkon
Chaos Rift Junior
Chaos Rift Junior
Posts: 384
Joined: Wed May 20, 2009 2:38 pm
Programming Language of Choice: C++
Location: Indiana

Re: SDL LoadBMP Problem

Post by Bakkon »

Works fine for me. Make sure "mount.bmp" is in the same directory as your executable.

Few other problems you have though. SDL_Quit frees buffer for you, so you shouldn't do that manually, but you should be freeing image. Also, use SDL_Delay(milliseconds) until you've learned how to break out of your infinite loop.
RandomDever
Chaos Rift Regular
Chaos Rift Regular
Posts: 198
Joined: Thu Mar 26, 2009 8:42 pm
Current Project: My Engine
Programming Language of Choice: C++

Re: SDL LoadBMP Problem

Post by RandomDever »

Here's the image:
Image
Sorry when uploaded it converted into JPEG. But it's 60 x 60 and I'm using VC++ 2008 :(
Last edited by RandomDever on Mon Jun 29, 2009 10:36 am, edited 1 time in total.
User avatar
MarauderIIC
Respected Programmer
Respected Programmer
Posts: 3406
Joined: Sat Jul 10, 2004 3:05 pm
Location: Maryland, USA

Re: SDL LoadBMP Problem

Post by MarauderIIC »

RandomDever wrote:I am only testing normally PNG and SDL_LoadBMP doesn't work.
? That's because you have to load a bmp with it.
I realized the moment I fell into the fissure that the book would not be destroyed as I had planned.
User avatar
dandymcgee
ES Beta Backer
ES Beta Backer
Posts: 4709
Joined: Tue Apr 29, 2008 3:24 pm
Current Project: https://github.com/dbechrd/RicoTech
Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
Programming Language of Choice: C
Location: San Francisco
Contact:

Re: SDL LoadBMP Problem

Post by dandymcgee »

MarauderIIC wrote:
RandomDever wrote:I am only testing normally PNG and SDL_LoadBMP doesn't work.
? That's because you have to load a bmp with it.
I think he meant:
RandomDever wrote:I am only testing normally [with a bitmap]. SDL_LoadBMP doesn't work with PNG.
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches! :twisted:
RandomDever
Chaos Rift Regular
Chaos Rift Regular
Posts: 198
Joined: Thu Mar 26, 2009 8:42 pm
Current Project: My Engine
Programming Language of Choice: C++

Re: SDL LoadBMP Problem

Post by RandomDever »

OK

Code: Select all

#include "SDL.h"
#include "SDL_image.h" 
#include <string> 

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 );
}


int main( int argc, char* args[] ) 
{ 
	//Start SDL
	SDL_Init( SDL_INIT_EVERYTHING ); 

	SDL_Surface *image;
	image = IMG_Load("mount.bmp");
	SDL_Surface *buffer;
	bool fullscreen = false;
	if ( fullscreen == true ) // For fullscreen
	buffer = SDL_SetVideoMode( 640, 480, 32, SDL_SWSURFACE |
	SDL_FULLSCREEN );
	else // For windowed
	buffer = SDL_SetVideoMode( 640, 480, 32, SDL_SWSURFACE );
	// Set window caption
	SDL_WM_SetCaption( "My Program : )", NULL );
/* End Initialization */

/* Game loop and such would go here */

apply_surface(60, 60, image, buffer );
SDL_Flip(buffer);
SDL_Delay(20000);
/* Free up space afterwards */

SDL_FreeSurface( image );

	//Quit SDL
	SDL_Quit();
	return 0;
} 
Mount.bmp:
Image
<object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/BfqzA2QSVzc&hl ... ram><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/BfqzA2QSVzc&hl=en&fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object>[/youtube]
I'm using VC++ 2008 WTF is wrong?!?!?!?!?!?!?!?!?!
Last edited by RandomDever on Tue Jun 30, 2009 2:19 pm, edited 1 time in total.
User avatar
JaxDragon
Chaos Rift Junior
Chaos Rift Junior
Posts: 395
Joined: Mon Aug 04, 2008 2:03 pm
Current Project: Kanoba Engine
Favorite Gaming Platforms: PS3, PC
Programming Language of Choice: C++
Location: Northeast NC

Re: SDL LoadBMP Problem

Post by JaxDragon »

Put the image in your Debug folder. Look at my image below.

Image
RandomDever
Chaos Rift Regular
Chaos Rift Regular
Posts: 198
Joined: Thu Mar 26, 2009 8:42 pm
Current Project: My Engine
Programming Language of Choice: C++

Re: SDL LoadBMP Problem

Post by RandomDever »

View above post
User avatar
MarauderIIC
Respected Programmer
Respected Programmer
Posts: 3406
Joined: Sat Jul 10, 2004 3:05 pm
Location: Maryland, USA

Re: SDL LoadBMP Problem

Post by MarauderIIC »

Code: Select all

	SDL_Surface *image;
	image = IMG_Load("mount.bmp");
        if (!image)
            return -1;
	SDL_Surface *buffer;
Try that (or other output) to make sure that the image is loading correctly. Nothing in your code jumps out at me as being wrong. You might try applying the surface to 0,0 too, just to make sure :P

Also check the return value that BlitSurface gives.
I realized the moment I fell into the fissure that the book would not be destroyed as I had planned.
Post Reply