   array of textures is filled with last loaded image
  I`m currently coding some OpenGL in Delphi using sources modified from NeHe. Everything sofar is okay, but now I wanted to implement TEXTURES. The tutorial on nehe.gamedev.net is only for 1 (one) tex - I hacked the code open for a variable (that is a defined constant) amount of textures. The code seems to be okay, since it does load any amount of images and runs through allocation routines fine.Sadly when I bind the texture while drawing only the last file loaded is ever displayed.I discussed this on IRC with PfhorSlayer and everything he told me about the way to do it in C seems to fit my code. Only!...I`m not sure about the way I allocate the memory!Since C has more direct control over variables and their memory-allocation/-adress they simply call glGenTextures(quantity,&array[0]) but in Delphi I (think) I have to say: glGenTextures quantity,array[0]);and hope to achieve the same.Since I do not - maybe that''s where it goes wrong!?  
  after generating texture ID''s with glGenTextures, u must use glBindTexture(ID NUMBER) before loading and initializing each texture on a texture-by-texture basis.After initial texture loading, u must again call glBindTexture(ID NUMBER) to access the required texture. if u fail to do this last step, the most recent texture call is used, which is the LAST image u loaded.Hope this helps.  ;  No, unfortunately it doesn`t...As I stated "[...]when I bind the textures while drawing only the last file loaded is ever displayed".If I call Texture-1 it looks the same as Texture-2 and so on ...If I change the last file, they all look like that one.The array I construct while loading contains sequential numbers (i.e. [1,2,3,4,5]) and the pointers used for the bitmaps point to different memory-locations.Everything is looking good - until you run the prog :-/  ;  here's a function in c++ that i've implemented to load textures : void LoadTextures(GLuint textureArray[], LPSTR strFileName, int textureID){AUX_RGBImageRec *pBitmap = NULL;if(!strFileName)return;pBitmap = auxDIBImageLoad(strFileName);if(pBitmap == NULL)exit(0);glGenTextures(1, &textureArray[textureID]);glBindTexture(GL_TEXTURE_2D, textureArray[textureID]);gluBuild2DMipmaps(GL_TEXTURE_2D, 3, pBitmap->sizeX, pBitmap->sizeY, GL_RGB, GL_UNSIGNED_BYTE, pBitmap->data);glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);if (pBitmap){if (pBitmap->data){free(pBitmap->data);}free(pBitmap);}}then you call LoadTextures(texture,"file1.bmp",0); LoadTextures(texture,"file2.bmp",1); ...remember to load glaux.h hope you can code it in delphi :/[edited by - Okasion on December 31, 2002 1:28:02 AM];http://www.sulaco.co.za/opengl5.htmat the bottom of the page there''s a BMP,JPG and TGA texture loading unit (for delphi ofcourse)hope it helps  ;  Here a code-snippet, since I do not see the error myself:// Load Bitmaps And Convert To Texturesprocedure LoadGLTextures;  const allimg : array[0..texnum] of PChar = (''data/tree.bmp'', ''data/black.bmp'', ''data/white.bmp'', ''data/d_blue.bmp'', ''data/l_blue.bmp'');  var//    ctex : array[0..texnum] of PTAUX_RGBImageRec; ctex : PTAUX_RGBImageRec; ti : integer;  begin// Load Texture{   for ti:=0 to texnum doctex[ti]:=nil;}   ti:=texnum;   glGenTextures(texnum+1, texture[2]);   while ti>=0 dobegin  ctex := auxDIBImageLoadA(allimg[ti]);  if Assigned(ctex) then    begin // Create Texture glBindTexture(GL_TEXTURE_2D, texture[ti]); 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, 3, ctex^.sizeX, ctex^.sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, ctex^.data); ti:=ti-1; ctex:=nil;end  else   ti:=-1;end;  end;  and here some stuff from DRAW_GL_SCENEprocedure d3plane (x,y: Integer); //flowroc 2 draw chessboard begin if ((x+y) MOD 2)=0 then glBindTexture(GL_TEXTURE_2D, texture[4]) else glBindTexture(GL_TEXTURE_2D, texture[3]);  glTexCoord2f(0.0, 0.0); glVertex3f (qinc*  x  , 0, qinc*  y  );  glTexCoord2f(1.0, 0.0); glVertex3f (qinc*(x+1), 0, qinc*  y  );  glTexCoord2f(1.0, 1.0); glVertex3f (qinc*(x+1), 0, qinc*(y+1));  glTexCoord2f(0.0, 1.0); glVertex3f (qinc*  x  , 0, qinc*(y+1)); end;  Thanks to the anonymous poster but that demo only uses ONE texture and so it doesn''t help me here...  ;quote:glGenTextures(texnum+1, texture[2]);  I'm not sure wat exactly u intend to do with this, nor am i i sure if its the same with normal C style gl...to my understanding, the first parameter denotes the number of texture ID's u need, and the second parameter denotes where they will be stored. The second argument is usually an array or an address to a variable.Wat u seem to do is generate 'texnum+1' texture id's and storing it in texture location number 3 OR in a texture array of size 2 (not sure about Delphi syntax, inform me on this).Not sure if i'm heading the right way, but if i wanted 4 textures created I'll do (in C):GLuint texture[4], texnum = 4;glGenTextures(texnum, textures);ORGLuint tex1, tex2, tex3, tex4;glGenTextures(1, &tex1);glGenTextures(1, &tex2);glGenTextures(1, &tex3);glGenTextures(1, &tex4);hope i'm on the right track. [edited by - crazee on January 1, 2003 2:31:29 AM];  hi it''s me again the texture loading unit from that page can handle way more than 1 texturetex : array[0..3] of GLuint;loading the textures...LoadTexture(''filename1'', tex[0],false);LoadTexture(''filename2'', tex[1],false);LoadTexture(''filename3'', tex[2],false);binding them...glBindTexture(GL_TEXTURE_2D, tex[0]);...well you get the point.and about your own code, you could try glGenTextures (quantity,@texture[0]); ?? using the addres operator (sorry if i''m wrong here, but i''ve been using c only for some time now so my delphi is a little rusty)p.s. Happy Newyear everyone!;  Happy New Year Everyone!...and a happy one it already seems to be (for me), since I have found out, what my error was:I was calling glBindTexture within glBegin / glEnd ... that is illegal :-/Thanks for all feedback!...and:go with the flow  