Page 2 of 3
Re: loading a .bmp file into SDL
Posted: Mon Jun 04, 2012 7:46 pm
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?
Re: loading a .bmp file into SDL
Posted: Mon Jun 04, 2012 8:08 pm
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......
Re: loading a .bmp file into SDL
Posted: Mon Jun 04, 2012 9:27 pm
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????
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.
Re: loading a .bmp file into SDL
Posted: Mon Jun 04, 2012 9:49 pm
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!
Re: loading a .bmp file into SDL
Posted: Mon Jun 04, 2012 10:18 pm
by azaron08
I tried putting "bmp.bmp" into the debug folder and it didn't change anything it still shows a blank screen
Re: loading a .bmp file into SDL
Posted: Tue Jun 05, 2012 12:53 pm
by azaron08
The thing wont even let me scout anything and iostream is included
Re: loading a .bmp file into SDL
Posted: Tue Jun 05, 2012 1:03 pm
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;
}
Re: loading a .bmp file into SDL
Posted: Tue Jun 05, 2012 2:17 pm
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;
}
Re: loading a .bmp file into SDL
Posted: Tue Jun 05, 2012 2:25 pm
by azaron08
sorry i didnt know how....
Re: loading a .bmp file into SDL
Posted: Tue Jun 05, 2012 2:45 pm
by OmenFelix
azaron08 wrote:sorry i didnt know how....
Dude...the button to the right of the 'Quote' one, clearly says 'Code'. Ah well. :3
Re: loading a .bmp file into SDL
Posted: Tue Jun 05, 2012 3:21 pm
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.
Re: loading a .bmp file into SDL
Posted: Tue Jun 05, 2012 3:30 pm
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
Re: loading a .bmp file into SDL
Posted: Tue Jun 05, 2012 3:36 pm
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").
Re: loading a .bmp file into SDL
Posted: Tue Jun 05, 2012 3:44 pm
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
cld u show me the code .... like the one u did of mine where u fixed it???
Re: loading a .bmp file into SDL
Posted: Tue Jun 05, 2012 3:47 pm
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.