Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

JimmyP

Need help making a .3ds file loader

This topic is 6717 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I''m trying to make a .3ds file loader and I''ve made it to the point where I extract each object''s vertex and face information and store it.All I have to do now(for a basic loader) is call glVertex3f a couple(of thousands) of times to make the polys.I want to store the loader in a seperate .c file like load3ds.c so that I can simply compile and link it with any other app,like a library.So there''s going to be a load3DS() function that loads the file parses it and creates display lists with all the objects in the 3ds file(or one list for the whole thing).I''ve done all that but in the function that generates the diplay list I get a segmentation fault error(something like a runtime error in Linux).By commenting out various commands I have found out that the glVertex3f commands cause the problem.I also know that there''s nothing wrong with the vertex coordinates since a simple glVeretx3f(1.0f,1.0f,1.0f) command will cause the same error.Is there a problem with creating displaylists without initializing GL and GLUT first?But even if that is the case.When I tried calling the load3DS function (which is on a seperate file) after the initialization I got the same problem.Anybody has any clues as to what the problem might be? -=Jimmy=-

Share this post


Link to post
Share on other sites
Advertisement
Why you want to write a separate .c file ?
I think it''s a worth of time and it''s not a good style.

Just use an own Object data structure and fill it with the vertices, mapping, and face indeces of the .3ds file.

Here an example

    
typedef struct
{
float x,y,z;
}Vertex;

typedef struct
{
int face[3]; //face[0], face[1], face[2]
}Poly;

typedef struct
{
float u,v;
}Mapping;

typedef struct
{
int NumVertex, NumMapping, NumPoly;
Vertex *VList;
Poly *PolyList;
Mapping *MapList;
}Object;



Inside your Load3DS function you read the chunk of the file and you fill the Object variable with the data read from the file

Share this post


Link to post
Share on other sites
But how can I view the *.3ds file? When I open it using a normal text editor I see nothing but garbage!

Please give me some hints..

Blizz

Share this post


Link to post
Share on other sites
I wan''t to be able to use the loader for all my apps,where it is needed,but the seperate file isn''t the problem.I tried the following:I had the main() function do all the initializiation (glut,window,etc.) then I called a initGL() func. which calls load3DS().load3DS() parses the file,extracts the vertex and face data,stores''em to memory.Then genDisplayLists() is called which makes the lists for each object.But when a glVertex3f command is called I get segmenation fault.Why does that happen???Anyway your way looks ok as well.I''ll simply use the load3DS to fill the object structure with data and render it in my display function as usual...I''ll give it a try but since the displaylist approach won''t work why should this one?Can anyone take a look at my (Linux)code and see if he can come up with a solution?
Blizz:You can''t understand the file because it''s a binary file not text file.Go to www.wotsit.org and do a search on 3ds.You''ll come up with 3 files.Download the one with a revision number of 0.93(can''t remember the author''s).You''ll find everything you need in there including some code to extract geomerty info among other things.BE CAREFULL though there''s a mistake in the code in the readlong() function.You only need to change temp3,temp4 to temp1,temp2 or somethoing,you''ll find out.If you have any problems you can always e-mail me.

-=Jimmy=-

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Hi,

i don''t seem able to download the above mentioned 3ds file describer, would it be possible for someone to send it to me???

i''d really appreciate it!

frank

Share this post


Link to post
Share on other sites

Don''t let the glVertex3f() fool you. If you''re getting seg faults then you definately haven''t initialised something correctly. I''d suggest writing a simple test program that will just draw a simple poly using glVertex3f(). Then, when this works, adapt it to draw using a display list. From here you should have a better understanding of what is going wrong.

Also, try using a debugger so you can look at the problem in more depth. (seg faults are usually caused when an attempt is made to write to an invalid memory address - usually a pointer problem).

With regards to 3ds, take a look at:

http://lib3ds.sourceforge.net

This is a free .3ds file loader with sourcecode.

--Andy

Share this post


Link to post
Share on other sites
Thanx for the info on lib3ds...I figured about the glVertex3f.Initializing OpenGL first solved the seg fault problem concerning the glVertex command but I had other problems...Anyway I''m starting over.I just hoped that I caould create a display list without any initialization,so that I could save this code as a seperate file and just compile it with any app needing a 3ds loader.Anyway thanx again....

-=Jimmy=-

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
hi again,

i forgot to add my e-mail address to my prior post.

please send the file(s) to frank@NOSPAMmainframe.franken.de.
please remove NOSPAM!!!

thank you all very much for your help,
i really appreciate it.

btw i tried www.wotsit.org again today with no success!! :-(((

thanks again

frank

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!