Daten aus txt werden nicht angezeigt
-
Hola Amigos,
ich extrahiere Daten aus einer txt.Datei und packe sie in eine Struktur.
Dann versuche ich mit OpenGL die extrahierten Daten anzuzeigen.
Zwar seh ich im Konsolefenster, dass der Compiler die Werte richtig entnommen hat, jedoch sehe ich kein Bild im "Grafikfenster".
Es sollte erstmal zwei Dreiecke zeigen.Ich seh aber leider nur schwarz. (Im wahrsten Sinne des Wortes)Hier noch ein bissl von meinem Code:
struct C_Koordinaten { public: GLdouble m_xValue; GLdouble m_yValue; GLdouble m_zValue; }; GLdouble x; GLdouble y; GLdouble z; C_Koordinaten punkte; void field(GLdouble x,GLdouble y,GLdouble z) { glVertex3d(x,y,z); }....
int main(int argc,char** argv) { ifstream Input("Text.txt",ios::beg); std::string line; if(Input == NULL) { cout << "Datei konnte nicht geoeffnet werden" << endl; } glutInit(&argc,argv); glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB|GLUT_DEPTH); glutInitWindowSize(500,500); glutInitWindowPosition(0,0); glutCreateWindow("ZIB"); while( Input >> punkte.m_xValue >> punkte.m_yValue >> punkte.m_zValue && std::getline(Input, line)) { x=punkte.m_xValue; y=punkte.m_yValue; z=punkte.m_zValue; glutDisplayFunc(display); glBegin(GL_POINTS); //TRIANGLES LINES POINTS field(x,y,z); glEnd(); cout << "x-Wert: " <<(punkte.m_xValue)<< " "; cout << "y-Wert: " <<(punkte.m_yValue)<< " "; cout << "z-Wert: " <<(punkte.m_zValue)<< endl; } glEnable(GL_DEPTH_TEST); myinit(); glutMainLoop(); Input.close(); cin.get(); return 0; }Also ich glaube ich muss was in der while-Schleife ändern.
Wird vielleicht 1 Punkt gezeichnet und ich seh den auf meinem Minibilschirm nicht?? Kennt ihr vielleicht eine opengl-funktion mit der man die Punkte vergrößern kann??
Vielleicht könnt ihr mir helfen...
Dank euch

-
Kennt ihr vielleicht eine opengl-funktion mit der man die Punkte vergrößern kann?
Ich seh aber leider nur schwarz.
Das Zeichnen (glBegin..glEnd) solltest Du in der Funktion "display" erledigen.
Wie hast Du ModelView-/Projection-Matrix gesetzt?
-
Ist das der komplette Code? Sollte sich das Programm nicht relativ schnell wieder verabschieden (-> fehlende DisplayFunc).
-
Danke erstmal für eure Antworten..
Also ich hatte die Funktion eigentlich schon in der display-funktion aber da ging es auch nicht.
Also es kommt das gleiche ErgebnisDas ist hier nochmal der Restcode.Also alles das was oben mit .... beschrieben wurde.
Also ich hab jetzt auch nochmal die field-funktion in die Displayfunktion eingesetzt.
Wie gesagt, krieg ich aber das gleiche Ergebnis.
Wisst ihr vielleicht woran es liegen könnte?void display() { glLoadIdentity(); glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); glBegin(GL_POINTS); //TRIANGLES LINES POINTS field(x,y,z); glEnd(); glLoadIdentity(); glFlush(); } void myinit() { glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(-32.0,32.0,-32.0,32.0,-32.0,32.0); glMatrixMode(GL_MODELVIEW); glClearColor(0.0,0.0,0.0,1.0); }
-
Das hier geht bei mir (man beachte die phantastische Renderoperation ;)):
#include <iostream> #include <fstream> #include <vector> #include <windows.h> #include <GL/gl.h> #include <GL/glu.h> #include <GL/glut.h> struct vec3_t { float xyz[3]; }; std::vector< vec3_t > buffer; bool LoadData( const char* fileName, std::vector< vec3_t >& buffer ) { std::ifstream istr( fileName ); if ( !istr ) return false; vec3_t v; while ( istr.good() ) { for ( int i = 0; istr && i < 3; ++i ) istr >> v.xyz[i]; if ( !istr ) { std::cout << "Fehlende Daten..."; return false; } buffer.push_back( v ); } return true; } void display( void ) { glClear( GL_COLOR_BUFFER_BIT ); glLoadIdentity(); glTranslatef( 0.0f, 0.0f, -5.0f ); glBegin( GL_POINTS ); for ( std::vector<vec3_t>::iterator it = buffer.begin(); it != buffer.end(); ++it ) { const vec3_t& v = *it; glVertex3f( v.xyz[0], v.xyz[1], v.xyz[2] ); } glEnd(); glFlush(); } void reshape( int w, int h ) { glViewport (0, 0, (GLsizei) w, (GLsizei) h); glMatrixMode (GL_PROJECTION); glLoadIdentity (); glFrustum (-1.0, 1.0, -1.0, 1.0, 1.5, 20.0); glMatrixMode (GL_MODELVIEW); } int main( int argc, char** argv ) { if ( !LoadData( "test.txt", buffer ) ) { std::cout << "Daten konnten nicht geladen werden..."; return -1; } glutInitDisplayMode( GLUT_SINGLE | GLUT_RGB ); glutInitWindowSize( 800, 600 ); glutInitWindowPosition( 100, 100 ); glutCreateWindow( "Test" ); glutDisplayFunc(display); glutReshapeFunc(reshape); glutMainLoop(); }Inhalt von "test.txt" ist übrigens:
-1.0 -1.0 0.0 1.0 -1.0 0.0 0.0 1.0 0.0