From Collada to openGL ES texture coordinates

i am developing a 3D engine on mobile phone and have a big problem with texture coordinates. initially it took me some time to find a decent collada exporter not using polygon mode and glBegin to create objects, and also which exports texture coordinates, currently i am dealing with maya to obtain collada files from 3d models.

but i fail to understand how to use the texture coordinates to draw a textured cube.

here is the complete dae file i obtained from maya :

<?xml version=“1.0” encoding=“utf-8”?>
<COLLADA xmlns=“” version=“1.4.1”>
<authoring_tool>Maya2008 | ColladaMaya v3.05B</authoring_tool>
<comments>ColladaMaya export options: bakeTransforms=0;exportPolygonMeshes=1;bakeLighting=0;isSampling=0;
<unit meter=“0.01” name=“centimeter”/>
<image id=“file1” name=“file1”>
<technique profile=“MAYA”>
<material id="_01___Default" name="_01___Default">
<instance_effect url="#_01___Default-fx"/>
<effect id="_01___Default-fx">
<newparam sid=“file1-surface”>
<surface type=“2D”>
<newparam sid=“file1-sampler”>
<technique sid=“common”>
<color>0 0 0 1</color>
<color>0.588235 0.588235 0.588235 1</color>
<texture texture=“file1-sampler” texcoord=“TEX0”>
<technique profile=“MAYA”>
<color>0 0 0 1</color>
<color>0 0 0 1</color>
<transparent opaque=“RGB_ZERO”>
<color>0 0 0 1</color>
<technique profile=“FCOLLADA”/>
<geometry id=“polySurfaceShape1” name=“polySurfaceShape1”>
<source id=“polySurfaceShape1-positions” name=“position”>
<float_array id=“polySurfaceShape1-positions-array” count=“24”>-50.0 -50.0 0 50.0 -50.0 0 -50.0 50.0 0 50.0 50.0 0 -50.0 -50.0 50.0 50.0 -50.0 50.0 -50.0 50.0 50.0 50.0 50.0 50.0</float_array>
<accessor source="#polySurfaceShape1-positions-array" count=“8” stride=“3”>
<param name=“X” type=“float”/>
<param name=“Y” type=“float”/>
<param name=“Z” type=“float”/>
<source id=“polySurfaceShape1-map1” name=“map1”>
<float_array id=“polySurfaceShape1-map1-array” count=“60”>0 0 1 0 0 1 1 1 0 0 1 0 0 1 1 1 0 0 1 0 0 1 1 1 0 0 1 0 1 1 1 1 0 1 0 0 0 0 1 0 1 1 1 1 0 1 0 0 0 0 1 0 1 1 1 1 0 1 0 0</float_array>
<accessor source="#polySurfaceShape1-map1-array" count=“30” stride=“2”>
<param name=“S” type=“float”/>
<param name=“T” type=“float”/>
<vertices id=“polySurfaceShape1-vertices”>
<input semantic=“POSITION” source="#polySurfaceShape1-positions"/>
<triangles material="_01___DefaultSG" count=“12”>
<input semantic=“VERTEX” source="#polySurfaceShape1-vertices" offset=“0”/>
<input semantic=“TEXCOORD” source="#polySurfaceShape1-map1" offset=“1” set=“0”/>

0 9 2 11 3 10 3 10 1 8 0 9 4 12 5 13 7 14 7 15 6 16 4 17 0 4 1 5 5 7 5 7 4 6 0 4 1 0 3 1 7 3 7 3 5 2 1 0 3 18 2 19 6 20 6 21 7 22 3 23 2 24 0 25 4 26 4 27 6 28 2 29</p>
<technique profile=“MAYA”>
<visual_scene id=“VisualSceneNode” name=“cube”>
<node id=“Box01” name=“Box01” type=“NODE”>
<translate sid=“translate”>3.52794 0 -1.99493</translate>
<rotate sid=“rotateZ”>0 0 1 0</rotate>
<rotate sid=“rotateY”>0 1 0 0</rotate>
<rotate sid=“rotateX”>1 0 0 -90</rotate>
<instance_geometry url="#polySurfaceShape1">
<instance_material symbol="_01___DefaultSG" target="#_01___Default">
<bind_vertex_input semantic=“TEX0” input_semantic=“TEXCOORD” input_set=“0”/>
<technique profile=“MAYA”>
<layer name="_0">Box01 polySurfaceShape1</layer>
<technique profile=“FCOLLADA”>
<instance_visual_scene url="#VisualSceneNode"/>

opengl has some limitations which imply to draw without glBegin, so i am using glDrawElements( GL_TRIANGLES, …) for that. geometry is fine, my only problem is texture coordinates.

if i follow the general collada information we find here or there on the web, the texture coordinates table is from this file : 1 0 1 1 0 1 0 1 0 0 1 0…
basically we check every 2nd value of the

list to get the texture coordinate ID to retrieve in the “polySurfaceShape1-map1-array” a couple of coordinates, so the previous list was given for the first face by the following ID list : 9 11 10 10 8 9…

now this texture coordinate table gives me at rendering a weird displayed texture, and i figured that the following table gives me a properly rendered texture :

GLfloat quadTexCoords[] = {
0.0f, 0.0f,
1.0f, 0.0f,
0.0f, 1.0f,
1.0f, 1.0f,
1.0f, 0.0f,
1.0f, 1.0f,
0.0f, 0.0f,
0.0f, 1.0f,
1.0f, 0.0f,
1.0f, 1.0f,
0.0f, 0.0f,
0.0f, 1.0f,
1.0f, 0.0f,
1.0f, 1.0f,
0.0f, 0.0f,
0.0f, 1.0f,
// TOP
0.0f, 0.0f,
1.0f, 0.0f,
0.0f, 1.0f,
1.0f, 1.0f,
1.0f, 0.0f,
1.0f, 1.0f,
0.0f, 0.0f,
0.0f, 1.0f

so it appears that the texture table i retrieve from the collada file gives me the texture coordinates for the triangles but opengl es is waiting for quad texture coordinates instead, as obviously the ID list : 9 11 10 10 8 9 contains 3 consecutive texture coordinates relative to a triangle but we cant have for a quad twice the same texture coordinate ID for a face

anyone has an idea of what is wrong in my engine ?

What does your function call to glTexCoordPointer look like?

the code to display the cube is the following one :

glVertexPointer( 3, GL_SHORT, 0, pshVertexTab );
glTexCoordPointer( iNbTexCoordPerVertex, GL_FLOAT, 0, pfTexCoordTab );
glBindTexture( GL_TEXTURE_2D, iTextureID );
glDrawElements( GL_TRIANGLES, iNbTriangleVertex, GL_UNSIGNED_BYTE, oVertexIDTab );

i have just verified the code of the collada dom viewer, which displays correctly the cube from the dae file and it uses same instructions than me and data structures sent to opengl are the same, so i really dont see any reason for opengl es to require some quad texture coordinates (as 4 UV coordinates) instead of the 6 texture coordinates you are supposed to provide when in GL_TRIANGLE mode

i also noticed that all opengl es texturing tutorials i found use quad texture coordinates to display a cube, there is something i absolutely fail to understand

fater tracing the collada dom viewer source at run, i have finaly reorganized data i was feeding opengl es with and now it functions

Glad to hear that you figured it out. Can you post how you solved it for OpenGL ES to conclude this thread for future reference? Thanks.

you have 3 tables to deliver to opengl es when you want to draw an object :

  • vertex coordinate table, with glVertexPointer
  • texture coordinate table, with glTexCoordPointer
  • vertex ID table, with glDrawElements

you may also have the normals table to provide but thats optional for some basic example

i was initialy rebuilding the texture coordinate table by getting each texture coordinate ID in

(dont forget the offset to get the right ID) and then rebuilding a table by retrieving the corresponding texture coordinate in the <float_array> node relative to texture coordinates, but i wasnt doing the same for vertices coordinates, i was using straight the <float_array> node relative to vertices coordinates and i was also retrieving from the

table only the vertex ID in a new table.

since we provide with glDrawElements a single table ID, the texture coordinates table and the vertices coordinates tables were not sorted the same way, and my texture was badly applied. so finaly i rebuild the vertices coordinates table the same way than the texture coordinates table. and the table i provide to glDrawElements is a new one, very simply created with each element having the same value than its rank in the table, basicaly the list is now :


I’ve written a step-by-step tutorial on how I parsed a COLLADA export taken from LightWave and imported it into OpenGL ES, which may be of use.