How load a 3d model

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 :’(

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.

I am programin in Dev C++ , and is a text file .

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.


Thanks for the help

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.