loading a .bmp file into SDL
Moderator: PC Supremacists
loading a .bmp file into SDL
Hello,
I need help. Ive been looking at tons of tutorials and searching on google for ways to get
pictures into my project in sld.....and need to learn it to continue with my tutorials!!! I wld like a really detailed answear but any help wanted!!! Also I'm looking for a more professional programmer that might be up to giving me some guidence if anyone would be intresed!!
Thank you
I need help. Ive been looking at tons of tutorials and searching on google for ways to get
pictures into my project in sld.....and need to learn it to continue with my tutorials!!! I wld like a really detailed answear but any help wanted!!! Also I'm looking for a more professional programmer that might be up to giving me some guidence if anyone would be intresed!!
Thank you
- lalacomun
- VS Setup Wizard
- Posts: 114
- Joined: Wed Dec 28, 2011 10:18 pm
- Favorite Gaming Platforms: psx, nintendo ds, gameboy advance, xbox 360, ps2
- Programming Language of Choice: C++
- Location: Argentina
- Contact:
Re: loading a .bmp file into SDL
so you want to load a BMP image into your game using SDL ?? if so yo should use the following function:
SDL_LoadBMP("location of file.bmp");
here, a code on how to load, and blit an image :
SDL_LoadBMP("location of file.bmp");
here, a code on how to load, and blit an image :
Code: Select all
SDL_Surface *image;
SDL_Surface *screen;
int main(int argc,char *argv[])
{
...//initialize and other crap
screen = SDL_SetVideoMode(640,480,32,SDL_SWSURFACE);
image = SDL_LoadBMP("LocationOfFile.bmp"); // load the image
SDL_BlitSurface(player,NULL,screen,NULL); // use this function to blit the image onto you screen
SDL_Flip(screen); //you need to flip your buffer so you can actually see something
..//rest of crap
}
- superLED
- Chaos Rift Junior
- Posts: 303
- Joined: Sun Nov 21, 2010 10:56 am
- Current Project: Engine
- Favorite Gaming Platforms: N64
- Programming Language of Choice: C++, PHP
- Location: Norway
Re: loading a .bmp file into SDL
That's why we have www.lazyfoo.net
Check it out. I guess that page has helped most of us on the forum, that have walked the path of SDL.
Check it out. I guess that page has helped most of us on the forum, that have walked the path of SDL.
Re: loading a .bmp file into SDL
Thank you so much and ive been to lazyfoo I just don't understand some of it!
Re: loading a .bmp file into SDL
also do i need to save my file or picture any where and if so where???? i already had the format shown above but it still only shows a black screen ....... idk wht im doing wrong but i never get an error
- superLED
- Chaos Rift Junior
- Posts: 303
- Joined: Sun Nov 21, 2010 10:56 am
- Current Project: Engine
- Favorite Gaming Platforms: N64
- Programming Language of Choice: C++, PHP
- Location: Norway
Re: loading a .bmp file into SDL
If you save it in the directory where you .exe file is, just load it like this: "image.bmp"
If you have a folder for you images (and the image folder is in the same directory as the .exe file), load it like this: "img_folder/image.bmp"
Remember to have the same set-up (folders and files) in the Debug/Release and the folder you have your project in.
If you have a folder for you images (and the image folder is in the same directory as the .exe file), load it like this: "img_folder/image.bmp"
Remember to have the same set-up (folders and files) in the Debug/Release and the folder you have your project in.
Re: loading a .bmp file into SDL
so the file directory is that were the all the files are or inside of the the one project file........ive tried both but i wasnt for sure and th "image.bmp" does that mean i save the file as image? or image.bmp??
- superLED
- Chaos Rift Junior
- Posts: 303
- Joined: Sun Nov 21, 2010 10:56 am
- Current Project: Engine
- Favorite Gaming Platforms: N64
- Programming Language of Choice: C++, PHP
- Location: Norway
Re: loading a .bmp file into SDL
No, you can name it as you like. But if you are trying to load up a BMP file, you'd better off saving it as a .bmp file. "whatever.bmp"azaron08 wrote:so the file directory is that were the all the files are or inside of the the one project file........ive tried both but i wasnt for sure and th "image.bmp" does that mean i save the file as image? or image.bmp??
If you want to load up .png files or .jpg files, you should look into SDL_image (it's pretty simple to add, and you would only change the Load_BMP function to IMG_Load or something)
Re: loading a .bmp file into SDL
how do i save it as a .bmp file? just name it "image.bmp"?
- superLED
- Chaos Rift Junior
- Posts: 303
- Joined: Sun Nov 21, 2010 10:56 am
- Current Project: Engine
- Favorite Gaming Platforms: N64
- Programming Language of Choice: C++, PHP
- Location: Norway
Re: loading a .bmp file into SDL
When you are done drawing your image, click on File -> Save As -> type in a name for your image, and chose ".bmp" as the desired filetype.
Re: loading a .bmp file into SDL
k ill c wht i can do.....and skype isnt work n for me any other options???
Last edited by azaron08 on Mon Jun 04, 2012 7:10 pm, edited 1 time in total.
Re: loading a .bmp file into SDL
i cant save as just a bmp i can only save it as a "24-bit Bitmap (*.bmp;*.dib) is that it????
Re: loading a .bmp file into SDL
this is what i have and all it does is load a black screen:
Code: Select all
#include <SDL.h>
#include <string>
int main( int argc,char* args[] )
{
//initilization,setup screen,running screen
SDL_Init(SDL_INIT_EVERYTHING);
SDL_Surface*screen;
SDL_Surface*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,0x00,0x00,0x00);
Uint32 color2=SDL_MapRGB(screen->format,0xff,0x00,0x00);
image=SDL_LoadBMP("bmp.bmp");
while (running)
{
start=SDL_GetTicks();
SDL_Event event;
while(SDL_PollEvent(&event))
{
switch(event.type)
{
case SDL_QUIT:
running=false;
break;
case SDL_KEYDOWN:
switch(event.key.keysym.sym)
{
case SDLK_UP:
b[0]=1;
break;
case SDLK_DOWN:
b[1]=1;
break;
case SDLK_LEFT:
b[2]=1;
break;
case SDLK_RIGHT:
b[3]=1;
break;
}
break;
case SDL_KEYUP:
switch(event.key.keysym.sym)
{
case SDLK_UP:
b[0]=0;
break;
case SDLK_DOWN:
b[1]=0;
break;
case SDLK_LEFT:
b[2]=0;
break;
case SDLK_RIGHT:
b[3]=0;
break;
}
break;
}
}
//logic&& render
if(b[0])
rect.y--;
if(b[1])
rect.y++;
if(b[2])
rect.x--;
if(b[3])
rect.x++;
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_Quit();
return 0;
}
- dandymcgee
- 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
"Longbottom, at the end of this lesson we will feed a few drops of this potion to your toad and see that happens. Perhaps that will encourage you to do it properly."azaron08 wrote:k ill c wht i can do.....and skype isnt work n for me any other potions???
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches!
Re: loading a .bmp file into SDL
Wht the h*ll does that mean