Thanks for your time. Here is my simple code.
…
// is it new file?
int new_file = 1;
int i = 0;
// Read input data from a file
void input(char * filename)
{
read input data and store into buffer(global array).
then set i to 0
}
// Initialization of OpenGL
void init(void)
{
glClearColor(0.0, 0.0, 0.0, 0.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glColor3f(1.0f, 1.0f, 1.0f);
gluOrtho2D((GLdouble)screenwidth*(-1.0), (GLdouble)screenwidth, (GLdouble)screenheight*(-1.0), (GLdouble)screenheight);
}
void Timer(int extra)
{
glutPostRedisplay();
glutTimerFunc(1, Timer, 0);
}
void resize(int w, int h)
{
//resize windows
}
// To Display data on screen
void myDisplay(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(0.0f, 0.5f, 0.0f);
glBegin(GL_LINE_LOOP);
glVertex2i(-500, -250);
glVertex2i(-500, 250);
glVertex2i(500, 250);
glVertex2i(500, -250);
glEnd();
...
//input("s_wave.txt");
draw(i%1000);
i++;
glutSwapBuffers();
}
// Original One
void draw(int index)
{
glBegin(GL_LINES);
for(int t = 0; t < index; t++)
{
if(new_file == 1)
{
glVertex2f(x[t], y[t]);
glVertex2f(x[t+1], y[t+1]);
}
else
{
glVertex2f(x[t], y_temp[t]);
glVertex2f(x[t+1], y_temp[t+1]);
}
}
glEnd();
//new_file = 0;
}
void main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glutInitWindowSize(screenwidth, screenheight);
glutInitWindowPosition(50, 50);
glutCreateWindow(“SEISMOGRAM PROTOTYPE”);
glutKeyboardFunc(keyboard);
init();
input("s_wave.txt");
glutDisplayFunc(myDisplay);
glutReshapeFunc(resize);
glutTimerFunc(0,Timer,0);
glutMainLoop();
}
If input function is in main, it can display data every second but there is no update. Also, it has a flag, new_file. It indicate the data is new or not. If it is old one, the code sets new_file to 0 and the values of buffer must set to 0. I guess the code displays input data and then display 0 on screen. But, I can see just ‘0’ every second.
If input is in display, I could not see any data on screen.
I know my simple code is quite bad but if you give me advice to fix, I will be really happy.
I really appreciate your time. Thanks.