View Full Version : Loading a tga file directly into openGL

01-04-2008, 04:17 AM
Hello! I would like to know if there is any techniques that allow the loading of a tga file into an openGL scene. For example,I have to make a nature scene with a forest and I have tga files of different trees. Is there a way to put the picture file directly into the scene?

01-04-2008, 04:46 AM
Read about texturing in OpenGL (there should be plenty of tutorials, for example ones from NeHe). You may be also interested in billboarding. As to tga loading, simple google search will give you some code.

01-04-2008, 05:05 AM
Thanks! I didn't know what I was looking for was called billboarding. :)

01-04-2008, 07:11 AM
TGA loading (http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=33)
billboarding (http://www.lighthouse3d.com/opengl/billboarding/)

01-04-2008, 09:27 AM
Thanks for the link! But,I can't understand everything in the Billboarding tutorial. Can anyone make it simpler for me? For example,if I just want the tga file to appear and not the snowman.

01-04-2008, 04:31 PM
Please take a look at this:
imageTga.zip (http://www.songho.ca/opengl/files/imageTga.zip)

It loads a TGA image and render it using glDrawPixels(). You can get better rendering performance by using OpenGL texture object. However, most images are not power of 2 (POT) in resolution, so, glDrawPixels() is much simpler for NPOT images.

You may use OpenGL extension, GL_ARB_texture_non_power_of_two, and GL_ARB_texture_rectangle if the video card supports them.
Here is an example to load NPOT images and render it as texture.
textureNPOT.zip (http://www.songho.ca/opengl/files/textureNPOT.zip)
textureRectangle.zip (http://www.songho.ca/opengl/files/textureRectangle.zip)

01-04-2008, 10:54 PM