Click to See Complete Forum and Search --> : OpenGl texture from jpg or gif


surfdabbler2
August 22nd, 2005, 07:44 AM
Is there a library available that will load a jpg or gif to an OpenGL texture?

I'm currently using the CGLImage class from gllib. This works well for
Windows bmp files, but to get the resolution I desire, my texture files are ending up over 4Mb in size. A similar jpg ends up around 110Kb, and the GIF file is 70K.

It would be great if a library was available that would allow me to make use of much smaller texture files.

Marc G
August 25th, 2005, 01:46 PM
You can use Freeimage (http://freeimage.sourceforge.net/features.html) for this. One of its features: "Easily integrates into DirectX and OpenGL. Only a minimum of programming is necessary to store a FreeImage bitmap into a DirectDraw surface or to use FreeImage to load your Direct3D/OpenGL textures. "

surfdabbler2
August 25th, 2005, 10:07 PM
Hi, and thanks for the reply.

For the benefit of anyone else reading this post, I've discovered what I think is the easiest way. There are a few libraries around, and FreeImage is certainly powerful in what it offers, but it's way beyond what I need. I just want to load files into a texture. It doesn't require 1Mb DLL to accomplish that. :)

There's a handy function called OleLoadPicturePath (olectl.h) that will load any standard windows image (BMP,JPG,GIF,WMF,ICO), and a small amount of tranformation code will convert that into an OpenGL Texture. For sample code, including the OpenGL texture transformation function, check out http://nehe.gamedev.net and go to tutorial lesson 41.

I haven't implemented it in my code yet, but the demo program works on jpg, and the entire demo application is about 800 lines of code.