   OpenIL loading texture into an OpenGL texture
  ok so even though its seems to be almost dead and is not very well documented, im using OpenIL or DevIL to load my images for texturing in OpenGL. there is a function , ilutGLLoadImage(), that claims to take a file-path as an ILstring and return a GLunit texture. However if it's working, witch i assume it is, then im doing something wrong. my program just crashes from the get go, i tried to modify the NeHe tutorial on texturing (as it uses glaux witch is dead and i want .png and other 32-bit depth file types). but i seem to have failed, im getting very frustrated with trying to find a way to texture in OpenGL, im hopeing this will work. here is my code so far:#include <windows.h>#include <GL/gl.h>#include <GL/glu.h>#include <GL/glut.h>#include <stdlib.h>#include<IL/il.h>#include<IL/ilu.h>#include<IL/ilut.h>GLuint* handle;static void resize(int width, int height){ilInit();    ilEnable(IL_ORIGIN_SET);    glEnable(GL_TEXTURE_2D);    ilutRenderer(ILUT_OPENGL);    *handle = ilutGLLoadImage("test.png");glShadeModel(GL_SMOOTH);// Enable Smooth ShadingglClearColor(0.0f, 0.0f, 0.0f, 0.5f);// Black BackgroundglClearDepth(1.0f);// Depth Buffer SetupglEnable(GL_DEPTH_TEST);// Enables Depth TestingglDepthFunc(GL_LEQUAL);// The Type Of Depth Testing To DoglHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);}static void display(void){    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);// Clear Screen And Depth BufferglLoadIdentity();// Reset The Current MatrixglTranslatef(0.0f,0.0f,-5.0f);glBindTexture(GL_TEXTURE_2D, *handle);glBegin(GL_QUADS);// Front FaceglTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  1.0f);// Bottom Left Of The Texture and QuadglTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  1.0f);// Bottom Right Of The Texture and QuadglTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f,  1.0f);// Top Right Of The Texture and QuadglTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f,  1.0f);// Top Left Of The Texture and Quad// Back FaceglTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f);// Bottom Right Of The Texture and QuadglTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f,  1.0f, -1.0f);// Top Right Of The Texture and QuadglTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f,  1.0f, -1.0f);// Top Left Of The Texture and QuadglTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f);// Bottom Left Of The Texture and Quad// Top FaceglTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f, -1.0f);// Top Left Of The Texture and QuadglTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f,  1.0f,  1.0f);// Bottom Left Of The Texture and QuadglTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f,  1.0f,  1.0f);// Bottom Right Of The Texture and QuadglTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f, -1.0f);// Top Right Of The Texture and Quad// Bottom FaceglTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, -1.0f, -1.0f);// Top Right Of The Texture and QuadglTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, -1.0f, -1.0f);// Top Left Of The Texture and QuadglTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  1.0f);// Bottom Left Of The Texture and QuadglTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  1.0f);// Bottom Right Of The Texture and Quad// Right faceglTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f);// Bottom Right Of The Texture and QuadglTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f, -1.0f);// Top Right Of The Texture and QuadglTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f,  1.0f,  1.0f);// Top Left Of The Texture and QuadglTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  1.0f);// Bottom Left Of The Texture and Quad// Left FaceglTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f);// Bottom Left Of The Texture and QuadglTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  1.0f);// Bottom Right Of The Texture and QuadglTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f,  1.0f,  1.0f);// Top Right Of The Texture and QuadglTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f, -1.0f);// Top Left Of The Texture and QuadglEnd();}static void key(unsigned char key, int x, int y){    switch (key)    {   case 27 :   case 'q':  exit(0);  break;   case '+':  break;   case '-':  break;    }    glutPostRedisplay();}static void idle(void){    glutPostRedisplay();}const GLfloat light_ambient[]  = { 0.0f, 0.0f, 0.0f, 1.0f };const GLfloat light_diffuse[]  = { 1.0f, 1.0f, 1.0f, 1.0f };const GLfloat light_specular[] = { 1.0f, 1.0f, 1.0f, 1.0f };const GLfloat light_position[] = { 2.0f, 5.0f, 5.0f, 0.0f };const GLfloat mat_ambient[]    = { 0.7f, 0.7f, 0.7f, 1.0f };const GLfloat mat_diffuse[]    = { 0.8f, 0.8f, 0.8f, 1.0f };const GLfloat mat_specular[]   = { 1.0f, 1.0f, 1.0f, 1.0f };const GLfloat high_shininess[] = { 100.0f };/* Program entry point */int main(int argc, char *argv[]){    glutInit(&argc, argv);    glutInitWindowSize(640,480);    glutInitWindowPosition(10,10);    glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);    glutCreateWindow("GLUT Shapes");    glutReshapeFunc(resize);    glutDisplayFunc(display);    glutKeyboardFunc(key);    glutIdleFunc(idle);    glClearColor(1,1,1,1);    glEnable(GL_CULL_FACE);    glCullFace(GL_BACK);    glEnable(GL_DEPTH_TEST);    glDepthFunc(GL_LESS);    glEnable(GL_LIGHT0);    glEnable(GL_NORMALIZE);    glEnable(GL_COLOR_MATERIAL);    glEnable(GL_LIGHTING);    glLightfv(GL_LIGHT0, GL_AMBIENT,  light_ambient);    glLightfv(GL_LIGHT0, GL_DIFFUSE,  light_diffuse);    glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);    glLightfv(GL_LIGHT0, GL_POSITION, light_position);    glMaterialfv(GL_FRONT, GL_AMBIENT,   mat_ambient);    glMaterialfv(GL_FRONT, GL_DIFFUSE,   mat_diffuse);    glMaterialfv(GL_FRONT, GL_SPECULAR,  mat_specular);    glMaterialfv(GL_FRONT, GL_SHININESS, high_shininess);    glutMainLoop();    return EXIT_SUCCESS;}
  I don't see where you are initializing handle, since it's a uninitialized pointer, dereferencing has a very high probability of crashing.   ;  ok so sorry in the time that past i changed it from a pointer to an array as that was what was done in NeHe tutoiral, and my program was crashing because i forgot to call glutSwapBuffers()(well i think) in my display function. so now it just shows the clear color and even though i called glColor3fv(blue) (i defined blue) the box still wont show up, and when i comment out the ilut* and il* functions it still dosn't display anything but the clear color. here is my new code:#include <windows.h>#include <iostream>#include <fstream>#include <cmath>#include <cstdlib>#include <GL/gl.h>#include <GL/glu.h>#include <GL/glut.h>#include<IL/il.h>#include<IL/ilu.h>#include<IL/ilut.h>#include <al.h>#include <alc.h>#include <alut.h>//lua stuffextern "C" {#include "lua.h"#include "lualib.h"#include "lauxlib.h"}ILint h,w,textrue;GLuint handle[1];static void resize(int width, int height){    memset(handle,0,sizeof(void *)*1);ilInit();iluInit() ;    ilutInit() ;    glEnable(GL_TEXTURE_2D);    ilutRenderer(ILUT_OPENGL);    glGenTextures(1, &handle[0]);    handle[0] = ilutGLLoadImage("C:\test.bmp");    //glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);// Linear Filtering    //glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);// Linear FilteringglShadeModel(GL_SMOOTH);// Enable Smooth ShadingglClearColor(1.0f, 1.0f, 1.0f, 0.0f);// Black Background//glClearDepth(1.0f);// Depth Buffer SetupglEnable(GL_DEPTH_TEST);// Enables Depth TestingglDepthFunc(GL_LEQUAL);// The Type Of Depth Testing To DoglHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);glLoadIdentity();}static void display(void){    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);// Clear Screen And Depth BufferglLoadIdentity();// Reset The Current MatrixglTranslatef(0.0f,0.0f,-5.0f);    glBindTexture(GL_TEXTURE_2D, handle[0]);GLfloat blue[] = {0.0f,1.0f,0.0f};glColor3fv(blue);glBegin(GL_QUADS);// Front FaceglTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  1.0f);// Bottom Left Of The Texture and QuadglTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  1.0f);// Bottom Right Of The Texture and QuadglTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f,  1.0f);// Top Right Of The Texture and QuadglTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f,  1.0f);// Top Left Of The Texture and Quad// Back FaceglTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f);// Bottom Right Of The Texture and QuadglTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f,  1.0f, -1.0f);// Top Right Of The Texture and QuadglTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f,  1.0f, -1.0f);// Top Left Of The Texture and QuadglTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f);// Bottom Left Of The Texture and Quad// Top FaceglTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f, -1.0f);// Top Left Of The Texture and QuadglTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f,  1.0f,  1.0f);// Bottom Left Of The Texture and QuadglTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f,  1.0f,  1.0f);// Bottom Right Of The Texture and QuadglTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f, -1.0f);// Top Right Of The Texture and Quad// Bottom FaceglTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, -1.0f, -1.0f);// Top Right Of The Texture and QuadglTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, -1.0f, -1.0f);// Top Left Of The Texture and QuadglTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  1.0f);// Bottom Left Of The Texture and QuadglTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  1.0f);// Bottom Right Of The Texture and Quad// Right faceglTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f);// Bottom Right Of The Texture and QuadglTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f, -1.0f);// Top Right Of The Texture and QuadglTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f,  1.0f,  1.0f);// Top Left Of The Texture and QuadglTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  1.0f);// Bottom Left Of The Texture and Quad// Left FaceglTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f);// Bottom Left Of The Texture and QuadglTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  1.0f);// Bottom Right Of The Texture and QuadglTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f,  1.0f,  1.0f);// Top Right Of The Texture and QuadglTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f, -1.0f);// Top Left Of The Texture and QuadglEnd();glutSwapBuffers();}static void key(unsigned char key, int x, int y){    switch (key)    {   case 27 :   case 'q':  exit(0);  break;   case '+':  break;   case '-':  break;    }    glutPostRedisplay();}static void idle(void){    glutPostRedisplay();}const GLfloat light_ambient[]  = { 0.0f, 0.0f, 0.0f, 1.0f };const GLfloat light_diffuse[]  = { 1.0f, 1.0f, 1.0f, 1.0f };const GLfloat light_specular[] = { 1.0f, 1.0f, 1.0f, 1.0f };const GLfloat light_position[] = { 2.0f, 5.0f, 5.0f, 0.0f };const GLfloat mat_ambient[]    = { 0.7f, 0.7f, 0.7f, 1.0f };const GLfloat mat_diffuse[]    = { 0.8f, 0.8f, 0.8f, 1.0f };const GLfloat mat_specular[]   = { 1.0f, 1.0f, 1.0f, 1.0f };const GLfloat high_shininess[] = { 100.0f };/* Program entry point */int main(int argc, char *argv[]){    glutInit(&argc, argv);    glutInitWindowSize(640,480);    glutInitWindowPosition(10,10);    glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);    glutCreateWindow("GLUT Shapes");    glutReshapeFunc(resize);    glutDisplayFunc(display);    glutKeyboardFunc(key);    glutIdleFunc(idle);    glClearColor(1,1,1,1);    glEnable(GL_CULL_FACE);    glCullFace(GL_BACK);    glEnable(GL_DEPTH_TEST);    glDepthFunc(GL_LESS);    glEnable(GL_LIGHT0);    glEnable(GL_NORMALIZE);    glEnable(GL_COLOR_MATERIAL);    glEnable(GL_LIGHTING);    glLightfv(GL_LIGHT0, GL_AMBIENT,  light_ambient);    glLightfv(GL_LIGHT0, GL_DIFFUSE,  light_diffuse);    glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);    glLightfv(GL_LIGHT0, GL_POSITION, light_position);    glMaterialfv(GL_FRONT, GL_AMBIENT,   mat_ambient);    glMaterialfv(GL_FRONT, GL_DIFFUSE,   mat_diffuse);    glMaterialfv(GL_FRONT, GL_SPECULAR,  mat_specular);    glMaterialfv(GL_FRONT, GL_SHININESS, high_shininess);    glutMainLoop();    return EXIT_SUCCESS;} [Edited by - ishkabible on May 22, 2010 12:15:26 PM];  i cant seem to figure this out, i have gone back and fourth on the IL functoin order, gone back and fourth on what i did and didn't call, and gone back and fourth between pointers, arrays, and pointer arrays. could someone point me in the direction of a tutorial on OpenIL that is up to date, or just show me what im doing wrong.;  ok so now i converted from just using ilutGLloadimage() to going though the whole IL* image name thing and i added error messages so i can get a better grasp of whats going on. i turns out it's not loading the file at all#include <windows.h>#include <iostream>#include <fstream>#include <cmath>#include <cstdlib>#include <GL/gl.h>#include <GL/glu.h>#include <GL/glut.h>#include<IL/il.h>#include<IL/ilu.h>#include<IL/ilut.h>#include <al.h>#include <alc.h>#include <alut.h>//lua stuffextern "C" {#include "lua.h"#include "lualib.h"#include "lauxlib.h"}GLuint image;ILuint texid;ILboolean success;static void resize(int width, int height){    glViewport(0, 0, 640, 480);    glEnable(GL_TEXTURE_2D);    glMatrixMode(GL_PROJECTION);    glLoadIdentity();    glOrtho(0.0, 640.0, 480.0, 0.0, 0.0, 100.0);    glMatrixMode(GL_MODELVIEW);    glClearColor(0.0f, 0.0f, 0.0f, 0.0f);    glClearDepth(0.0f);    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);    if (ilGetInteger(IL_VERSION_NUM) < IL_VERSION)    { fprintf(stderr, "wrong version");    }ilInit(); /* Initialization of DevIL */    ilGenImages(1, &texid); /* Generation of one image name */    ilBindImage(texid); /* Binding of image name */    success = ilLoadImage("test.bmp"); /* Loading of image "image.jpg" */    if (success) /* If no error occured: */    {    success = ilConvertImage(IL_RGBA, IL_UNSIGNED_BYTE); /* Convert every colour component into*/    if(!success) { fprintf(stderr,"could not convert image");    }    glGenTextures(1, &image); /* Texture name generation */    glBindTexture(GL_TEXTURE_2D, image); /* Binding of texture name */    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); /* We will use linear interpolation for magnification filter */    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); /* We will use linear interpolation for minifying filter */    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()); /* Texture specification */    ilDeleteImages(1, &texid);    } else {fprintf(stderr, "could not load image");    }}static void display(void){    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);// Clear Screen And Depth BufferglLoadIdentity();// Reset The Current MatrixglTranslatef(0.0f,0.0f,-5.0f);    glBindTexture(GL_TEXTURE_2D, image);GLfloat blue[] = {0.0f,1.0f,0.0f};glColor3fv(blue);    glBegin(GL_QUADS);    glTexCoord2i(0, 0); glVertex2i(0,   0);    glTexCoord2i(0, 1); glVertex2i(0,   480);    glTexCoord2i(1, 1); glVertex2i(640, 480);    glTexCoord2i(1, 0); glVertex2i(640, 0);    glEnd();glutSwapBuffers();}static void key(unsigned char key, int x, int y){    switch (key)    {   case 27 :   case 'q':  exit(0);  break;   case '+':  break;   case '-':  break;    }    glutPostRedisplay();}static void idle(void){    glutPostRedisplay();}const GLfloat light_ambient[]  = { 0.0f, 0.0f, 0.0f, 1.0f };const GLfloat light_diffuse[]  = { 1.0f, 1.0f, 1.0f, 1.0f };const GLfloat light_specular[] = { 1.0f, 1.0f, 1.0f, 1.0f };const GLfloat light_position[] = { 2.0f, 5.0f, 5.0f, 0.0f };const GLfloat mat_ambient[]    = { 0.7f, 0.7f, 0.7f, 1.0f };const GLfloat mat_diffuse[]    = { 0.8f, 0.8f, 0.8f, 1.0f };const GLfloat mat_specular[]   = { 1.0f, 1.0f, 1.0f, 1.0f };const GLfloat high_shininess[] = { 100.0f };/* Program entry point */int main(int argc, char *argv[]){    glutInit(&argc, argv);    glutInitWindowSize(640,480);    glutInitWindowPosition(10,10);    glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);    glutCreateWindow("GLUT Shapes");    glutReshapeFunc(resize);    glutDisplayFunc(display);    glutKeyboardFunc(key);    glutIdleFunc(idle);    glClearColor(1,1,1,1);    glEnable(GL_CULL_FACE);    glCullFace(GL_BACK);    glEnable(GL_DEPTH_TEST);    glDepthFunc(GL_LESS);    glEnable(GL_LIGHT0);    glEnable(GL_NORMALIZE);    glEnable(GL_COLOR_MATERIAL);    glEnable(GL_LIGHTING);    glLightfv(GL_LIGHT0, GL_AMBIENT,  light_ambient);    glLightfv(GL_LIGHT0, GL_DIFFUSE,  light_diffuse);    glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);    glLightfv(GL_LIGHT0, GL_POSITION, light_position);    glMaterialfv(GL_FRONT, GL_AMBIENT,   mat_ambient);    glMaterialfv(GL_FRONT, GL_DIFFUSE,   mat_diffuse);    glMaterialfv(GL_FRONT, GL_SPECULAR,  mat_specular);    glMaterialfv(GL_FRONT, GL_SHININESS, high_shininess);    glutMainLoop();    return EXIT_SUCCESS;}