Archived

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

astrocrep

Easy Question: BMP Loading...

Recommended Posts

I am working on a very simple game engine... Just uses 16x16 tiles to create a map. How can I load and draw a bmp. I used to know something along the lines of: bmp1 = LoadBMP("tile1.bmp"); DrawBMP(bmp1,x,y); But can''t fine it anymore. Any Help Greatly Appreciated! Thanks Alot, Rich P.S. I am Using OpenGL/GLUT as the sub-system for my graphics.

Share this post


Link to post
Share on other sites
Yeah Ive been going throu them... there all pretty good... but I don''t need to get all into textures... plus theres no easy clear cut way to load and then draw... I don''t need scaling.. or anything...

Just simplicity...

Thanks
Rich

Share this post


Link to post
Share on other sites
2D doesn''t mean 2D anymore. It means 2D with the camera perpendicular to the plane that you''re drawing on.
But hey, put it this way, at least you can spend a little time developing the camera code and you''ll have yourself a much more interesting over-head game

Share this post


Link to post
Share on other sites
Well, you could use LoadImage which loads bitmaps.
Or you could go here - http://opengl.nutty.org/OpenIL/

I recommend using either PNG or JPG files rather than bitmaps. They are much smaller.

Share this post


Link to post
Share on other sites
a bitmap file, in true color has 24 bits per pixel
(3 bytes, one for red, green, blue)
the image starts at offset 54.
a 640x480 image will then be 640x480x3=921600 bytes,
plus the header, 54 bytes equals 921654 bytes.

hoped it helped...

[Hugo Ferreira][Positronic Dreams]
Need [3D Artist] & [Sound Designer]
for small project. Contact me plz...

Share this post


Link to post
Share on other sites
I believe a BMP file also stores the data in the form BGR, not RGB as you might expect, so the byte at 0x36 is in fact the blue component of the first pixel, 0x37 is the green, and 0x38 is the red.



[edited by - Nemesis2k2 on March 7, 2003 7:06:53 AM]

Share this post


Link to post
Share on other sites
Hey Nemesis2k2, you are correct about the swap of Blue and Red components. To correct this use a feature of OpenGL to correct this for you if you don''t want to write the code to swap the bytes. Use GL_BGR or GL_BGR_EXT instead of GL_RGB when using gluBuild2DMipmaps() or glTexImage2D().

Example:
gluBuild2DMipmaps(GL_TEXTURE_2D, 3, Image.sizeX, Image.sizeY, GL_BGR, GL_UNSIGNED_BYTE, Image.data);

if you are using an old gl.h v1.1 header file then GL_BGR will not be defined so use GL_BGR_EXT. Or throw the following into you code:

#define GL_BGR 0x80E0

Share this post


Link to post
Share on other sites
quote:
Original post by nfz
Hey Nemesis2k2, you are correct about the swap of Blue and Red components. To correct this use a feature of OpenGL to correct this for you if you don''t want to write the code to swap the bytes. Use GL_BGR or GL_BGR_EXT instead of GL_RGB when using gluBuild2DMipmaps() or glTexImage2D().

Example:
gluBuild2DMipmaps(GL_TEXTURE_2D, 3, Image.sizeX, Image.sizeY, GL_BGR, GL_UNSIGNED_BYTE, Image.data);

if you are using an old gl.h v1.1 header file then GL_BGR will not be defined so use GL_BGR_EXT. Or throw the following into you code:

#define GL_BGR 0x80E0




Or you might just want to swap the variables:

for (i = 0; i < width * height; i++) {

imageData ^= imageData[i + 2];
imageData[i + 2] ^= imageData[i];
imageData[i] ^= imageData[i + 2];

And that''s all there is to it.

Share this post


Link to post
Share on other sites