About glDrawElements

Hi,

i met a problem at glDrawElements function. I use the following codes to test.


glVertexPointer(3, GL_FLOAT,0,vertices);
glNormalPointer(GL_FLOAT,0, normals);

glDrawElements( GL_TRIANGLES, NUM_DUCK_FACES * 3, GL_UNSIGNED_BYTE, index );

i think glDrawElements is equal to these codes, i know there is no glVertex in Opengl es, i just want to show what glDrawElements does :


glVertex(vertices(index[0]));
glNormal(normals(index[0]));
glVertex(vertices(index[1]));
glNormal(normals(index[1]));
.....

That is to say vertex and normal have the same index, am i right? but when i have two index for vertex and normal what i can do?
For example,



static const GLfloat objVertexBoat[]={.....}

static const GLbyte objNormalBoat[]={.....}

static const GLubyte objVertexIndexBoat[]=
    {0,2,3,
     0,3,1,
     ....
    }
static const GLubyte objNormalIndexBoat[]=
    {0,1,2,
     0,2,3,
     ....
    }

That is to say normal has its index for every vertex. So how can i use glDrawElements? Need i change the index of normal to be the same with vertex?
Any other simple way?

Another question, what do uv means? i think they are not the same with ST. Because the value of uv often is not in range 0 and 1.

Looking forward to fast replying. Thank you

Mia

[attachment=0:vw47w1h1]cube.rar[/attachment:vw47w1h1]
These files contains the .skp and .dae files.

Actually glVertex is always the last call for a specific vertex.

That is to say vertex and normal have the same index, am i right? but when i have two index for vertex and normal what i can do?

Re-organise your data so it only needs one index. OpenGL (ES) does not support more than one index array.

Another question, what do uv means? i think they are not the same with ST. Because the value of uv often is not in range 0 and 1.

The OpenGL specification uses U and V for unnormalised texel coordinates and S and T for normalised texture coordinates. But typically they’re both used interchangeably for texture coordinates. Texture coordinates don’t have to be between 0 and 1.

The following datas are datas , texture and normal coordinates for every vertex:


<source id="mesh1-geometry-position"> 
  <float_array id="mesh1-geometry-position-array" count="24">178.350505 121.322840 0.000000 48.100505 84.572840 0.000000 48.100505 121.322840 0.000000 178.350505 84.572840 0.000000 178.350505 84.572840 12.000000 178.350505 121.322840 12.000000 48.100505 121.322840 12.000000 48.100505 84.572840 12.000000</float_array> 
- <technique_common> 
- <accessor source="#mesh1-geometry-position-array" count="8" stride="3"> 
  <param name="X" type="float" /> 
  <param name="Y" type="float" /> 
  <param name="Z" type="float" /> 
  </accessor> 
  </technique_common> 
  </source> 



<source id="mesh1-geometry-uv"> 
  <float_array id="mesh1-geometry-uv-array" count="48">-178.350505 121.322840 -48.100505 84.572840 -48.100505 121.322840 -178.350505 84.572840 121.322840 0.000000 84.572840 12.000000 84.572840 0.000000 121.322840 12.000000 -178.350505 0.000000 -48.100505 12.000000 -178.350505 12.000000 -48.100505 0.000000 -84.572840 0.000000 -121.322840 12.000000 -121.322840 0.000000 -84.572840 12.000000 48.100505 0.000000 178.350505 12.000000 48.100505 12.000000 178.350505 0.000000 178.350505 84.572840 48.100505 121.322840 48.100505 84.572840 178.350505 121.322840</float_array> 
- <technique_common> 
- <accessor source="#mesh1-geometry-uv-array" count="24" stride="2"> 
  <param name="S" type="float" /> 
  <param name="T" type="float" /> 
  </accessor> 
  </technique_common> 
  </source>


<source id="mesh1-geometry-normal"> 
  <float_array id="mesh1-geometry-normal-array" count="18">0.000000 0.000000 -1.000000 1.000000 0.000000 0.000000 0.000000 1.000000 0.000000 -1.000000 0.000000 0.000000 0.000000 -1.000000 0.000000 0.000000 0.000000 1.000000</float_array> 
- <technique_common> 
- <accessor source="#mesh1-geometry-normal-array" count="6" stride="3"> 
  <param name="X" type="float" /> 
  <param name="Y" type="float" /> 
  <param name="Z" type="float" /> 
  </accessor> 
  </technique_common> 
  </source> 



<triangles material="FrontColorNoCulling" count="12"> 
  <input semantic="VERTEX" source="#mesh1-geometry-vertex" offset="0" /> 
  <input semantic="NORMAL" source="#mesh1-geometry-normal" offset="1" /> 
  <input semantic="TEXCOORD" source="#mesh1-geometry-uv" offset="2" set="0" /> 
  

0 0 0 1 0 1 2 0 2 1 0 1 0 0 0 3 0 3 0 1 4 4 1 5 3 1 6 4 1 5 0 1 4 5 1 7 0 2 8 6 2 9 5 2 10 6 2 9 0 2 8 2 2 11 1 3 12 6 3 13 2 3 14 6 3 13 1 3 12 7 3 15 1 4 16 4 4 17 7 4 18 4 4 17 1 4 16 3 4 19 4 5 20 6 5 21 7 5 22 6 5 21 4 5 20 5 5 23</p> 
  </triangles> 


In terms of your reply, the first triangle is made of vertex (178.350505,121.322840,0.000000),(48.100505,84.572840,0.000000),(48.100505,121.322840,0.000000), and their texture coordinates are (-178.350505,121.322840),(-48.100505,84.572840),(-48.100505,121.322840) (without considing normal vectors). I think they won’t work. The corresponding datas are so strange.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.