I am a beginner in OpenGL with glut library. I have a file with two colums of data that represent x and y coordinates.
i want to read this data and draw point on the frame. the file is a text file and the data are like this 2 6
5 8
7 5
3 8
First column is x while second is y coordinate, single space between them. In my program if i use console application (C++) i can read the file but if i use glut OpenGL
it cannot read the file.
How do you try to read the file? What doesn’t work, the reading or the drawing? My glass ball is cloudy, could you please be a bit more specific and perhaps show us your code?
Reading a text file of a format that simple is a very basic operation in most programming lanugages (except maybe brainfuck and similar), so if you have a basic understanding of the fundamentals of the programming lanuage you use, reading that file is a really primitive task, no mater what fancy libraries and framework your program uses. If you don’t understand the fundamentals of the programing language you are using, it is adviseable to getting an in-depth understanding of the language at first, before learning how to use OpenGL® through that language.
int i, x, y, c = 0;
//i used 2-dim array to store points
int point[100][2];
ifstream infile;
infile.open("points3.txt");
while (infile >> i)
{
cout <<" how many times is the while lop running" <<endl;
if (c % 2 != 0) //if i is the first integer in a row
point[c / 2][0] = i; //set as x-cord.
else //else if i is the second integer in a row
point[c / 2][1] = i; //set as y-cord.
// if a row's integers are all read, then draw the point using x/y -cord.
if(point[c / 2][0]&&point[c / 2][1])
{
glBegin (GL_POINTS);
glColor3f(1.0, 0.0, 0.0);
glVertex2f (point[c / 2][0], point[c / 2][1]);
glEnd();
//cout <<i;
}
c++;
//cout <<c;
}
glFlush();
I compiled your code and wrote the point coordinates from your first post into a propperly named text file.
I got a white window with red dots in the lower left corner. This is the output for “glxinfo | grep -i opengl” on my system:
OpenGL vendor string: Intel Open Source Technology Center
OpenGL renderer string: Mesa DRI Intel(R) Sandybridge Mobile
OpenGL core profile version string: 3.1 (Core Profile) Mesa 10.1.0
OpenGL core profile shading language version string: 1.40
OpenGL core profile context flags: (none)
OpenGL core profile extensions:
OpenGL version string: 3.0 Mesa 10.1.0
OpenGL shading language version string: 1.30
OpenGL context flags: (none)
OpenGL extensions:
Are you sure the file reading works? Is the file in the working directory?
sure the file is in the working directory with project file, main, dependency file and the rest. I am using codeblock IDE in windows Xp. Now i want to try Dev C++ and see what will happen.