Advertisement

Display list, textures and 3d exploration

Started by June 11, 2000 04:09 PM
2 comments, last by lunasol 24 years, 5 months ago
Hi, it must simple but i can''t get it : i build a scene with 3DSMAX with 2 textures (let''s be humble...) i convert it as a display list with 3D exploration (cool app IMHO) but (there is a always a "but") when i run my app i''ve got only 1 texture. if you can look at my code a few minutes to tell me what is wrong... static int material_ref [2][2] = { {0,12}, {1,24} }; void LoadGLTextures(){ int status=1; int i; GLfloat mat_emission[]={1.0f,0.7f,0.0f,1.0f}; GLfloat mat_diffuse[]={1.0f,0.7f,0.0f,1.0f}; AUX_RGBImageRec *TextureImage[2]; memset(TextureImage,0,sizeof(void *)*1); if (TextureImage[0]=LoadBMP("data/crom1.bmp")){ glGenTextures(1,&texture[0]); glTexImage2D(GL_TEXTURE_2D,0,3,TextureImage[0]->sizeX,TextureImage[0]->sizeY,0, GL_RGB,GL_UNSIGNED_BYTE,TextureImage[0]->data); glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE); glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT); glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT); } if (TextureImage[1]=LoadBMP("data/castle1.bmp")){ glGenTextures(1,&texture[1]); glTexImage2D(GL_TEXTURE_2D,0,3,TextureImage[1]->sizeX,TextureImage[1]->sizeY,0, GL_RGB,GL_UNSIGNED_BYTE,TextureImage[1]->data); glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE); glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT); glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT); } for (i=0;i<2;i++){ if (TextureImage){ if(TextureImage->data){ free(TextureImage->data); } free(TextureImage); } } } void MyMaterial(GLenum mode,GLfloat *f,GLfloat alpha){ GLfloat d[4]; d[0]=f[0]; d[1]=f[1]; d[2]=f[2]; d[3]=alpha; glMaterialfv (GL_FRONT_AND_BACK,mode,d); }; void SelectMaterial(int i){ GLfloat alpha=materials.alpha; MyMaterial (GL_AMBIENT, materials.ambient,alpha); MyMaterial (GL_DIFFUSE, materials.diffuse,alpha); MyMaterial (GL_SPECULAR, materials.specular,alpha); MyMaterial (GL_EMISSION, materials.emission,alpha); glBindTexture( GL_TEXTURE_2D, texture ); }; GLint Gen3DObjectList() { int i; int j; int mindex=0; int mcount=0; GLint lid=glGenLists(1); glNewList(lid, GL_COMPILE); glBegin (GL_TRIANGLES); for(i=0;i<sizeof(face_indicies)/sizeof(face_indicies[0]);i++) { if(!mcount) { SelectMaterial(material_ref[mindex][0]); mcount=material_ref[mindex][1]; mindex++; } mcount–; for(j=0;j<3;j++) { int vi=face_indicies[j]; int ni=face_indicies[j+3]; int ti=face_indicies[j+6]; glNormal3f (normals[ni][0],normals[ni][1],normals[ni][2]); glTexCoord2f(textures[ti][0],textures[ti][1]); glVertex3f (verticies[vi][0],verticies[vi][1],verticies[vi][2]); } } glEnd (); glEndList(); return lid; } when i run my app ALL my objects are mapped with the last texture i load. hope that make sense… thanks for the replies lunasol </i>
ok i find myself what was wrong (glBindTexture inside glBegin/glEnd is not effective)

sorry if you lose your time reading the long post. The next time i will search a little bit more before posting


lunasol
Advertisement
ok, I think to have multi-texturing you must only call glGenTextures() once. You should call it before you load your first texture. It should look like this, glGenTextures(2,&texture[0]);
That may be the problem.
Joe
My HomepageSome shoot to kill, others shoot to mame. I say clear the chamber and let the lord decide. - Reno 911
You''re right, you cannot bind textures between glBegin and glEnd. But, you also need to bind before you load the texture (glTexImage2D) and set all the parameters.

glGenTextures doesn''t perform a bind, it merely allocates some texture objects for your code.

You can call glGenTextures as many times as you want.



Scott Franke [druid-]
sfranke@gljournal.org
druid-'s GL Journal
http://www.gamedev.net/opengl

This topic is closed to new replies.

Advertisement