View Full Version : How can i load a 2D .jpeg/.jpg image and display it using glut of opengl?
05-01-2012, 08:15 PM
How can i load a 2D .jpeg/.jpg image and display it using glut of opengl?
Can anyone post complete example code?
05-02-2012, 01:44 AM
You are asking two completely different questions wrapped into one post.
Loading a texture can be done either by writing a loader yourself or by using some 3rd party image loading utilities.
Why not simply convert the JPG into a BMP or TGA file and deal with that instead - at least then you can put these loders into your own image class. I rely upon my compiler's runtime libararies to load JPG but BMP,TGA are natively supported in my own code. Honestly, I would not worry about JPG too much as it's a lossy format (when converted to JPG the image quality is not 100% accurate compared to the original) and nobody truely supports JPG as their first choice of original art.
Using glut to create an opengl program would just be a matter of using Google to find some simple tutorials. Glut does not display opengl images/textures, you need to use OpenGI API functions to do that; again tutorial sites such as HeNe can show you how.
05-02-2012, 02:00 AM
Can you post the complete example code?
05-02-2012, 02:26 AM
No. I don't program in glut.
You Google and type in GLUT OPENGL TUTORIAL. Unbelieveable!
The very first 'hit' = what you want. Lighthouse3d.com has good examples
05-02-2012, 02:29 AM
Which do you use to load image? Which library do you use to load images?
05-02-2012, 02:49 AM
My primary format is .TGA files. These support 8 bit (greyscale), 16-bit (grey scale), 24-bit RGB, 32-bit RGBA format and can also be optionally compressed.
Dead easy to load uncompressed TGA files - its a 12 byte header followed by the RAW image data.
I don't use any libraries - I wrote my own TGA,BMP and JPG loader (although JPG is natively supported in Delphi).
05-02-2012, 04:00 AM
How did you write your own loader? Is it available on internet? How do you make .TGA files from png/jpg/bmp?
05-02-2012, 04:25 AM
If you don't want to write your own loader, then use one of the ones listed over at the Wiki
If you want to write your own, then you need to figure out the file format from its specification
This site has specs for A LOT of formats :
05-02-2012, 05:53 AM
How do you make .TGA files from png/jpg/bmp?
Use an art package like PhotoShop or Paintshop Pro
Is it available on internet? Yes. Many tutorial sites like HeNe show you how to load TGA or BMp files.
05-02-2012, 04:34 PM
Is the code you wrote available in internet? Did you write the nehe tutorial to load TGA/BMP? What's special about TGA or BMP? What's wrong with png,jpg?
05-03-2012, 04:32 AM
Is the code you wrote available in internet?No.
Did you write the nehe tutorial to load TGA/BMP?No.
What's special about TGA or BMP?Nothing. But they are easy to load! TGA supports alpha channel (32-bit).
What's wrong with png,jpg? JPG is a lossy format (meaning when it's compressed data is lost. It is not 100% identical to the original image. For computer graphics that's bad!
PNG is better than JPG, but very difficult to load (as in write your own loader class). As I said before, just re save the assets into TGA. Job done.
Powered by vBulletin® Version 4.2.0 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.