I have located your problem… look at the code below:
#include <stdlib.h>
#include <math.h>
#include <GL/glut.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <iostream.h>
#include <fstream.h>
ifstream fin;
double x=0.0, y=0.0, size=0.0;
double a[10],b[10],c[10];
int lnum=0;
int line =0;
void read_data(void)
{
lnum=0;
fin.open (“input2.txt”);
if (fin.fail())
{
cout << "Could not open file
";
exit(1);
}
while (!fin.eof())
{
fin >> x >> y >> size ;
a[lnum] = x;
b[lnum] = y;
c[lnum] = size;
lnum++;
}
if (fin.is_open())
fin.close();
return;
}
void display(void)
{
glClear (GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glColor3f (1.0, 1.0, 1.0);
glLoadIdentity (); // clear the matrix
gluLookAt (0.0, 0.0, 3, 0.0, 0.0, -2.0, 0.0, 1, 0.0);
//********************************
read_data(); // Remove this, you keep reading the data every time you call the display routine, that is why it updates when you change your text file… only need it in your keyboard routine!
//********************************
line=0;
while (line != lnum )
{
glTranslatef (-a[line], -b[line], 0);
glutSolidCube (c[line]);
glTranslatef (a[line], b[line], 0);
line++;
}
glutSwapBuffers(); //only displays after the scene is drawn, so as
// to avoid flickering
}
// a simple reshape function as seen in class
void reshape (int w, int h)
{
glViewport (0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
gluPerspective (60,1,1,10);
glMatrixMode (GL_MODELVIEW);
glLoadIdentity();
}
// handles keyboard events
void keyboard(unsigned char key, int x, int y)
{
switch (key) {
case ‘r’:
case ‘R’:
read_data();
glutPostRedisplay();
break;
case 27: /* Escape Key */
exit(0); // closes window
break;
default:
break;
}
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize (600, 400);
glutInitWindowPosition (100, 100);
glutCreateWindow(“Example”);
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutKeyboardFunc (keyboard);
glutMainLoop();
return 0;
}
[This message has been edited by nexusone (edited 11-26-2002).]