PDA

View Full Version : polygons defined in text file



12-04-2000, 10:07 AM
I am trying to understand how to write a program that will display polygons defined in an external text file. The text file will contain the vertices for GL_QUAD elements, and I'm getting stuck since this file is not defined at compile time. Does anyone have an idea of how to parse this file and generate the shapes in realtime? Thanks.

gtada
12-04-2000, 11:09 AM
Hi Guido,
You could use either a linked list to add vertices as you go, or you could do a "prepass" of the text file, count the number of vertices, dynamically allocate an array, read the file again and fill that array with that info.

Does that help?

Greg

Michael Steinberg
12-04-2000, 01:16 PM
To get the number of polys in the file do:

fseek( file, 0, SEEK_END );
int length = ftell( file );

num_polys = length / sizeof(float) / num_of_components_per_vertex / num_of_vertices_per_polygon

Obviously this will only work when the file ONLY contains quads and no header.

12-04-2000, 08:53 PM
Thanks. This makes the theory much clearer and will definately get me started.