Archived

This topic is now archived and is closed to further replies.

Ferneu

Loading a BMP file on the screen (DOS)... yep, another noob...

Recommended Posts

Well, another noob asking for the same thing. Anyway, since all the topics I''ve read asking for this received recommendations like: go to windows... get Allegro... I''m not really willing to make a game or so. At least not yet. All I wanna do is to load a small .bmp file into a little C program. I''m using turbo C, and I was reading an old Herbert Schildt book (1988, see OLD) and there he teaches how to intialize the graphics mode, and so on... He also teaches how to create a sprite and move it around the screen. In the matter of fact, he even teaches you how to create a simple game, I think you guys call it TAG or something, a game where your goal is to touch the other guy and then you run away from him, and when he touches you... you got the point. The problem is that he only teaches how to use a sprite you''ve made inside the code, a global array like: int human[4][4] = { 1, 6, 6, 6, 4, 2, 3, 9, 9, 1, 6, 6, 9, 11, 6, 6 }; which works fine, but I haven''t found anything about how load it from a simple, uncompressed, black & white, .bmp file. Turbo C have some graphics functions which are shown on some BGI demo files, like putimage(), but the demo code also uses a sprite which is created inside the code, it''s just a circle (elipse actually, guess). Summing up: I want to load a bmp from a file to the screen (on DOS). I''ve already have knowledge on how to initialize the graphics mode, accessing the video RAM and so on. Just can load the image from the file to the screen. Any old graphics tutorial would help, in case you can guys do not have time to spend with the noobie here. PS: My English may be bad when I''m writing, but I have excelent reading skills, so don''t worry about anything when answering this. LOL ?

Share this post


Link to post
Share on other sites
Yes don't use DOS if you don't need to unless you really want to...I suggest you try using some kind of API this one is the easiest to get started with in my opinion click, it's not the only one you can use so you should make some research of your own on which one you want to use...

About your problem you need to use binary files here's a good reference clicky

[edited by - FtMonkey on August 10, 2003 2:07:19 AM]

Share this post


Link to post
Share on other sites
You should try programming the GBA. I hear in alot of ways it''s similar to old DOS programming.

Anyway...

What you''ll need:
- A hex editor.
- A C compiler.
- A computer with a file system.

What you need to do:
- Open the hex editor.
- Enter some data. The example you showed would be something like ''01 06 06 06 04 02 03 09 09 01 06 06 09 0B 06 06''
- Save your new file and remember where you put it.
- This is the code you''ll need to load your image (not tested):

#include <stdio.h>

typedef unsigned char Pixel;

#define IMAGE_HEIGHT 4
#define IMAGE_WIDTH 4
typedef Pixel[IMAGE_WIDTH*IMAGE_HEIGHT] Image;

int LoadImage(const char* filename, Image image)
{
FILE *file = fopen(filename, "rb");
int okay = 0;

if(!file)
return 0;

if(fread(image, sizeof(Image), 1, file))
okay = 1;

fclose(file);

return okay; // will return 1 if everything is okay, 0 if something went wrong.
}

// Examples for reading and writing data from the images

Pixel GetPixel(int x, int y, Image image)
{
if(x < 0 || x >= IMAGE_WIDTH || y < 0 || y >= IMAGE_HEIGHT)
return 0;
else
return image[x+y*IMAGE_WIDTH];
}

void SetPixel(Pixel p, int x, int y, Image image)
{
if(x >= 0 && x < IMAGE_WIDTH && y >= 0 && y < IMAGE_HEIGHT)
image[x+y*IMAGE_WIDTH] = p;
}

Share this post


Link to post
Share on other sites
Hey guys, thx again for all the help.
I''ve got so excited when the bmp showed up on the
screen that I''ve forgotten to tell you what exactly
I have done.

Well, here you go: http://www.brackeen.com/home/vga/
there you can find a complete tut on how to load
some 256 color bmps on DOS, the way the guy teaches
looks like the way I was trying to do it, using
the BIOS interrupt and pointers to the video memory,
the difference is that he''s done it right hehe

Thx again for all the help.

Share this post


Link to post
Share on other sites