Some Problems with GldrawElements ...

Hello !

I have some problemes when i use glDrawElements(); with Texture Coordinates !

I work with ase file, i reverse the y and z coordinnate …

when i don’t use glDrawElements my objets is creating in a good way ! but i tried to use gldraw… and my texture is not good applying ! (excuse for my bad english … )

my code :

if(num_Tvecteur > 0){
	if(num_Tface > 0){
		matrice_temp = new GLfloat[num_Tface*3 *2];
		for(int i=0; i < num_Tface; i++){
			matrice_temp[i*3+0] = matrice_Tfinale[matrice_Tface[(i*3+0)]*2 +0];
			matrice_temp[i*3+1] = matrice_Tfinale[matrice_Tface[(i*3+0)]*2 +1];

			matrice_temp[i*3+2] = matrice_Tfinale[matrice_Tface[(i*3+1)]*2 +0];
			matrice_temp[i*3+3] = matrice_Tfinale[matrice_Tface[(i*3+1)]*2 +1];

			matrice_temp[i*3+4] = matrice_Tfinale[matrice_Tface[(i*3+2)]*2 +0];
			matrice_temp[i*3+5] = matrice_Tfinale[matrice_Tface[(i*3+2)]*2 +1];
			
			//printf("Face %d 	X1:%f Y1:%f

",i,matrice_temp[i*3+0],matrice_temp[i*3+1]);
//printf("Face %d X2:%f Y2:%f
",i,matrice_temp[i*3+2],matrice_temp[i*3+3]);
//printf("Face %d X3:%f Y3:%f

",i,matrice_temp[i*3+4],matrice_temp[i*3+5]);
}

	}else{
		matrice_temp = matrice_Tfinale;
	}
}

objListe = glGenLists(1);
glNewList(objListe, GL_COMPILE);

	glEnableClientState(GL_VERTEX_ARRAY);
	glEnableClientState(GL_TEXTURE_COORD_ARRAY);

	glEnable(GL_TEXTURE_2D);
	if( pTex == NULL){
		if(numerotex > 0){
			TGAtex[numerotex].Activer();
		}else
			glBindTexture(GL_TEXTURE_2D, 8);
		}else{
			if(numerotex > 0)
				pTex[numerotex].SetActive();
	}
	//Coordonnées vecteur
	glVertexPointer(3,GL_FLOAT,0,matrice_finale);
	//Coordonnes textures
	glTexCoordPointer(2,GL_FLOAT,0,matrice_temp);
	//Création Object..
	glDrawElements(GL_TRIANGLES,num_face*3,GL_UNSIGNED_INT,matrice_face);

	/*
	glBegin(GL_TRIANGLES);
	  for(int j=0;j<num_face;j++){
			glTexCoord2f(matrice_Tfinale[matrice_Tface[(j*3+0)]*2+0],
						 matrice_Tfinale[matrice_Tface[(j*3+0)]*2+1]);

			glVertex3f(matrice_finale[matrice_face[(j*3+0)]*3+0],
					   matrice_finale[matrice_face[(j*3+0)]*3+1],
					   matrice_finale[matrice_face[(j*3+0)]*3+2]);

			glTexCoord2f(matrice_Tfinale[matrice_Tface[(j*3+1)]*2+0],
						 matrice_Tfinale[matrice_Tface[(j*3+1)]*2+1]);
			
			glVertex3f(matrice_finale[matrice_face[(j*3+1)]*3+0],
					   matrice_finale[matrice_face[(j*3+1)]*3+1],
					   matrice_finale[matrice_face[(j*3+1)]*3+2]);

			glTexCoord2f(matrice_Tfinale[matrice_Tface[(j*3+2)]*2+0],
						 matrice_Tfinale[matrice_Tface[(j*3+2)]*2+1]);

			glVertex3f(matrice_finale[matrice_face[(j*3+2)]*3+0],
					   matrice_finale[matrice_face[(j*3+2)]*3+1],
					   matrice_finale[matrice_face[(j*3+2)]*3+2]);
	  }
	glEnd();
	*/
	glDisable(GL_TEXTURE_2D);

	glDisableClientState(GL_VERTEX_ARRAY);
	glDisableClientState(GL_TEXTURE_COORD_ARRAY);

	glEndList();

if I use my first method with : glvertex, glTexCoord … it’s run ! but in my computer it’s a little slow ! (p2 350 128 RAM 16 Mo banshee)

do you have some idee ?

Thanks very much !
bye !
Cyril !

It’s probably because your vertex numbers for your texture coordinates do not match your vertex numbers for your model coordinates.

The ase file probably splits the texture mesh into a “front” and “back” or something similar to a quake type model, and when this is done you have multiple texture vertices map to a single model vertex. This happens along the “seam” of the front and back of the model. Count the number of texture coordinate vertices, and the number of model vertices, in your data, and if they don’t match then that’s your problem.

I think you have to duplicate the model vertices that are along the “seam” so that you can have a one-to-one correspondence with the texture vertices and model vertices, which is required when using glDrawElements.