Muszę napisać program, który będzie wyświetlał wykres słupkowy i dane będą pobierane z pliku. Obecnie wiem narysować jeden słupek i kolega wyjaśnił mi jak wczytywać dane z pliku, ale nie do końca to działa. Prosił bym o opinie o tym czy zmierzam w dobrym kierunku(a jeśli w dobrym, to co następne zrobić i jak według was wglądał by projekt.
Pod tym adresem można zobaczyć jak może wyglądać projekt:
http://www.di.ubi.pt/~fsilva/cg/Project.pdf
To mój kod:
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
#include <fstream>
#include <stdlib.h>
#include <string>
#include <iostream>
using namespace std;
void init(void)
{
glClearColor (0.0, 0.0, 0.0, 0.0);
glShadeModel (GL_FLAT);
}
void read()
{
int a;
string city;
ifstream file;
file.open("C:/dane/test.txt", ios::app | ios::in | ios::out);
if(file.good())
{
while(!file.eof())
{
file>>city>>a;
cout<<city<<a;
file.close();
}
return;
}
else
{
cout<<"Fail!";
return;
}
}
void rysuj()
{
glColor3f (1.0, 1.0, 0.0);
glutSolidCube(1.0);
glColor3f(0.0,1.0,0.0);
glutWireCube(1.0);
}
void display(void)
{
glClear (GL_COLOR_BUFFER_BIT);
//glColor3f (1.0, 1.0, 0.0);
glLoadIdentity (); /* clear the matrix */
/* viewing transformation */
glTranslatef(4.0, -6.0, -14.0);
//gluLookAt (-2.0, 3.0, 7.0, -2.0, 2.0, 2.0, 0.0, 1.0, 0.0);
glScalef (1.0, 6.0, 1.0); /* modeling transformation */
rysuj();
glFlush ();
}
void reshape (int w, int h)
{
glViewport (0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
gluPerspective(80.0, 1.0, 1.5, 18.0);
//glFrustum (-1.0, 1.0, -1.0, 1.0, 1.5, 20.0);
glMatrixMode (GL_MODELVIEW);
}
int main(int argc, char** argv)
{
read();
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize (500, 500);
glutInitWindowPosition (100, 100);
glutCreateWindow (argv[0]);
init ();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMainLoop();
return 0;
}