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

Started by
5 comments, last by Ferneu 20 years, 8 months ago
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 ?
Advertisement
Look up fopen/fread/fclose.
Chess is played by three people. Two people play the game; the third provides moral support for the pawns. The object of the game is to kill your opponent by flinging captured pieces at his head. Since the only piece that can be killed is a pawn, the two armies agree to meet in a pawn-infested area (or even a pawn shop) and kill as many pawns as possible in the crossfire. If the game goes on for an hour, one player may legally attempt to gouge out the other player's eyes with his King.
Using DOS is considerably harder than windows/opengl/etc. Just warning you.
-~-The Cow of Darkness-~-
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]
The monkeys are listening...
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  4typedef 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 imagesPixel 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; }
Chess is played by three people. Two people play the game; the third provides moral support for the pawns. The object of the game is to kill your opponent by flinging captured pieces at his head. Since the only piece that can be killed is a pawn, the two armies agree to meet in a pawn-infested area (or even a pawn shop) and kill as many pawns as possible in the crossfire. If the game goes on for an hour, one player may legally attempt to gouge out the other player's eyes with his King.
Thx guys. I''ve done it now.

Thanks
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.

This topic is closed to new replies.

Advertisement