PDA

View Full Version : Problem loading an .obj file



anton1212
04-06-2012, 09:51 AM
Good afternoon to everybody
Today I have a problem with loading an .obj file in OpenGl. The .obj file is a very simple cube (attached behind). I'm using Visual C Studio and what I don't know is how to read the data on the .obj.
I open it as an .obj file with fopen but my doubt comes when I try to extract the values. I'm not trying to create an universal function or library, I'm only trying to extract the values that I have on the specific .obj file so I know the number of spaces, words and where they are so with a couple of "for" loops I should be able to do it.
The problem is that when I eliminate the spaces using a fgetc and when I try to read the float values contained, I always have the same result (always 0.00000)
Could you help me? I attach now the whole code


#
# Wavefront OBJ file..\cubo.obj
#
# Converted by the PolyTrans geometry converter from Okino Computer Graphics, Inc.
# Date/time of export: 11/17/19105 11:36:18
#
# Bounding box of geometry = (-0.5,-0.5,-0.5) to (0.5,0.5,0.5).

mtllib cubo.mtl

# Coordinates for object 'cubo'
v -0.500000 -0.500000 0.500000
v 0.500000 -0.500000 0.500000
v -0.500000 0.500000 0.500000
v 0.500000 0.500000 0.500000
v -0.500000 0.500000 -0.500000
v 0.500000 0.500000 -0.500000
v -0.500000 -0.500000 -0.500000
v 0.500000 -0.500000 -0.500000
# 8 vertices

vt -1.000000 0.0 0.0
vt -1.000000 1.000000 0.0
vt 0.0 0.0 0.0
vt 0.0 1.000000 0.0
vt 0.0 2.000000 0.0
vt 0.0 3.000000 0.0
vt 0.0 4.000000 0.0
vt 1.000000 0.0 0.0
vt 1.000000 1.000000 0.0
vt 1.000000 2.000000 0.0
vt 1.000000 3.000000 0.0
vt 1.000000 4.000000 0.0
vt 2.000000 0.0 0.0
vt 2.000000 1.000000 0.0
# 14 texture vertices

usemtl default__2


s off
f 1/3 2/8 3/4
f 2/8 4/9 3/4
f 3/4 4/9 5/5
f 4/9 6/10 5/5
f 5/5 6/10 7/6
f 6/10 8/11 7/6
f 7/6 8/11 1/7
f 8/11 2/12 1/7
f 2/8 8/13 4/9
f 8/13 6/14 4/9
f 7/1 1/3 5/2
f 1/3 3/4 5/2
# 12 polygons


AND my code in C



for(i=0;i<57;i++)
{

if(i>13 &amp;&amp; i<22) //FOR EXAMPLE FOR EXTRACT THE V COORDINATES
{
fscanf(cubo,"%c", &amp;prov);
fscanf(cubo,"%c", &amp;prov);
fscanf(cubo,"%f", &amp;num);
printf("%f",num); //I initialized it as 0 at the begining and I always have a 0 from the printf
getchar();
}
}