PDA

View Full Version : Texture mapping on a disk



Zelig
12-31-2012, 09:04 AM
I have created a circular surface using a triangle fan and I now want to put a texture on it. I know that I must use texture coordinates to map portions of my texture to the triangles constituting my disk but I can't succed in getting a correct result. :cry:

Can anyone tell me how to define the texture coordinates?

debinair
01-03-2013, 01:58 AM
I have created a circular surface using a triangle fan and I now want to put a texture on it. I know that I must use texture coordinates to map portions of my texture to the triangles constituting my disk but I can't succed in getting a correct result. :cry:

Can anyone tell me how to define the texture coordinates?

If you are drawing it with triangle fan, the texcordinates should not differ.
{0,0,
1,0,
1,1,
0,1}
it should work..

Zelig
01-03-2013, 09:17 AM
If I use the coordinates indicated, my texture appears but the complete texture is displayed in the first two triangles. In the other triangles, I only get some "random" black lines... :cry:

debinair
01-03-2013, 11:54 AM
Can u post ur code here .. I want u see ur draw function alongwith coordinates.

Zelig
01-04-2013, 04:38 AM
The "Draw" function" :

public void draw(GL10 gl){
gl.glVertexPointer(3, GL11.GL_FLOAT, 0, tableauSommets);
gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
gl.glColorPointer(4, GL11.GL_UNSIGNED_BYTE, 0, tableauCouleurs);
gl.glEnableClientState(GL10.GL_COLOR_ARRAY);
gl.glNormalPointer(GL10.GL_FLOAT, 0,tableauVecteursNormaux);
gl.glEnableClientState(GL10.GL_NORMAL_ARRAY);
gl.glMaterialfv(GL10.GL_FRONT_AND_BACK, GL10.GL_SPECULAR,couleurMatériau);
gl.glMaterialfv(GL10.GL_FRONT_AND_BACK, GL10.GL_DIFFUSE,couleurMatériau);
gl.glMaterialf(GL10.GL_FRONT_AND_BACK,GL10.GL_SHIN INESS, 10);
gl.glEnable(GL10.GL_TEXTURE_2D);
gl.glEnable(GL10.GL_BLEND);
gl.glBlendFunc(GL10.GL_ONE, GL10.GL_SRC_COLOR);
gl.glBindTexture(GL10.GL_TEXTURE_2D, textures[0]);
gl.glTexCoordPointer(2, GL10.GL_FLOAT,0, bufferTexture);
gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY );
gl.glDrawElements(GL11.GL_TRIANGLE_FAN,nombreSecte urs*3,GL11.GL_UNSIGNED_BYTE, tableauEventail);
gl.glDisable(GL10.GL_TEXTURE_2D);
gl.glDisable(GL10.GL_BLEND);
gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRA Y);
}


and the code for the creation of the disk :

sommets[0]=0.0f;
sommets[1]=0.0f;
sommets[2]=épaisseur/2;
angle=(float)(2*java.lang.Math.PI/nombreSecteurs);
for(i=0;i<nombreSecteurs;i++){
// les sommets du triangle
sommets[3+3*i]=(float)(rayon*java.lang.Math.cos(i*angle));
sommets[4+3*i]=(float)(rayon*java.lang.Math.sin(i*angle));
sommets[5+3*i]=épaisseur/2;
}
for(i=0;i<couleursSommets.length;i++){
couleursSommets[i]=1.0f;
}
for(i=0;i<vecteursNormaux.length;i+=3){
vecteursNormaux[i]=0.0f;
vecteursNormaux[i+1]=0.0f;
vecteursNormaux[i+2]=1.0f;
}
for(i=0;i<nombreSecteurs-1;i++){
éventail[3*i]=0;
éventail[3*i+1]=(byte)(i+1);
éventail[3*i+2]=(byte)(i+2);
}
éventail[3*nombreSecteurs-3]=0;
éventail[3*nombreSecteurs-2]=(byte)nombreSecteurs;
éventail[3*nombreSecteurs-1]=1;
vbb = ByteBuffer.allocateDirect(sommets.length * 4);
vbb.order(ByteOrder.nativeOrder());
tableauSommets = vbb.asFloatBuffer();
tableauSommets.put(sommets);
tableauSommets.position(0);
vbb= ByteBuffer.allocateDirect(couleursSommets.length*4 );
vbb.order(ByteOrder.nativeOrder());
tableauCouleurs =vbb.asFloatBuffer();
tableauCouleurs.put(couleursSommets);
tableauCouleurs.position(0);
vbb = ByteBuffer.allocateDirect(vecteursNormaux.length * 4);
vbb.order(ByteOrder.nativeOrder());
tableauVecteursNormaux = vbb.asFloatBuffer();
tableauVecteursNormaux.put(vecteursNormaux);
tableauVecteursNormaux.position(0);
tableauEventail=ByteBuffer.allocateDirect(éventail .length);
tableauEventail.put(éventail);
tableauEventail.position(0);
couleurMatériau=transformeEnFloatBuffer(couleur);
tbb = ByteBuffer.allocateDirect(coordonnéesTexture.lengt h * 4);
tbb.order(ByteOrder.nativeOrder());
bufferTexture = tbb.asFloatBuffer();
bufferTexture.put(coordonnéesTexture);
bufferTexture.position(0);

debinair
01-04-2013, 05:35 AM
Now, its like 1 GL_TRIANGLE_FAN require one texcoord set. In your code, if you have 5 GL_TRIANGLE_FAN you should repeat tex cords 5 times in same array.

for e.g. for 2 GL_TRINGLE_FAN

your array will be
{
0,0,
1,0,
1,1,
0,1,

0,0,
1,0,
1,1,
0,1, }

Zelig
01-25-2013, 08:17 AM
No, I don't have 5 triangle fans!!! One is enough th generate a disk!!!

ClayMontgomery
02-10-2013, 03:27 PM
It's best to use a 3D authoring tool like Blender to do this interactively, then export to a Collada or POD file to a game engine.

Regards, Clay

Zelig
02-17-2013, 12:02 AM
As I am very new to open GL, can you please explain me the basis of the use of a game engine? : if several engines exist, which one to choose ? How can I insert this engine in my application?...

ClayMontgomery
02-18-2013, 08:52 AM
A game engine will read your vertices and texture coordinates from a file (Collada or POD) and send the appropriate commands to OpenGL ES. It also does animations. The best free game engines are Ogre and PowerVR.

Regards, Clay