This is cool - applying it to OpenGL

Jones
Unregistered
 
Post: #1
I found a cool tutorial/sample of loading a BMP image.

Linky.

I noticed a small error in it:

Code:
read(&bitmapFileHeader, sizeof(BITMAPFILEHEADER,1,filePtr);

Should be:

Code:
read(&bitmapFileHeader, sizeof(BITMAPFILEHEADER,1),filePtr);

I think, although I'm pretty sure the sizeof() function only takes on argument. Other than that, I think it's actually managed to explain something I never understood. Only one problem, how to make an OpenGL texture from it?

Thanks.

EDIT: Also, why does he load the bitmap data to an unsigned char? Wouldn't pixel data always be integer based, as it consists of numbers designating RGB values?
Quote this message in a reply
Moderator
Posts: 508
Joined: 2002.09
Post: #2
This is cooler Wink

"When you dream, there are no rules..."
Quote this message in a reply
Sage
Posts: 1,403
Joined: 2005.07
Post: #3
Misleading topic...

you can probably search this forum for texture loading, in fact heres how to turn animated gif's into textures: http://idevgames.com/forum/showthread.php?p=114803

edit: Taxxodium you beat me AGAIN LOL

Sir, e^iπ + 1 = 0, hence God exists; reply!
Quote this message in a reply
Member
Posts: 245
Joined: 2005.11
Post: #4
Actually it should almost certainly be
Code:
read(&bitmapFileHeader, sizeof(BITMAPFILEHEADER), 1, filePtr);
since, as you say, sizeof() only takes one argument. The bitmap image will use, at most, 8 bits per channel, so it is stored as an array of bytes. If you don't want to use unsinged chars you can use UInt8s, which are exactly the same thing.
Quote this message in a reply
Jones
Unregistered
 
Post: #5
Quote:Misleading topic...

you can probably search this forum for texture loading, in fact heres how to turn animated gif's into textures: http://idevgames.com/forum/showthread.php?p=114803

edit: Taxxodium you beat me AGAIN

Except that I am not dealing with Gif's, nor am I using Cocoa/Quartz, as that limits future portability of anything I do. I've got a copy of Apple's OpenGL guide lying around. Truthfully, I never really saw how it could help me with what I'm doing (GLUT and OpenGL, not CGL or AGL).
Quote this message in a reply
Sage
Posts: 1,403
Joined: 2005.07
Post: #6
dude... look at the opengl bits of it that send the texture to opengl Huh

Sir, e^iπ + 1 = 0, hence God exists; reply!
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #7
That tutorial won't work on big-endian machines (any PowerPC Mac), and it relies heavily on Windows types which you'd have to define for yourself. It also doesn't tell you how to send that data to OpenGL, which might turn out to be handy Rasp

As always, I recommend ImageIO if you just need Mac/10.4+ support; QuickTime if you just need Mac/10.0.0+ support, and libpng or libjpeg if you need cross-platform support.
Quote this message in a reply
Jones
Unregistered
 
Post: #8
OneSadCookie Wrote:That tutorial won't work on big-endian machines (any PowerPC Mac), and it relies heavily on Windows types which you'd have to define for yourself. It also doesn't tell you how to send that data to OpenGL, which might turn out to be handy Rasp

As always, I recommend ImageIO if you just need Mac/10.4+ support; QuickTime if you just need Mac/10.0.0+ support, and libpng or libjpeg if you need cross-platform support.

I've tried libpng, unfortunatly I'm not sure I understand all the stuff in the tutorial code. Nor am I sure all of it is valid... for example, the function prototype they show you is lacking the types for the arguments... am I to guess? Rasp (I'm talking about the code on the O'Reilly webpage.) I'm gonna try this, assuming that the filename is *char[], the x and y sizes are *int and the image data is unsigned *char. But why would the x and y sizes need to be integers? And is it absolutely neccessary to have the x and y values provided on load?

I would much rather write the image loading stuff myself, but I have no idea how to check for endianess of the system, or how the file is encoded (endianess-wise), for example.

You know, sometimes, when I look at these file formats... I say to myself; "Damn, you know, even I could make an easier-to-use format than that!". Maybe that's BS, but is it too much to ask that pixel colors are stored as ints in a text file, with no endianess-knowledge required? Rasp

In the meantime, I'll try libpng again. Another alternative I've presented myself, is converting SDL surfs to GL textures, but that would require the actual use of SDL. And I don't like how it interfaces with OpenGL... GLUT is much more... "clean".
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #9
You will always have to deal with endianness when reading & writing binary files. That's just the nature of the beast.

Yes, you can make an easier-to-use file format, but it will a) be much larger, and b) be nonstandard, so you'll end up having to write a converter to that format anyway Rasp

I don't think the O'Reilly libpng tutorial is the best ever. I'd point you here: http://onesadcookie.com/svn/repos/RubyGa...urce/png.c but quite frankly, I'm not sure you understand enough to extract the PNG code from the little bit of ruby wrapping surrounding it.

ImageIO code is here: http://gamewiki.evolpenguin.com/index.ph...re_Loading

QuickTime code is here:
http://onesadcookie.com/svn/repos/QTValuePak

either is substantially easier than libpng.
Quote this message in a reply
Jones
Unregistered
 
Post: #10
I've been looking at DevIL, and so far, based on what I've read in the manual, it seems powerful and easy to use, two desirable features. It requires a lot of packages, but come with it, so no trouble there.

Question:

If eventually I wanted to distribute something that used DevIL, I would have to ship/package the devil libraries with it, correct? (Along with anything else...) They are not, it would seem, frameworks which brings up another issue for me...

How to link to them? Annoyed
Quote this message in a reply
Sage
Posts: 1,403
Joined: 2005.07
Post: #11
I suppose internet searching could help you.

Sir, e^iπ + 1 = 0, hence God exists; reply!
Quote this message in a reply
Member
Posts: 114
Joined: 2005.03
Post: #12
DevIL is nice in theory, but you will have to bundle the DevIL library and all dynamic libraries it depends on with your game. For me, finding out which those were was too much work, I simply switched to OpenGL texture loading and it's working perfectly.
Quote this message in a reply
Jones
Unregistered
 
Post: #13
DevIL comes packaged with all supporting libraries, you can simply pass them on with your program.

However, I'm having trouble finding a guide to linking to non-framework libraries, perhaps one of you could clear this up?

I've looked about, and it would seem there are NO tutorials for setting DevIL to work in an xCode project. I have no experience with .dylib (Which I assume stands for "Dynamic Library".) Nor do I know where the installers placed these files. In my include and lib directories, which for the life of me I can't find. (Yes I know they're hidden, I'm using terminal to search.)

I once saw a command "pragma" to include libraries like headers, in some c source for a directX program. Not sure if it's relevant.

Any help would be greatly appreciated.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Anybody want a cool walker? mikey 0 1,834 Apr 17, 2009 11:48 AM
Last Post: mikey
  Applying fog... retroactively TomorrowPlusX 18 7,014 Dec 14, 2004 07:21 AM
Last Post: TomorrowPlusX