Jump to content


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


10 replies to this topic

#1 thatdude33

    New Member

  • Members
  • Pip
  • 4 posts

Posted 08 April 2007 - 02:58 AM

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 :).

#2 Reedbeta

    DevMaster Staff

  • Administrators
  • 4979 posts
  • LocationBellevue, WA

Posted 08 April 2007 - 04:13 AM

Searching for BMP File Format in google brought up this as the first result: http://www.fortuneci...4/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.
reedbeta.com - developer blog, OpenGL demos, and other projects

#3 thatdude33

    New Member

  • Members
  • Pip
  • 4 posts

Posted 08 April 2007 - 04:46 AM

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

#4 Reedbeta

    DevMaster Staff

  • Administrators
  • 4979 posts
  • LocationBellevue, WA

Posted 08 April 2007 - 05:02 AM

http://www.codersour..._io_binary.html
reedbeta.com - developer blog, OpenGL demos, and other projects

#5 thatdude33

    New Member

  • Members
  • Pip
  • 4 posts

Posted 08 April 2007 - 05:15 AM

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

#6 Reedbeta

    DevMaster Staff

  • Administrators
  • 4979 posts
  • LocationBellevue, WA

Posted 08 April 2007 - 07:34 AM

It's binary.
reedbeta.com - developer blog, OpenGL demos, and other projects

#7 STLDude

    Member

  • Members
  • PipPip
  • 59 posts

Posted 08 April 2007 - 07:52 AM

thatdude33 said:

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

#8 thatdude33

    New Member

  • Members
  • Pip
  • 4 posts

Posted 08 April 2007 - 02:30 PM

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!

#9 L1zb3th

    New Member

  • Members
  • PipPip
  • 10 posts

Posted 14 April 2007 - 03:44 PM

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 !

#10 pater

    Valued Member

  • Members
  • PipPipPip
  • 117 posts

Posted 14 April 2007 - 06:35 PM

L1zb3th said:

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

#11 Reedbeta

    DevMaster Staff

  • Administrators
  • 4979 posts
  • LocationBellevue, WA

Posted 14 April 2007 - 10:17 PM

thatdude33 said:

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.
reedbeta.com - developer blog, OpenGL demos, and other projects





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users