Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: How can i load a 2D .jpeg/.jpg image and display it using glut of opengl?

  1. #1
    Junior Member Newbie
    Join Date
    Jan 2010
    Posts
    20

    Question How can i load a 2D .jpeg/.jpg image and display it using glut of opengl?

    How can i load a 2D .jpeg/.jpg image and display it using glut of opengl?
    Can anyone post complete example code?

  2. #2
    Senior Member OpenGL Pro BionicBytes's Avatar
    Join Date
    Mar 2009
    Location
    UK, London
    Posts
    1,169
    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.

  3. #3
    Junior Member Newbie
    Join Date
    Jan 2010
    Posts
    20
    Can you post the complete example code?

  4. #4
    Senior Member OpenGL Pro BionicBytes's Avatar
    Join Date
    Mar 2009
    Location
    UK, London
    Posts
    1,169
    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
    http://www.lighthouse3d.com/opengl/glut/

  5. #5
    Junior Member Newbie
    Join Date
    Jan 2010
    Posts
    20
    Which do you use to load image? Which library do you use to load images?

  6. #6
    Senior Member OpenGL Pro BionicBytes's Avatar
    Join Date
    Mar 2009
    Location
    UK, London
    Posts
    1,169
    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).

  7. #7
    Junior Member Newbie
    Join Date
    Jan 2010
    Posts
    20
    How did you write your own loader? Is it available on internet? How do you make .TGA files from png/jpg/bmp?

  8. #8
    Super Moderator OpenGL Guru
    Join Date
    Feb 2000
    Location
    Montreal, Canada
    Posts
    4,264
    If you don't want to write your own loader, then use one of the ones listed over at the Wiki
    http://www.opengl.org/wiki/Related_toolkits_and_APIs

    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 :
    http://www.wotsit.org
    ------------------------------
    Sig: http://glhlib.sourceforge.net
    an open source GLU replacement library. Much more modern than GLU.
    float matrix[16], inverse_matrix[16];
    glhLoadIdentityf2(matrix);
    glhTranslatef2(matrix, 0.0, 0.0, 5.0);
    glhRotateAboutXf2(matrix, angleInRadians);
    glhScalef2(matrix, 1.0, 1.0, -1.0);
    glhQuickInvertMatrixf2(matrix, inverse_matrix);
    glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
    glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);

  9. #9
    Senior Member OpenGL Pro BionicBytes's Avatar
    Join Date
    Mar 2009
    Location
    UK, London
    Posts
    1,169
    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.

  10. #10
    Junior Member Newbie
    Join Date
    Jan 2010
    Posts
    20
    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?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •