hi,

i need to create a basic object in opengl, e.g. a house. this could be done easily enough but all the vertex coordinates and facet windings have to be read in from another file. So far i have managed to open the file and read in the vertex coordinates. I don’t have a clue how to read in the facet windings.

in data file i'm reading from looks like this

1.0
-1.0
1.0
-1.0
-1.0
1.0
........
........
 
2 3 11 1 0
4 5 7 12 6
........
........

(the 1's and -1's are the vertex coords and the line of numbers are the facet windings)

the code for the input looks like this

GLfloat vertices[12][32];
GLint facets[8][5];
 
void entr(){
 
        char filename[21];
        FILE *in_file;
        printf("\ntype name of file: ");
        gets(filename);
        in_file = fopen(filename, "r");
        if(in_file==NULL)
                {
                printf("\ncannot open file: %s \n", filename);
                return 1;
                }
          
       GLfloat num, row, col;
        GLint row1, col1;
 
 
 /*get data for vertices*/
        for (row=0; row<12; row++)
                {
                for(col=0; col<3; col++)
                        {
                        fscanf(in_file, "%f", &vertices[row][col]);
                        }
 
/*get data for facets*/
                for (row1=0; row1<8; row1++)
                        {
                        for(col1=0; col1<5; col1++)
                        {
                                fscanf(in_file, "%f", &facets[row][col]);
                        }
                }
                }
}

how do i get the second set of numbers to read in?

thanks

Member Avatar for iamthwee

So you'll be needing a file i/o tutorial for C. Perhaps one telling you how to read in a line and then tokenising it using the whitespace as a delimiter.

Consult google.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.