PDA

View Full Version : Etch and lib3ds



knobby67
03-27-2007, 07:10 AM
Hi All,
I recently started using lib3ds as my model loader for OpenGL, after a few attempts I got it working with models, lights and textures. I then got updated my Debian system to Etch and found my code didn't draw any models, that is exactly the same code I was using beforehand. On much testing it seemed that lib3ds was not producing any vertexes? I wrote this bit of test code to view the model, can anyone tell me if what I'm doing is right or is there a problem with Etch and lib3ds?

void LoadModel(char *filename)
{
Lib3dsFile* file = 0;
Lib3dsMesh *mesh;
Lib3dsFace *face;

unsigned int p,loop=0,i;
float *value;


/*******************************Load the model file****************************/
file=lib3ds_file_load(filename);
if ( ! file )
{
printf(" Loading 3DS file failed.\n");
}
else
{
printf("Model Loaded \n");
}
/************************************************** ****************************/
printf("Model Name %s\n",file->name);
printf("Model Version %lX\n",file->mesh_version);
/************************************************** ****************************/

/**********************Step through attributes*********************************/
for (mesh = file->meshes; mesh; mesh = mesh->next)
{
printf("Object name %s\n",mesh->name);

for (p = 0; p < mesh->faces; p++) /* step through mesh list */
{
face = &mesh->faceL[p];

printf("%d Material name %s",++loop,face->material);
printf(" points %o %o %o",face->points[0],face->points[1],face->points[2]);
printf(" flags %o ",face->flags);
printf(" smoothing %lX", face->smoothing);
printf(" normal %f %f %f \n",face->normal[0],face->normal[1],face->normal[2]);

/**********************Vertex ************************************************** ****/

for (i=0; i<3; ++i)
{
value=mesh->pointL[face->points[i]].pos;
printf("vertex point %d %f %f %f \n",i,*value,*(value+1),*(value+2))

}

}
}



}




This produces the following output
Model Loaded
Model Name MAXSCENE
Model Version 3
Object name Sphere01
1 Material name blueShine points 0 1 2 flags 7 smoothing 1 normal 1.000000 0.000000 0.000000
vertex point 0 0.000000 0.000000 0.000000
vertex point 1 0.000000 0.000000 0.000000
vertex point 2 0.000000 0.000000 0.000000
2 Material name blueShine points 742 2 3 flags 7 smoothing 1 normal 1.000000 0.000000 0.000000
vertex point 0 0.000000 0.000000 0.000000
vertex point 1 0.000000 0.000000 0.000000
vertex point 2 0.000000 0.000000 0.000000


The vertex 0,0,0 is repeated for the rest of the model, can anyone give me a pointer in the right direction? Thanks. :)
I should add I've tried loads of models all are the same. I've now also a built in function from lib3ds to show the vertexes and it also shows all zeros.
Sorry if this is not the correct forum, I've tried everywhere else with no answers, so I'm hoping some other opengl linux programmer also uses this libary and can give me a poiner.

knobby67
03-27-2007, 08:00 AM
Hi all,
I'm even more puzzled now? I've found and used the built in function lib3ds_mesh_dump(mesh) and this also lists my vertexes as all zeros. So I thought I'd uses ldd to see if I could see the lib3ds library listed, no sign of it, but it exists in both usr/lcal/lib and usr/lib.

As my print code doesn't do any screen drawing, so I thought I'd get rid of my library files except for lib3ds so I change part of my make from
*old make*
all:
$(CC) source/main.c -o test -lGL -lGLU `sdl-config --cflags --libs` `sdl-config --libs` -lSDL_image -l3ds

to
new make
all:
$(CC) source/main.c -o test -l3ds

Now when I compile I suddenly get a large number of errors

make -k all
gcc -Wall -ansi -g source/main.c -o test -l3ds
/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../lib/lib3ds.a(matrix.o): In function `lib3ds_matrix_rotate_z':
(.text+0xe62): undefined reference to `sinf'
/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../lib/lib3ds.a(matrix.o): In function `lib3ds_matrix_rotate_z':
(.text+0xe6d): undefined reference to `cosf'
/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../lib/lib3ds.a(matrix.o): In function `lib3ds_matrix_rotate_y':
(.text+0xf42): undefined reference to `sinf'
/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../lib/lib3ds.a(matrix.o): In function `lib3ds_matrix_rotate_y':
(.text+0xf4d): undefined reference to `cosf'
/

and many more similar errors, can anyone advise, has anyone seen this before? I think I'm going mad :(

nib
03-27-2007, 07:02 PM
It appears to me that you have not included the standard library in your compile? Or you need to include math.h in your code.

So, it compiles but when links it can't find the calls in the library and pukes.

http://en.wikipedia.org/wiki/Math.h

Just my guess...

predaeus
03-28-2007, 12:41 AM
Using math.h also requires to link against the math library so probably add -lm.

knobby67
03-28-2007, 01:16 AM
Hi thanks -lm solves my second problem. However I still have the first problem of all vectors loaded are 0.0f

jide
03-28-2007, 04:29 AM
Are you pretty sure the model you're loading has vertices ? Did you tried blender and the 3ds plugin to see what it sees (or use wings3d) ? Even tried with another model file ?

I personally never used lib3ds providen in Debian/Etch. I use my own compiled one. But I don't see why there should have a problem with Debiand and lib3ds.

Cannot tell much more for the moment.

knobby67
03-28-2007, 06:12 AM
Hi yes I've tried half a dozen models, on top of that my code worked under sarge. And I've tried both compiling my own and apt-get the debian package, both give the same results 0.0f for vertices :s I'm quiet at a loss.

jide
03-28-2007, 06:39 AM
I have Debian Etch, and all is working pretty well. Have you got some specific stuff installed, do you run under 64 bits cpus ?
Did you ever looked if the gcc you have is compatible with lib3ds ? Which version of both gcc and lib3ds do you use (and also the libc) ?

From a quick view at the bug browser of lib3ds I found that:

http://sourceforge.net/tracker/index.php?func=detail&aid=1565394&group_id=4041&atid=104041

seems that lib3ds has some problems with recent compilers. My gcc version is currently 4.0.3 and it works well.
You might need to wait a bit (so I'll do before upgrading gcc :) )

knobby67
03-28-2007, 08:54 AM
I've got the latest Etch RC2 gcc shows
gcc version 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)

maybe this is the problem :s
Damn reading the report it seems it is, about 40 hours of my life lost.

Thanks for the help:)

jide
03-28-2007, 02:14 PM
This is not lost !

Whether you wait for a bug fix in lib3ds or whether you build an old gcc version (as 4.0.x). Would advise for building your own gcc...