سؤال

My problem is that I've stuck with creating simple objects.

I'm using Code::Blocks with freeGlut. At the beginnig I created a black rectangle, and that gose fine. Than I wanted to add curve, but curve points where in the .txt file. I've added the file to the project and then added the curve. Building gose fine but when I run project I saw that the bottom of rectangle is bind with the left side of curve.

I don't know from black line joining rectangle with curve came from.

Down below is my code:

#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
#include <stdlib.h>
#include <math.h>
#include <iostream>
#include <iomanip>
#include <fstream>

using namespace std;

void Display()
{
glClearColor( 1.0f, 1.0f, 1.0f, 1.0f );    
glClear( GL_COLOR_BUFFER_BIT );    
glColor3f( 0.0f, 0.0f, 0.0f );    
glBegin( GL_POLYGON );    
glVertex3f( -4, -150.0, 0.0 );
glVertex3f( -4, 150.0, 0.0 );
glVertex3f( 4, 150.0, 0.0 );
glVertex3f( 4, -150.0, 0.0 );

float XP,RE,IM;

ifstream plik;
plik.open("swop.txt");

ofstream pliko;
pliko.open("test.txt");

while(!plik.eof())
{
    plik >> XP >> RE >> IM;
    if(plik.good())
    {
        glPointSize( 2 );
        glBegin( GL_POINTS );
        glVertex3f(XP,100*RE,0);
        pliko << setprecision(5) << fixed;
        pliko << "    " << XP << "    " << setw(5) << RE << "    " << setw(5) << IM << "\n";
        glEnd();
        glFlush();
    }
 else break;
}
plik.close();
pliko.close();

glEnd();
glFlush();
glutSwapBuffers();
}

int main( int argc, char * argv[] )
{
glutInit( & argc, argv );   
glutInitDisplayMode( GLUT_DOUBLE | GLUT_RGB );    
glutInitWindowSize( 800, 400 );
glutCreateWindow( "Powierzchnia Swobodna" );
glutDisplayFunc( Display );
gluOrtho2D(-100,100,-150,150); 
glutMainLoop();
return 0;
}

When I cut the curve from void Display() it only shows the polygon, when I paste the curve the line appears:

image

What to do in this case?

هل كانت مفيدة؟

المحلول

Move the second glEnd to a point before you start rendering the curve, in order to finish the polygon.
After the last glVertex call is common.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top