i have to prompt for and then read a file of integers. the first integer, n, is the number of vertices. then there are n pairs of integers to represent the 2-d coordinates of the vertices. each line to be drawn is not necessarily on a seperate line in the file.
#include <GL/glut.h>
#include <string>
#include <iostream>
#include <fstream>
using namespace std;
int point [2];
int number_in = 0;
ifstream infile;
void init( )
{
glClear (GL_COLOR_BUFFER_BIT);
}
void display ()
{
glClearColor( 0.0, 0.0, 1.0, 0.0 );
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
gluOrtho2D( -10.0, 10.0, -10.0, 10.0);
glColor3f( 1.0, 1.0, 1.0 );
glBegin (GL_LINE_STRIP);
infile >> number_in;
while (!infile.eof())
{
for (int i = 0; i < number_in; i++)
{
infile >> number_in;
point [0] = number_in;
infile >> number_in;
point [1] = number_in;
glVertex2iv (point);
}
infile >> number_in;
}
glEnd ();
}
void main (int argc, char **argv)
{
glutInit( &argc, argv );
glutInitDisplayMode( GLUT_SINGLE | GLUT_RGB );
glutInitWindowSize( 700, 500 );
glutInitWindowPosition( 0, 0 );
glutCreateWindow( “Floorplan Design” );
string open_this;
cout << "Please enter the name of the floorplan file to be opened: ";
cin >> open_this;
cout << endl;
infile.open (open_this.c_str());
if (infile.fail())
{
cout << “File failed to open. " << " Please ensure file exists and try again.”
<< endl << endl << endl;
exit (0);
}
else
{
init( );
glutDisplayFunc (display);
glutMainLoop();
}
}
[This message has been edited by strawberrylemonade (edited 02-08-2004).]