Jump to content
  • Advertisement
Sign in to follow this  
Weng

OpenGL Can .jpg files be used for texture mapping?

This topic is 4405 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I have read some openGL texture mapping examples from the NeHe openGL website. The texture mapping examples and other code which needs texture mappings all use bitmap files. (.bmp extension) Can I use .jpg files instead? I have tried renaming the .jpg files into the .bmp extension but the code taken from NeHe OpenGL gives an error.

Share this post


Link to post
Share on other sites
Advertisement
JPEG files are structured totally differently than BMP files. Your image loading code uses that structure to extract the image data from the file. Just changing the file extension does not change the data (the fact that this fools Windows always amuses me)

To use JPEG files, you need code that knows how to load JPEGs. I would suggest using an image loading library like Devil or Corona.

Share this post


Link to post
Share on other sites
That code load .bmp files. Changing the extension of a .jpg file to .bmp does not actually make it .bmp format! Sure you can use .jpg and any other format you want, as long as you write code that loads that format, or use a 3rd party library that does that.

Share this post


Link to post
Share on other sites
Anything can be used for texture mapping, you just need some way of interpretting the data as pixels and sending it to OpenGL. For JPEG images you would probably want to use libjpeg. There are also several image loading libraries that support many different formats. I see DevIL and Corona mentioned often as good libraries. There's also phantom's GTL which properly supports compressed DDS textures, among others.

Share this post


Link to post
Share on other sites
This drives me to ask, is every image file format essentially a bitmap, which differentiates it from the other formats by the compression algorithms it uses and other features? What I mean is, say for example, JPEG, is that, at it's pure form, a bitmap? So I would decompress it and whatever, decode it, however you'd say it, and then feed the raw bitmap image data to whatever I need say for example a texture, is that correct? Is the same applied to audio files? Is wav the equivalent of bmp? That meaning, is say, ogg, at it's pure form, just a wav? However, it's different in it's own compression algorithms and what not?

I hope this doesn't sound too confusing, it's been puzzling me for a while now and I figured I'd ask in the context of this thread.

Share this post


Link to post
Share on other sites
blanky :

i understand your question, but when thinking a little it is quite surprising :)

the fact is that .bmp are a big matrix of pixels.
Those pixels are stored individually with a certain representation (1,4,8,16,24 & 32 bit). Thus indeed every image format can be in its pure form (as you call it) interpreted in that way. Does that make them all bmp ? no. But as far as they are made to be diplayed as a matrix of pixels, they can all be represented as a bmp. But, yes that's one way of seeing it. The analogy with the wav is correct imo. (one detail, true bmp does not come with certain stuff like alpha channel support, and other things, so don't see images as bmp, see them as... well images with certain carracteristics :)

Share this post


Link to post
Share on other sites
Targas are your friend. Learn to love .tga files. They are flexible in that you can vary the bits per pixel 16(for grayscale) 24 (color with no alpha) and 32 ( color with alpha.)

They also offer optional compression but you might want to check with your interpreter implimentation to see if it offers realtime decompression, the trade off between saved space and performance may not be worth it.

.jpg are crap. They are good for webpages because they compress down small for easy transmission.

Share this post


Link to post
Share on other sites
Yes I like TGA over JPG, and PNG over GIF, correct me if I'm wrong in these 'likings' since I'm not much of an artist or a pro at image formats.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!