Writing a BMP from C++ [help please!]

A7b0620cf313e6e669245cfa312b2592
0
thatdude33 101 Apr 08, 2007 at 02:58

Hi everybody, I’m new here, and I have quite a problem.

I’ve been tearing my hair out trying to write a BMP file from a program of mine (a raytracer). Now, I have everything done, each pixel gets its own color value (r,g,b), but I can’t use any image displaying library (ex. Allegro, SDL) because there’s something wrong with my computer (don’t try to help me fix this, please).

What I would like, however is for somebody to either point me to a tutorial (note, I’m not that good at programming), or to a class that writes bmps, or, for that matter, any kind of images, and with a “how to use” sort of thing.

Thanks in advance :).

10 Replies

Please log in or register to post a reply.

A8433b04cb41dd57113740b779f61acb
0
Reedbeta 167 Apr 08, 2007 at 04:13

Searching for BMP File Format in google brought up this as the first result: http://www.fortunecity.com/skyscraper/windows/364/bmpffrmt.html

I’m sure google will help you further in this matter.

By the way, if your computer can’t use Allegro or SDL, something is not just wrong with it but SERIOUSLY wrong. I’d recommend you nuke and pave it (backup your data, whipe the hard drive, and reinstall everything) or if that doesn’t work, get a new computer.

A7b0620cf313e6e669245cfa312b2592
0
thatdude33 101 Apr 08, 2007 at 04:46

It’s just that for some reason system32 is completely read-only and I can’t do anything to change it.

Thanks for the reply, but I did search google for something I could understand, but maybe I could ask you to help me with what I found.

The thing that I don’t get is writing to the file. I’ve never done it before, and, to be honest, I don’t know where to start (yeah, I’m pretty much a noobie at this stuff).

So the main thing I don’t know how to do is how to write the data (in HEX, right?) to the file. So I have the headers done, but how do I convert them to the HEX that I need to write to my file? (Assume I know how to open and write a file with fstream.)

A7b0620cf313e6e669245cfa312b2592
0
thatdude33 101 Apr 08, 2007 at 05:15

I’m sorry, but that means nothing to me :(.
Wait, is a .bmp stored in binary? I thought it was in HEX…?

A8433b04cb41dd57113740b779f61acb
0
Reedbeta 167 Apr 08, 2007 at 07:34

It’s binary.

997e1243eb8e4ee07dff88ebc9bbbe9b
0
STLDude 101 Apr 08, 2007 at 07:52

@thatdude33

It’s just that for some reason system32 is completely read-only and I can’t do anything to change it.

You should not change anything in system32 directory, leave it alone. If you where trying to copy sdl, alegro dll’s there, you do not need to do this, just copy those files (dll’s) into same folder as your executable is (your program).

A7b0620cf313e6e669245cfa312b2592
0
thatdude33 101 Apr 08, 2007 at 14:30

The problem is that I don’t have administrative rights on my own computer (wierd, huh?). Please don’t ask about it. Anyway, so I tried to install the allegro devpack (yes, I’m using dev-c++), but when I verify the installation, it says the following files are missing: [about 100 files here]. I thought I might as well give it a try thought, right? So I linked liballeg.a and included <allegro.h>, but in the error message it told me, and I quote “Something must be terribly wrong with your code. Please fix it.”

And when I try to install manually, I have to write stuff in the system environment variables which is blocked.

Back on topic: what do I have to put in the main lines of the .bmp? Like after the header and what not?

EDIT-> How can I stop writing on one line with file.write() and start writing on another? I have everything else to write a .bmp in HEX, and I’m gonna use another program to convert the HEX to binary.

EDIT #2-> I GOT SDL WORKING! I’m happy. I guess then that my problem is solved!

E70f63aceb25fa57bee707b4edbef0c1
0
L1zb3th 101 Apr 14, 2007 at 15:44

xDDDDDDDD
if the computer doesn’t have enought privileges, HACK IT ….
because if your using it for programming, its nothing bad..
if is windows, is the most easy thing in the world …
ahh, and i foget :P :
the only thing that you need in Allegro is the alleg42.dll,source files and libraries ..
Have you tryed the GDI of windows ?
Au Revoir !

6d318bb67270aa12b325e2cd7b64ff7a
0
pater 101 Apr 14, 2007 at 18:35

@L1zb3th

xDDDDDDDD
if the computer doesn’t have enought privileges, HACK IT …. if is windows, is the most easy thing in the world …

That’s not exactly true. There’s a lot you can do (at least on XP Home) as unpriviledged user (sometimes even deleting important program files), but it’s definitelly NOT possible to gain administrative priviledges without knowing the admin password. Windows XP is not 95 any more!
But, as stated above, programming without administrative rights is kinda hard to do, as you might not even have the right to debug your own processes. The simplest thing would probably be to ask your administrator for the proper rights…

A8433b04cb41dd57113740b779f61acb
0
Reedbeta 167 Apr 14, 2007 at 22:17

@thatdude33

How can I stop writing on one line with file.write() and start writing on another? I have everything else to write a .bmp in HEX, and I’m gonna use another program to convert the HEX to binary.

Don’t do that. There’s no reason to use another program to convert hex (presumably you mean hex codes stored in text format…) to binary. file.write writes in binary directly.