Results 1 to 4 of 4

Thread: polygons defined in text file

  1. #1

    polygons defined in text file

    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.

  2. #2
    Member Contributor
    Join Date
    Apr 2000
    Salt Lake City, UT

    Re: polygons defined in text file

    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?


  3. #3
    Senior Member OpenGL Pro
    Join Date
    Dec 2007

    Re: polygons defined in text file

    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.

  4. #4

    Re: polygons defined in text file

    Thanks. This makes the theory much clearer and will definately get me started.

Similar Threads

  1. Replies: 1
    Last Post: 11-25-2018, 02:24 PM
  2. How To Open a text file
    By Numan Ali in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 02-28-2018, 09:17 AM
  3. loading .obj file: how to triangularize polygons ?
    By john_connor in forum OpenGL: General
    Replies: 9
    Last Post: 08-23-2016, 11:34 AM
  4. file not defined
    By in forum OpenGL: Basic Coding
    Replies: 9
    Last Post: 04-24-2004, 04:59 PM
  5. terrain text file
    By in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 11-18-2003, 08:14 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Proudly hosted by Digital Ocean