opengl - C++ program freezes when trying to display a triangle with vertices read from data file -


i wrote small program reads 3 vertices of type double data file , displays them triangle (using lines). compiles, when run window freezes. tried debugging it, without success. created separate program reads same data same way without displaying graphically. worked. suppose problem in opengl commands.

could point out mistake(s)?

//to compile, use   $ g++ -lgl -lglut triangulation.cpp -o triangulation       #include <iostream>     #include <gl/glut.h>     #include <fstream>//for operation on files     using namespace std;      double triangle_vertices[3][2];      void draw_triangulation() {         glclear(gl_color_buffer_bit);         glcolor3f(0.8, 0.8, 0.0);//color of shape (red,green,blue). red+green=yellow          int i=0;             ifstream myfile ("data.txt"); //read file         if (myfile.is_open()) {             while (myfile.good()) {                 (i;i<3;i++) {                 (int j=0;j<2;j++) {                     myfile >> triangle_vertices[i][j];                 }                 }             }         cout<<"file successfuly read."<<endl;         }         myfile.close();          i=0;                 glbegin(gl_lines); //display line vertices 2&0             glvertex3f(triangle_vertices[i+2][0],triangle_vertices[i+2][1],0.0);             glvertex3f(triangle_vertices[i][0],triangle_vertices[i][1],0.0);             glend();             (i;i<2;i++) {  //display lines vertices 0&1 , 1&2             glbegin(gl_lines);             glvertex3f(triangle_vertices[i][0],triangle_vertices[i][1],0.0);             glvertex3f(triangle_vertices[i+1][0],triangle_vertices[i+1][1],0.0);             glend();         }     glflush();     }          void initialize() {         glclearcolor(0.32, 0.49, 0.46, 0.0);//(red,green,blue,alpha) initializes background color.         glmatrixmode(gl_projection);         glloadidentity();         glortho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);     }      int main(int iargc, char** cppargv) {         glutinit(&iargc, cppargv);         glutinitdisplaymode(glut_single | glut_rgb);         glutinitwindowsize(600, 600); //600*600 pixel window         glutinitwindowposition(200, 200);         glutcreatewindow("triangulation data file"); //title of window         initialize();         glutdisplayfunc(draw_triangulation);          glutmainloop();         return 0;     } 

reading file disk extremely slow operation, want in draw method (which ideally called 30+ times per second). should read vertex data before hand (in main) , store in structure can access drawtriangulation method.


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -