Results 1 to 10 of 10

Thread: Texture mapping on a disk

  1. #1
    Junior Member
    Join Date
    Dec 2012
    Posts
    5

    Texture mapping on a disk

    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.

    Can anyone tell me how to define the texture coordinates?

  2. #2

    Re: Texture mapping on a disk

    Quote Originally Posted by Zelig
    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.

    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..

  3. #3
    Junior Member
    Join Date
    Dec 2012
    Posts
    5

    Re: Texture mapping on a disk

    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...

  4. #4

    Re: Texture mapping on a disk

    Can u post ur code here .. I want u see ur draw function alongwith coordinates.

  5. #5
    Junior Member
    Join Date
    Dec 2012
    Posts
    5

    Re: Texture mapping on a disk

    The "Draw" function" :
    Code :
    	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_SHININESS, 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,nombreSecteurs*3,GL11.GL_UNSIGNED_BYTE, tableauEventail);
    		gl.glDisable(GL10.GL_TEXTURE_2D);
    		gl.glDisable(GL10.GL_BLEND);
    		gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
    	}

    and the code for the creation of the disk :
    Code :
    		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.length * 4);
    		tbb.order(ByteOrder.nativeOrder());
    		bufferTexture = tbb.asFloatBuffer();
    		bufferTexture.put(coordonnéesTexture);
    		bufferTexture.position(0);

  6. #6

    Re: Texture mapping on a disk

    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, }

  7. #7
    Junior Member
    Join Date
    Dec 2012
    Posts
    5

    Re: Texture mapping on a disk

    No, I don't have 5 triangle fans!!! One is enough th generate a disk!!!

  8. #8
    Member
    Join Date
    Jun 2012
    Location
    Texas
    Posts
    61

    Re: Texture mapping on a disk

    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

  9. #9
    Junior Member
    Join Date
    Dec 2012
    Posts
    5

    Re: Texture mapping on a disk

    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?...

  10. #10
    Member
    Join Date
    Jun 2012
    Location
    Texas
    Posts
    61

    Re: Texture mapping on a disk

    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

Similar Threads

  1. Texture mapping
    By Giacomo in forum OpenGL ES general technical discussions
    Replies: 3
    Last Post: 06-28-2005, 08:04 AM
  2. Help needed(Texture Mapping)
    By qasim1981 in forum OpenGL ES general technical discussions
    Replies: 12
    Last Post: 01-15-2005, 10:50 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •