Code:
#include <windows.h> #include <gl\gl.h> #include <gl\glut.h> #include <stdlib.h> #include <math.h> #include <vector> #include <iostream.h> #include <fstream.h> #include <stdio.h> struct Point3D { float x, y, z; }; struct Triangle { char name[10]; Point3D point[3]; }; istream & operator >> (istream & in , Point3D & pt) { char c; in >> c >> pt.x >> c >> pt.y >> c >> pt.z >> c; return in; } istream & operator >> (istream & in, Triangle & tri) { in >> tri.name >> tri.point[0] >> tri.point[1] >> tri.point[2]; return in; } ostream & operator << (ostream & out , const Point3D & pt) { out << "(" << pt.x << "," << pt.y << "," << pt.z << ")"; return out; } ostream & operator << (ostream & out , const Triangle & tri) { out << tri.name << " " << tri.point[0] << " " << tri.point[1] << " " << tri.point[2]; return out; } float read () { std::vector<Triangle> v; ifstream in ("sample.txt", ios::in); if (!in) { cout << "could not open" << endl; return 1; } return 1; } void draw (const Triangle) { Triangle triangle; while (in >> triangle) { v.push_back(triangle); } glBegin(GL_TRIANGLES); for (int i = 0, i<v.size(), i++) { glVertex3f(v[i]); } glEnd; glutSwapBuffers(); return 0; } int main (int argc, char **argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB); glutInitWindowSize(640, 480); glutInitWindowPosition(10,10); glutCreateWindow("Triangle"); //init(); glMatrixMode(GL_PROJECTION); glutDisplayFunc(draw); //glutKeyboardFunc(keyboard); glutMainLoop (); return 0; }
This is ther first time I combine both graphic programming and OO. So, explaination will be helpful.
Comment