Texture loader?

Started by
12 comments, last by lc_overlord 15 years, 7 months ago
I was wondering what is the most simple texture loader to implement/use? On a side note I was wondering how come OpenGL doesn't come with a standard texture loader?
Advertisement
I like DevIL.

Khronos maintains OpenGL and a few other open spec solutions.
GL itself is an API for dealing with the GPU. It doesn't bother with file formats.
Also, there are so many file loaders that it's not worth making another one by Khronos.
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);
Besides glTexImage2D and glTexSubImage2D are designed to be fun for programmers to figure out, with their random non-sensical error messages and twisted reasons for failing... Who said Khronos don't have a sense of humour!
Feel free to 'rate me down', especially when I prove you wrong, because it will make you feel better for a second....
Well by simple I mean simple to install/use. Devil doesn't have enough documentations for me to get started with it.

edit: Well Opengl is a graphic library so I was just wondering why a graphics library doesn't at least come with a standard loader...
Quote:Original post by Shadowwoelf
edit: Well Opengl is a graphic library so I was just wondering why a graphics library doesn't at least come with a standard loader...


They could have added it to GLU but like I said, there are so many other libraries that the cost of paying people to create it and maintain is a big waste.
If it was available, most companies would not even use it.

Think of GL as a stand alone library for only talking to your GPU.
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);
The best texture loader that I've seen so far is NeHe's IPicture code (Win32 dependent).

Basically he has a single function that will load a wide variety of formats and even images from the web. It supports transparency as well. It's definitely worth taking a look at; I used it all the time over other gfx libs due to how simple it is. Assuming you are developing for the Win32 platform only, it might be your best bet for now.
What are you using? SDL, Win32? OSX? A bit more info is really needed.

If you use SDL, SDL will load many image formats and you can just dump that data into GL. If you are learning OpenGL then get the "Beginning OpenGL game Programming book" they cover .bmp and .tga files and really are simple to load once you work through the code.
use DevIL.

NBA2K, Madden, Maneater, Killing Floor, Sims http://www.pawlowskipinball.com/pinballeternal

Use SOIL

DevIL is officially driving me crazy. I cannot figure out how to get it to run.

I followed the websites instructions to install and I "think" I did everything right. (Only thing that I couldn't do was add the debug.lib since it wasn't in the zip file)

Then I used this to try and somehow make a patch work of whats going on. Wiki example

And I get 11 linking errors.

Linking...GameState.obj : error LNK2019: unresolved external symbol __imp__ilDeleteImages@8 referenced in function "public: __thiscall WORLD_STATE::WORLD_STATE(void)" (??0WORLD_STATE@@QAE@XZ)GameState.obj : error LNK2019: unresolved external symbol __imp__ilGetInteger@4 referenced in function "public: __thiscall WORLD_STATE::WORLD_STATE(void)" (??0WORLD_STATE@@QAE@XZ)GameState.obj : error LNK2019: unresolved external symbol __imp__ilGetData@0 referenced in function "public: __thiscall WORLD_STATE::WORLD_STATE(void)" (??0WORLD_STATE@@QAE@XZ)GameState.obj : error LNK2019: unresolved external symbol __imp__ilConvertImage@8 referenced in function "public: __thiscall WORLD_STATE::WORLD_STATE(void)" (??0WORLD_STATE@@QAE@XZ)GameState.obj : error LNK2019: unresolved external symbol __imp__ilLoadImage@4 referenced in function "public: __thiscall WORLD_STATE::WORLD_STATE(void)" (??0WORLD_STATE@@QAE@XZ)GameState.obj : error LNK2019: unresolved external symbol __imp__ilBindImage@4 referenced in function "public: __thiscall WORLD_STATE::WORLD_STATE(void)" (??0WORLD_STATE@@QAE@XZ)GameState.obj : error LNK2019: unresolved external symbol __imp__ilGenImages@8 referenced in function "public: __thiscall WORLD_STATE::WORLD_STATE(void)" (??0WORLD_STATE@@QAE@XZ)GameState.obj : error LNK2019: unresolved external symbol __imp__ilInit@0 referenced in function "public: __thiscall WORLD_STATE::WORLD_STATE(void)" (??0WORLD_STATE@@QAE@XZ)GameState.obj : error LNK2019: unresolved external symbol __imp___CrtDbgReportW referenced in function "public: __thiscall std::_Vector_const_iterator<class baseGameState *,class std::allocator<class baseGameState *> >::_Vector_const_iterator<class baseGameState *,class std::allocator<class baseGameState *> >(class baseGameState * *,class std::_Container_base_secure const *)" (??0?$_Vector_const_iterator@PAVbaseGameState@@V?$allocator@PAVbaseGameState@@@std@@@std@@QAE@PAPAVbaseGameState@@PBV_Container_base_secure@1@@Z)Lesson33.obj : error LNK2001: unresolved external symbol __imp___CrtDbgReportW.\Debug/Lesson33.exe : fatal error LNK1120: 9 unresolved externalsBuild log was saved at "file://d:\Projects\Lesson33\Debug\BuildLog.htm"Lesson33 - 11 error(s), 0 warning(s)========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========



Headers
#include <windows.h>											// Header File For Windows#include <stdio.h>												// Header File For Standard Input/Output#include <IL/il.h>#include <gl\gl.h>											// Header File For The OpenGL32 Library	#include <gl\glu.h>												// Header File For The GLu32 Library#include "texture.h"											// Header File Containing Our Texture Structure ( NEW )#include "GameState.h"#include "globalvariables.h"#include <vector>#include <string>


Actually using the library

WORLD_STATE::WORLD_STATE(){	ilInit();	ilGenImages(1, &texid);	ilBindImage(texid);	success = ilLoadImage("town01_a.tga");	if (success)		{		success = ilConvertImage(IL_RGB, IL_UNSIGNED_BYTE);    if (!success)    {      /* Error occured */      done=true;    }    glGenTextures(1, &#8465;);    glBindTexture(GL_TEXTURE_2D, image);    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);    glTexImage2D(GL_TEXTURE_2D, 0, ilGetInteger(IL_IMAGE_BPP), ilGetInteger(IL_IMAGE_WIDTH),      ilGetInteger(IL_IMAGE_HEIGHT), 0, ilGetInteger(IL_IMAGE_FORMAT), GL_UNSIGNED_BYTE,      ilGetData());	ilDeleteImages(1, &texid);}		}


These three variables are declared private

ILuint texid;
ILboolean success;
GLuint image;

On a side note Wiki example does not actually bind any texture to the quad being drawn which is odd.

So what am I doing wrong?

This topic is closed to new replies.

Advertisement