What are u all using to load textures for OpenGL?

I have been trying to load a texture for a while now with no luck. All the tutorials I find use glaux , are for .raw files (I prefer .bmp, .png, or .jpg), or the majority just skip over that part and talk about the actual texturing code…

What do you guys use to load textures? I am very curious, openGL has been around forever, I thought texturing would be absolutely trivial to get working, please help :slight_smile:

Try DevIL

I looked at DevIL, but I cannot figure out how to install it on VS2008…

I am trying to get SOIL, simple opengl image loader to work, but I get some linking error, probably because I can’t find the static library file or I am linking it in the wrong spot. The file in SOIL’s lib folder is a .a file, wth is a .a file…

Any help on DevIL or SOIL, or anything that can load a image would be greatly appreciated :slight_smile:


I found SOIL the best, but all of them works correctly.
.a is the lib file for gcc, mingw.
To make soil work, you have to compile and copy the LIB file, and copy the SOIL.h into your compiler.
Go to the SOIL/projects/VC? folder, and open the project to do it.
Then you find everything to load an image at the official website:

I use Codeblocks btw, but it should work with VS2008 too.

The projects that come with SOIL won’t compile for me :frowning:

I am trying to get FreeImage to work, I found an example project on codesampler.com that compiles and works, but I am having trouble getting it to work in my own project.

I am still having trouble. The example of FreeImage and Opengl I got from codesampler.com does not use GLUT, and I am getting a lot of errors. If anyone has a good GLUT + OpenGL texture example that will compile in Visual Studio let me know :slight_smile:

i wrote my own TGA loader (as a lesson for nehe.gamedev.net)
feel free to use it if you like

thanks for the offer, but I really want to load bmps, jpegs, or pngs.

I am finding this process extremely painful. There are so many examples and libraries to get this simple task done, but I cannot get any of them to work with my existing project, and sometimes not at all. How do you all cope with all the differences in IDE, libraries, C++ random crap, and more?

Loading textures is far from simple if you want to support some common file formats. DevIL is actually pretty easy to use with Visual Studio but i haven’t used it in a while. I wrote my own importers for TGAs and DDS files. TGAs are really easy to handle, that was the reason for me to use them. DDS files are the most interesting files, because they can store all the stuff like DXT compressed images, 1D, 2D, 3D, Cubemap textures, with mipmaps or without. It was a pain to write a loader for that format but it was really worth the effort. Textures load like 5x faster than from TGAs now and i have full control over the data.

However it seems that you have to get a bit more used to how to get other peoples software working in your projects. I would pick one library and not hop to the next only because it doesn’t work right away. C++ is difficult in that regard, but that’s a skill that you need to learn.


I am happy to hear that this isn’t a trivial process. I am all for any library that has some good documentation on how to use it. Can anybody point me in a good direction? I am dying to mess around with cube maps, multi-texturing, and “glyph-bombs” as GLSL book puts it (the orange one).

I am going to try and stick to using SOIL, simple OpenGL Image Library.

It appears to do everything I need without extra stuff complicating the process. I have the SOIL.h file setup correctly, I renamed the libSOIL.a to libSOIL.lib, went to project->properties->linker->input and added it in with the other .lib files. I then added in:

/* load an image file directly as a new OpenGL texture */
GLuint tex_2d = SOIL_load_OGL_texture

I get some error C2099: initializer is not a constant c:\Users\Danny\Desktop\ogl_texture2\ogl2brick.c 95, which I don’t understand. Line 95 is the “);” from the code above. Does this mean I didn’t install SOIL properly? I have the img_test.png in the right folder…

You can’t use an .a file by renaming it to .lib. .a files are usually compiled for Linux and even if they are compiled for Windows, they are created by GCC which is incompatible with Visual Studio.

You need to find a .lib file to link to. Either SOIL provides that somewhere on their website or you need to get the sources and compile it yourself. It is usually not necessary to “install” a library, just put files in the proper directory.

For example for DevIL, you download it, there are a few .h files, a .lib file and possibly .exp and .dll files. You put the headers somewhere in your include-path. The others you put into your library-path, where the linker will find it. Then you compile your stuff, and tell the linker that it should link to “devil.lib” or whatever it is called. That should do the trick. If you run your app, it might be necessary to copy the dll to your apps directory.

About your error: Is tex_2d by chance a global variable? You can’t initialize global vars with a function-call. You need to call that function at run-time.


I have that error above in a function call now, but I get the same error again.

Anyways, I cannot find a windows static library file in SOIL’s download. There is the .a file which I renamed, but that might not be good. I cannot compile my own, their VS9 project doesn’t run correctly. Can anybody try to get SOIL to run on a windows machine with visual studio?

I let Windows decode JPG/stuff for me (via OleLoadPicture), and the several lines of code necessary to load .DDS (compressed or not).

I am not trying to bite your head off, but that doesn’t really help me, I googled OleLoadPicture and didn’t get anything substantial.

Compile SOIL, and it will work :slight_smile: It took 5 minutes for me to compile, and I am a beginner too.

Glad to hear it isn’t rocket science, Can you send me the compiled SOIL file, did you make one for VS 2008? Did you actually use it at all or did you just compile it?

My email is: meatwadShake357@gmail.com

I used Codeblocks, so I can’t send it. But it’s easy to compile. Go to: <folder of SOIL>/projects/VC9
Then hit the compile button. Copy the soil.lib to the right place. Easy :slight_smile:

Can you try running something with this code and the SOIL library?

GLuint GetTexture(std::string Filename)
GLuint tex_ID;

tex_ID = SOIL_load_OGL_texture(

	if( tex_ID &gt; 0 )
		glEnable( GL_TEXTURE_2D );
		glBindTexture( GL_TEXTURE_2D, tex_ID );
		return tex_ID;
		return 0;


When I copy and paste it in, I get some syntax error: missing ‘)’ before ‘:’ which I cannot figure out…

#include <windows.h>
#include "ILX.h"
#include <olectl.h>
#include <gl\gl.h>
#include <gl\glext.h>

//====================[[ JPG ]]================================================================[[
static ILTEX _ILXLoadTextureJPG(U8* data,int DataSize){

	//----[ copy data ]-------------------------------------[
	// yeah, I know it's bloated. 
	// But jpegs sent here would be small anyway
	HGLOBAL hGlobal = GlobalAlloc(GMEM_MOVEABLE,DataSize);


	IPicture* PictuBaka;
	if(OleLoadPicture( pstm, DataSize,0,IID_IPicture,(LPVOID*)&PictuBaka)){
		//trace("Cannot load image %s",fName);
		return 0;
		return 0;


	int wid = bi.bmWidth;
	int hei = bi.bmHeight;

	char* pixels = (char*)xmalloc(wid*hei*4);



	HDC dc = CreateCompatibleDC(GetDC(0));


	for(int j=wid*hei*4;j-=4;)pixels[j+3]= -1; // set alpha=1.0f;

	ILTEX tex = ilCreateTexture2D(wid,hei,ILTEXFMT_BGRA8);
	return tex;

//====================[[ DDS ]]================================================================[[
static ILTEX _ILXLoadTextureDDS(U8* data,int DataSize){
	int* ddsd = (int*)(data+4);

	int wid,hei,numMipMaps,nBlockSize,fourcc;
	const U8* pixels;
	IL_TEX_FORMAT format;

	wid = ddsd[3];
	hei = ddsd[2];
	numMipMaps = ddsd[6];
	fourcc = ddsd[20];
	pixels = data + (4 + 124);

		case '1TXD':
			// DXT1's compression ratio is 8:1
			format = ILTEXFMT_DXT1;
			nBlockSize = 8;
		case '3TXD':
			// DXT3's compression ratio is 4:1
			format = ILTEXFMT_DXT3;
			nBlockSize = 16;
		case '5TXD':
			// DXT5's compression ratio is 4:1
			format = ILTEXFMT_DXT5;
			nBlockSize = 16;
			return null;

	ILTEX tex = ilCreateTexture2D(wid,hei,format,numMipMaps!=1);
	if(!tex)return null;

	int nWid=wid,nHei=hei;

	for(int i=0;i<numMipMaps;i++){
		int nSize = ((nWid+3)/4) * ((nHei+3)/4) * nBlockSize;
		pixels += nSize;

	return tex;	

ILTEX ILXLoadTexture(const char* FNameOrData,int DataSize){
	bool WasFile=false;
	U8* data = (U8*)FNameOrData;
	U8* dataalloc=null;
		data = (U8*)uffetch(FNameOrData,&DataSize);
		if(!data)return null;
		dataalloc = data;
	ILTEX res = null;
	if(data[0]=='D' && data[1]=='D' && data[2]=='S'){
		res = _ILXLoadTextureDDS(data,DataSize);
		res = _ILXLoadTextureJPG(data,DataSize);
	return res;