Read image with DevIL

698 views Asked by At

I have problems with reading an image with DevIL 1.7.8. So far I know the following snippet should work:

ilInit();
ILuint ImageName;
ilGenImages(1, &ImageName);
ilBindImage(ImageName);
wchar_t* imgFilename = L"..\\..\\resources\\textures\\red.png"; 
ilLoadImage(imgFilename);
ILubyte* texture = ilGetData();

When I check the first pixels

for (int i=0; i<64; i++) cout << (int)texture[i] << endl;

I get a pretty random output. The picture is actually completely red.

As well I tried using ilut

ilutRenderer(ILUT_OPENGL);
GLuint t = ilutGLLoadImage(L"..\\..\\resources\\textures\\red.png");

But actually I can't even include the corresponding header file because within that header file il.h is linked which is supposed to be in a folder (\IL) that does not exist. Even when I create this folder and copy the needed header files into it I get compile errors.

Can anybody help me with DevIL?

1

There are 1 answers

0
Godzilla On

I am reading image and binding textures like this:

ilEnable(IL_ORIGIN_SET);
ilOriginFunc(IL_ORIGIN_LOWER_LEFT); // set [0,0] of texture to bottom left corner

ilImage image;
GLuint ind;
glGenTextures(1, &ind);
glBindTexture(GL_TEXTURE_2D, ind);
image.Load(L"<path>");//  or just name.format  be sure to have image in correct folder.

When rendering, you need to bind the correct texture first:

glBindTexture(GL_TEXTURE_2D, ind);

And then assign UV coordites of texture to vertexes:

glTexCoord2f(x1, y1);               
glVertex3f(x, y, z);

Do not forget to enable GL_TEXTURE_2D or whatever type you are using.