PDA

View Full Version : using vbo with .obj file loader



ssnakus
08-18-2008, 08:18 PM
hi
i try to render an object described in .obj file that contains all the attributes (vertex coordinates, texture coordinates, normals...). i use a loader to load all that to opengl.
the problem is that i want to render the object whith vbo but the count of the attributes is not the same.
the file contains also the indices of each attribute;



exemple of a cube:
the file cube.obj contains:
v -0.5 0 0.5
v 0.5 0 0.5
v -0.5 0 -0.5
v 0.5 0 -0.5
v -0.5 1 0.5
v 0.5 1 0.5
v -0.5 1 -0.5
v 0.5 1 -0.5
# 8 vertices

vt 0 0 0
vt 1 0 0
vt 0 1 0
vt 1 1 0
vt 0 0 0
vt 1 0 0
vt 0 1 0
vt 1 1 0
vt 0 0 0
vt 1 0 0
vt 0 1 0
vt 1 1 0
# 12 texture vertices

vn 0 -2 0
vn 0 -1 0
vn 0 -1 0
vn 0 -2 0
vn 0 2 0
vn 0 1 0
vn 0 1 0
vn 0 2 0
# 8 vertex normals

g Box01
f 1/10/1 3/12/3 4/11/4
f 4/11/4 2/9/2 1/10/1
f 5/9/5 6/10/6 8/12/8
f 8/12/8 7/11/7 5/9/5
f 1/5/1 2/6/2 6/8/6
f 6/8/6 5/7/5 1/5/1
f 2/1/2 4/2/4 8/4/8
f 8/4/8 6/3/6 2/1/2
f 4/5/4 3/6/3 7/8/7
f 7/8/7 8/7/8 4/5/4
f 3/1/3 1/2/1 5/4/5
f 5/4/5 7/3/7 3/1/3
# 12 faces

f 5/4/5 7/3/7 3/1/3 means a face with 3 vertex(triangle)
5/4/5 means that the coordinate of the first vertex is in the 5th positin of vertex's array, the texture coordinate is in the 4th position of the textcoord array...


who can hel me?
thanks

babis
08-19-2008, 08:13 AM
The easy way out is to duplicate your data & have as many vertices/normals/texcoords as indices. So create some new arrays out of your current (v/vt/vn) ones.

ssnakus
08-26-2008, 07:42 AM
thanks babis, that work well. but i would know if i can make that work without more arrays, for exemple modify the VBO's fonctions parameters??