View Full Version : How load a 3d model

03-17-2004, 07:38 PM
I need help to load a 3d model

the file format is:

x y z

0 0 0
0 1 0 -> a rectangle
1 1 0
1 0 0

0 x x
0 x -> another rectangle


0 0 0
0 ... -> n rectangles

please can me help :'(

03-18-2004, 05:06 AM
It'd help if you told us what language you're working in, and whether the file you're trying to load is binary or text.

03-19-2004, 06:35 AM
I am programin in Dev C++ , and is a text file .

03-19-2004, 06:56 AM
assuming you know how to parse a text file:

you'll probably need to scan the text file a total of 2 times.

The first time counting the number of rectangles you have. keep a running sum of those.
after the first pass you'll need to allocate an array of 3D point structures of size num_rectangles*4 (4 vertices to each rectangle). after that you need to scan the file again reading in the vertices into your vertex array.

now you have all your vertices in a vertex array.

look up using vertex arrays and pass this to a glDrawArrays function to draw your 3D model.


03-19-2004, 06:46 PM
Thanks for the help http://www.opengl.org/discussion_boards/ubb/biggrin.gif

03-22-2004, 06:51 PM
You may not scan file, but check it's size. If every rectangle is written with same number of bytes, it would be easy to count number of rectangles.

The other way to load this file is loading rectangles to a stack (with counting them). Then you will not need to load bytes from file twice.