loading a .bmp file into SDL

Anything related in any way to game development as a whole is welcome here. Tell us about your game, grace us with your project, show us your new YouTube video, etc.

Moderator: PC Supremacists

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: loading a .bmp file into SDL

Post by dandymcgee »

azaron08 wrote:Wht the h*ll does that mean
This may help you solve your spelling problem.
This may help you solve your IRC problem.
Google may help you solve the rest of your problems.

Do you even think before you type?
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches! :twisted:
azaron08
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 40
Joined: Sun May 27, 2012 12:50 pm

Re: loading a .bmp file into SDL

Post by azaron08 »

Yes I knw how 2 spell I just choose not 2.....I rlly need help with programming plz don't be a Dick and help me......
User avatar
Ginto8
ES Beta Backer
ES Beta Backer
Posts: 1064
Joined: Tue Jan 06, 2009 4:12 pm
Programming Language of Choice: C/C++, Java

Re: loading a .bmp file into SDL

Post by Ginto8 »

azaron08 wrote:Yes I knw how 2 spell I just choose not 2.....I rlly need help with programming plz don't be a Dick and help me......
First, do not insult our intelligence by intentionally making yourself seem stupider than you claim to be. If you don't at least try to spell things correctly, there is no way in hell that we will take you seriously.
Second, don't call dandy a dick. Not only is he one of the most reasonable (and lenient) mods I've ever come across, he is instantaneously your superior by virtue of having to deal with the vacuous and petty insults of people like you.
Third, you are most certainly not in a position to make demands for help or kindness. Earn enough respect and maybe you could get away with it, but I think that whoever could earn that much respect wouldn't need the help or kindness anyway.

I'm personally still willing to help you, but don't think that you have earned anything even vaguely resembling respect.
azaron08 wrote:i cant save as just a bmp i can only save it as a "24-bit Bitmap (*.bmp;*.dib) is that it???? :oops:
We call it "bmp" because that's the typical filename suffix. Yes, bmp is short for Bitmap, and the 24-bit aspect is rather incidental in this case, just as it's incidental that the colors are in BGR order.

So, regarding your program, I would put in some cout's or printf's or whatever suits your fancy and print out the value of image. I'd bet that it's 0, aka NULL. If it is in fact NULL, it means that it was unable to find the image. One of two things happened here: either you named the file incorrectly, or you're running the program from the wrong directory. If you're using an IDE such as MSVC++, it probably runs the program in the same directory as the executable file (which is usually named either Debug or Release). Drop the file there and it should work.
Quit procrastinating and make something awesome.
Ducky wrote:Give a man some wood, he'll be warm for the night. Put him on fire and he'll be warm for the rest of his life.
azaron08
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 40
Joined: Sun May 27, 2012 12:50 pm

Re: loading a .bmp file into SDL

Post by azaron08 »

My bad....sorry just pisses me off at the program not working......ive been trying tons of stuff 4 like 2 weeks and havent gotten any results. Ill try and put the picture in the debug file because I'm using c++ and its one thing I haven't tried!
azaron08
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 40
Joined: Sun May 27, 2012 12:50 pm

Re: loading a .bmp file into SDL

Post by azaron08 »

I tried putting "bmp.bmp" into the debug folder and it didn't change anything it still shows a blank screen
azaron08
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 40
Joined: Sun May 27, 2012 12:50 pm

Re: loading a .bmp file into SDL

Post by azaron08 »

The thing wont even let me scout anything and iostream is included :twisted:
azaron08
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 40
Joined: Sun May 27, 2012 12:50 pm

Re: loading a .bmp file into SDL

Post by azaron08 »

it doesnt look like any thing is wrong with the code!! u tell me!! i cant figure it out.....it will pull up a white screen but no image:

#include <SDL.h>
#include <string>
#include <iostream>
using namespace std;
int main( int argc,char* args[] )
{
//initilization,setup screen,running screen
SDL_Init(SDL_INIT_EVERYTHING);
SDL_Surface*screen,*image;
screen=SDL_SetVideoMode(640,480,32,SDL_SWSURFACE);
bool running=true;
const int FPS=30;
Uint32 start;
bool b[4]={0,0,0,0};
SDL_Rect rect;
rect.x=10;
rect.y=10;
rect.w=20;
rect.h=20;
Uint32 color=SDL_MapRGB(screen->format,0xff,0xff,0xff);
Uint32 color2=SDL_MapRGB(screen->format,0xff,0x00,0x00);
image=SDL_LoadBMP("bmp.bmp");
cout<<image;
while (running)
{
start=SDL_GetTicks();
SDL_Event event;
while(SDL_PollEvent(&event))
{
switch(event.type)
{
case SDL_QUIT:
running=false;
break;

break;

}
}
//logic




//render
SDL_FillRect(screen,&screen->clip_rect,color);
//SDL_FillRect(screen,&rect,color2);
SDL_BlitSurface(image,NULL,screen,NULL);
SDL_Flip(screen);
if(1000/FPS>SDL_GetTicks()-start)
SDL_Delay(1000/FPS-(SDL_GetTicks()-start));


}

SDL_FreeSurface(image);
SDL_Quit();
return 0;
}
User avatar
OmenFelix
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 59
Joined: Fri May 04, 2012 1:42 pm
Current Project: Arcadian Descent(C++, SDL, KOS)
Favorite Gaming Platforms: PS2, PC, XBOX, NDS
Programming Language of Choice: C/C++

Re: loading a .bmp file into SDL

Post by OmenFelix »

azaron08 wrote:it doesnt look like any thing is wrong with the code!! u tell me!! i cant figure it out.....it will pull up a white screen but no image:

#include <SDL.h>
#include <string>
#include <iostream>
using namespace std;
int main( int argc,char* args[] )
{
//initilization,setup screen,running screen
SDL_Init(SDL_INIT_EVERYTHING);
SDL_Surface*screen,*image;
screen=SDL_SetVideoMode(640,480,32,SDL_SWSURFACE);
bool running=true;
const int FPS=30;
Uint32 start;
bool b[4]={0,0,0,0};
SDL_Rect rect;
rect.x=10;
rect.y=10;
rect.w=20;
rect.h=20;
Uint32 color=SDL_MapRGB(screen->format,0xff,0xff,0xff);
Uint32 color2=SDL_MapRGB(screen->format,0xff,0x00,0x00);
image=SDL_LoadBMP("bmp.bmp");
cout<<image;
while (running)
{
start=SDL_GetTicks();
SDL_Event event;
while(SDL_PollEvent(&event))
{
switch(event.type)
{
case SDL_QUIT:
running=false;
break;

break;

}
}
//logic




//render
SDL_FillRect(screen,&screen->clip_rect,color);
//SDL_FillRect(screen,&rect,color2);
SDL_BlitSurface(image,NULL,screen,NULL);
SDL_Flip(screen);
if(1000/FPS>SDL_GetTicks()-start)
SDL_Delay(1000/FPS-(SDL_GetTicks()-start));


}

SDL_FreeSurface(image);
SDL_Quit();
return 0;
}
Dude, seriously? Format your code using the code tag for god sake. -_-

Code: Select all

#include <SDL.h>
#include <string>
#include <iostream>
using namespace std;
int main( int argc,char* args[] )
{
	//initilization,setup screen,running screen
	SDL_Init(SDL_INIT_EVERYTHING);
	SDL_Surface*screen,*image;
	screen=SDL_SetVideoMode(640,480,32,SDL_SWSURFACE);
	bool running=true;
	const int FPS=30;
	Uint32 start;
	bool b[4]={0,0,0,0};
	SDL_Rect rect;
	rect.x=10;
	rect.y=10;
	rect.w=20;
	rect.h=20;
	Uint32 color=SDL_MapRGB(screen->format,0xff,0xff,0xff);
	Uint32 color2=SDL_MapRGB(screen->format,0xff,0x00,0x00);
	image=SDL_LoadBMP("bmp.bmp");
	cout<<image;
	while (running)
	{ 
		start=SDL_GetTicks();
		SDL_Event event;
		while(SDL_PollEvent(&event))
		{
			switch(event.type)
			{
			case SDL_QUIT:
				running=false;
				break;
			
				break;

			}
		}
		//logic 
		
		
		
		
		//render
		SDL_FillRect(screen,&screen->clip_rect,color);
		//SDL_FillRect(screen,&rect,color2);
		SDL_BlitSurface(image,NULL,screen,NULL);
		SDL_Flip(screen);
		if(1000/FPS>SDL_GetTicks()-start)
			SDL_Delay(1000/FPS-(SDL_GetTicks()-start));
		

	}
	
		SDL_FreeSurface(image);
		SDL_Quit();
		return 0;
}
Why not check out my game-development forum at: http://f1rel0ck.netai.net
Or my 2D RPG at: https://www.facebook.com/pages/Arcadian ... 6873806531
Image
Image
Image
azaron08
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 40
Joined: Sun May 27, 2012 12:50 pm

Re: loading a .bmp file into SDL

Post by azaron08 »

sorry i didnt know how.... :oops:
User avatar
OmenFelix
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 59
Joined: Fri May 04, 2012 1:42 pm
Current Project: Arcadian Descent(C++, SDL, KOS)
Favorite Gaming Platforms: PS2, PC, XBOX, NDS
Programming Language of Choice: C/C++

Re: loading a .bmp file into SDL

Post by OmenFelix »

azaron08 wrote:sorry i didnt know how.... :oops:
Dude...the button to the right of the 'Quote' one, clearly says 'Code'. Ah well. :3
Why not check out my game-development forum at: http://f1rel0ck.netai.net
Or my 2D RPG at: https://www.facebook.com/pages/Arcadian ... 6873806531
Image
Image
Image
User avatar
YourNerdyJoe
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 79
Joined: Sun Oct 02, 2011 3:28 pm
Current Project: Top secret (not really) Top-Down Shooter for GBA
Favorite Gaming Platforms: GBA, Gamecube, PC, 3DS
Programming Language of Choice: C/C++
Contact:

Re: loading a .bmp file into SDL

Post by YourNerdyJoe »

If you're using visual studio and are running the program from within it (by pushing F5) then you have to put the image in the same directory as the code.
Otherwise put it in the folder with program.exe and double click it.
See that?.....
Exactly
https://yournerdyjoe.github.io/
azaron08
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 40
Joined: Sun May 27, 2012 12:50 pm

Re: loading a .bmp file into SDL

Post by azaron08 »

Were is the codes directory......sorry I'm rlly new to this.........I'm probly a burden or iratent but I rally just wanna understand everything
User avatar
bbguimaraes
Chaos Rift Junior
Chaos Rift Junior
Posts: 294
Joined: Wed Apr 11, 2012 4:34 pm
Programming Language of Choice: c++
Location: Brazil
Contact:

Re: loading a .bmp file into SDL

Post by bbguimaraes »

I compiled your code, put an image on the same folder as the executable named bmp.bmp, and it ran perfectly. So it probably is just a matter of positioning your file. Try this: put this at the beggining of your code:

Code: Select all

system("pwd"); // for unix
system("dir"); // for Windows
This should give you the current directory.

Remember you'll need to include <cstdlib> and that system is inside the std namespace (either use using namespace std, using std::system or replace system("pwd") by std::system("pwd").
azaron08
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 40
Joined: Sun May 27, 2012 12:50 pm

Re: loading a .bmp file into SDL

Post by azaron08 »

so i just put "dir" code infront of everything and it does wht? and where shld i move the bmp.bmp file to because i have no clue where the .exe file is! i feel like an idiot :oops: cld u show me the code .... like the one u did of mine where u fixed it???
Last edited by azaron08 on Tue Jun 05, 2012 3:47 pm, edited 1 time in total.
User avatar
bbguimaraes
Chaos Rift Junior
Chaos Rift Junior
Posts: 294
Joined: Wed Apr 11, 2012 4:34 pm
Programming Language of Choice: c++
Location: Brazil
Contact:

Re: loading a .bmp file into SDL

Post by bbguimaraes »

Oh yes, I forgot to say it outputs to the console (or wherever your standard output is directed). What are you using to compile and run your code? There is probably a place where it says the working directory.
Post Reply