   vanishing textures.
  Hi, I just moved my geometry and texture data into a templated linkedlist. But in doing so, I screwed up some thing to do with texturing.The LoadBMP function is used from one of the NeHe texturing loading tutorials, Its only modified to display a messagebox if it returns false.   int DrawGLScene(GLvoid){firsttime=clock();glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);glColor3f(1.0f, 1.0f,1.0f);glBindProgramARB(GL_VERTEX_PROGRAM_ARB,vShad);//glEnable(GL_VERTEX_PROGRAM_ARB);glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB,fShad);//glEnable(GL_FRAGMENT_PROGRAM_ARB);glLoadIdentity();/* DRAW cworld */glPushMatrix();gluLookAt(camera.position.x,camera.position.y,camera.position.z,camera.target.x,camera.target.y,camera.target.z,camera.up.x,camera.up.y,camera.up.z);cworld->draw();glPopMatrix();lasttime=firsttime;firsttime=clock();diff_time=(firsttime-lasttime+diff_time)/2;glFlush();return TRUE;}class OBJECT{public:OBJECT();~OBJECT();void draw();void genLists(void);LINKED_LIST<NODE<POLYGON>, POLYGON >* polygon_list;LINKED_LIST<NODE<POLYGON>, POLYGON >* uvpoly_list;GLuint draw_list;GLuint* texture;};OBJECT::OBJECT(){polygon_list = new LINKED_LIST<NODE<POLYGON>, POLYGON >;uvpoly_list  = new LINKED_LIST<NODE<POLYGON>, POLYGON >;texture = new GLuint;}OBJECT::~OBJECT(){delete polygon_list;delete uvpoly_list;glDeleteTextures(1, texture);delete texture;}void OBJECT::genLists(){draw_list=glGenLists(1);glNewList(draw_list,GL_COMPILE);glBegin(GL_TRIANGLES);/*Loop for each polygon in the list*/NODE<POLYGON>* uv_cur=uvpoly_list->head;for(NODE<POLYGON>* poly_cur= polygon_list->head; poly_cur!=polygon_list->tail; poly_cur=poly_cur->next,uv_cur=uv_cur->next){/*Loop for each vertex*/POINT3f normal, a, b, c;a=poly_cur->data->points[0];b=poly_cur->data->points[2];c=poly_cur->data->points[1];a.x-=c.x;a.y-=c.y;a.z-=c.z;b.x-=c.x;b.y-=c.y;b.z-=c.z;normal.x=a.y*b.z-a.z*b.y;normal.y=a.z*b.x-a.x*b.z;normal.z=a.x*b.y-a.y*b.x;float length=sqrt(normal.x*normal.x+normal.y*normal.y+normal.z*normal.z);normal.x/=(length+0.001);normal.y/=(length+0.001);normal.z/=(length+0.001);/*generate mapping coords*/POINT3f i,j,k;i=uv_cur->data->points[0];j=uv_cur->data->points[1];k=uv_cur->data->points[2];//glActiveTextureARB(GL_TEXTURE0_ARB);glEnable(GL_TEXTURE_2D);glBindTexture(GL_TEXTURE_2D, *texture);//glEnable(GL_TEXTURE_2D);//glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT);//glTexEnvf (GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, GL_REPLACE);glNormal3f(normal.x, normal.y, normal.z);glTexCoord2f(i.x, i.y);//glMultiTexCoord2f(GL_TEXTURE0_ARB, i.x, i.y);glVertex3f((poly_cur->data->points[0].x)/100 , (poly_cur->data->points[0].y)/100 ,(poly_cur->data->points[0].z)/100);glTexCoord2f(j.x, j.y);//glMultiTexCoord2f(GL_TEXTURE0_ARB, j.x, j.y);glVertex3f((poly_cur->data->points[1].x)/100 , (poly_cur->data->points[1].y)/100 ,(poly_cur->data->points[1].z)/100);glTexCoord2f(k.x, k.y);//glMultiTexCoord2f(GL_TEXTURE0_ARB, k.x, k.y);glVertex3f((poly_cur->data->points[2].x)/100 , (poly_cur->data->points[2].y)/100 ,(poly_cur->data->points[2].z)/100);}glEnd();glEndList();}void OBJECT::draw(){glCallList(this->draw_list);}/*Loop for each object in scene*/for(int object_i=0; object_i<*num_objects; object_i++){/*Add an object to object_list*/errlog<<"adding object"<<object_i<<"\n";errlog.flush();NODE<OBJECT>* cur_object = object_list->addNode();errlog<<"added object to world \n";errlog.flush();/*TEXTURE*/char* texture_file = new char[128];file.get(texture_file, sizeof(char)*128, ''\r'');errlog<<"read texture "<< texture_file << "\n";errlog.flush();AUX_RGBImageRec* textureimage = new AUX_RGBImageRec;textureimage = LoadBMP("Data\\Crate.bmp");if (textureimage){glGenTextures(1, cur_object->data->texture);//glActiveTextureARB(GL_TEXTURE0_ARB);glEnable(GL_TEXTURE_2D);glBindTexture(GL_TEXTURE_2D, *(cur_object->data->texture));glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_LINEAR);glTexImage2D(GL_TEXTURE_2D, 0, 3, textureimage->sizeX, textureimage->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, textureimage->data);}if (textureimage){if (textureimage->data){delete textureimage->data;}delete textureimage;}file.read(texture_file, sizeof(char)*1);file.read(texture_file, sizeof(char)*1);delete texture_file;......................}Ive checked previous works and tutorials to see if im calling the gl functions in the right order. I havnt rewritten this from scratch, its been modified from code that already did display textures fine.Thankyou 
  well firstly dont use glaux. NeHe has a Glaux Replacement up.Glaux has 16+ known memory leaks.Glaux was only used for demonstations.SGI who created glaux says never to use it.Glaux was nexer a part of OpenGL, it was more like a mod.    ;  DerAnged: Thankyou. I''m free from glaux now, but that wasn''t the problem.I''ve modified the loading code to this, due to my wanting to explicity state glTexParameteri and glTexImage2D arguments in the loadworld method rather than in yet another file. /*Loop for each object in scene*/for(int object_i=0; object_i<*num_objects; object_i++){/*Add an object to object_list*/errlog<<"adding object"<<object_i<<"\n";errlog.flush();NODE<OBJECT>* cur_object = object_list->addNode();errlog<<"added object to world \n";errlog.flush();/*TEXTURE*/char* texture_file = new char[128];file.get(texture_file, sizeof(char)*128, ''\r'');errlog<<"read texture "<< texture_file << "\n";errlog.flush();//BITMAP* textureimage = new BITMAP;//textureimage = LoadBMP("Data\\Crate.bmp");HBITMAP hBMP;BITMAPBMP;glGenTextures(1, cur_object->data->texture);hBMP=(HBITMAP)LoadImage(GetModuleHandle(NULL), texture_file, IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION | LR_LOADFROMFILE );if (!hBMP)MessageBox(NULL, "Error loading texture","ERROR", MB_OK | MB_ICONINFORMATION);GetObject(hBMP, sizeof(BMP), &BMP);glPixelStorei(GL_UNPACK_ALIGNMENT, 4);//glActiveTextureARB(GL_TEXTURE0_ARB);glEnable(GL_TEXTURE_2D);glBindTexture(GL_TEXTURE_2D, *(cur_object->data->texture));glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_LINEAR);glTexImage2D(GL_TEXTURE_2D, 0, 3, BMP.bmWidth, BMP.bmHeight, 0, GL_BGR_EXT, GL_UNSIGNED_BYTE, BMP.bmBits);DeleteObject(hBMP);file.read(texture_file, sizeof(char)*1);file.read(texture_file, sizeof(char)*1);delete texture_file;;  Do you have a valid OpenGL rendering context before you try and load the textures?Enigma ;quote:Original post by aaron_ds  DerAnged: Thankyou. I''m free from glaux now, but that wasn''t the problem.I''ve modified the loading code to this, due to my wanting to explicity state glTexParameteri and glTexImage2D arguments in the loadworld method rather than in yet another file. /*Loop for each object in scene*/for(int object_i=0; object_i<*num_objects; object_i++){/*Add an object to object_list*/errlog<<"adding object"<<object_i<<"\n";errlog.flush();NODE<OBJECT>* cur_object = object_list->addNode();errlog<<"added object to world \n";errlog.flush();/*TEXTURE*/char* texture_file = new char[128];file.get(texture_file, sizeof(char)*128, ''\r'');errlog<<"read texture "<< texture_file << "\n";errlog.flush();//BITMAP* textureimage = new BITMAP;//textureimage = LoadBMP("Data\\Crate.bmp");HBITMAP hBMP;BITMAPBMP;glGenTextures(1, cur_object->data->texture);hBMP=(HBITMAP)LoadImage(GetModuleHandle(NULL), texture_file, IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION | LR_LOADFROMFILE );if (!hBMP)MessageBox(NULL, "Error loading texture","ERROR", MB_OK | MB_ICONINFORMATION);GetObject(hBMP, sizeof(BMP), &BMP);glPixelStorei(GL_UNPACK_ALIGNMENT, 4);//glActiveTextureARB(GL_TEXTURE0_ARB);glEnable(GL_TEXTURE_2D);glBindTexture(GL_TEXTURE_2D, *(cur_object->data->texture));glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_LINEAR);glTexImage2D(GL_TEXTURE_2D, 0, 3, BMP.bmWidth, BMP.bmHeight, 0, GL_BGR_EXT, GL_UNSIGNED_BYTE, BMP.bmBits);DeleteObject(hBMP);file.read(texture_file, sizeof(char)*1);file.read(texture_file, sizeof(char)*1);delete texture_file; have you tried changing glTexImage2D(GL_TEXTURE_2D, 0, 3, BMP.bmWidth, BMP.bmHeight, 0, GL_BGR_EXT, GL_UNSIGNED_BYTE, BMP.bmBits);   to gluBuild2DMipmaps(GL_TEXTURE_2D, 3, BMP.bmWidth, BMP.bmHeight, GL_BGR_EXT, GL_UNSIGNED_BYTE, BMP.bmBits);   ;  Enigma: yes. The function CreateGLWindow creates the context and calls InitGL() immediatly before CreateGLWindow returns.It is inside InitGL() that I load the textures. ;  if glubuild2dmipmaps doesnt work(see my last post) than make sure that you are using 24bit bitmaps that are a power of two(thats what the glaux replacement needs)(the power of two thing is something almost all loaders need)    ;  DerAnged: Thankyou, that was the problem. I was using  glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_LINEAR);when I wasn't using mipmaps. Doh! Sometimes its the simplest mistakes that I pass over.Thankyou again!EDIT: yes, I am using 24bit 2^x bitmaps  [edited by - aaron_ds on February 8, 2004 5:13:54 PM];quote:Original post by aaron_ds  DerAnged: Thankyou, that was the problem. I was using  glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_LINEAR);when I wasn''t using mipmaps. Doh! Sometimes its the simplest mistakes that I pass over.Thankyou again!EDIT: yes, I am using 24bit 2^x bitmaps  [edited by - aaron_ds on February 8, 2004 5:13:54 PM]glad i could help. good luck on your game/engine.    