Display list, textures and 3d exploration
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>
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement