I have created a bezier curve tool and each time I draw a bezier curve segment I get a straight line between each mouse click. I don't understand why this is happening and was wondering if someone could take a look at my render function and see the error. I have been working on this program with some other users on this stack exchange.
void myDisplay()
{
glClear(GL_COLOR_BUFFER_BIT);
if ((pointsVector[0].x != NULL) && (pointsVector[0].y != NULL))
{
drawLine(pointsVector[points], Cursor);
}
for (int i = 1; i < points; i++)
{
// draw main line & dot
glColor3f(255, 0, 0);
drawDot(pointsVector[i - 1]);
// draw tangent lines and tangent dots
glColor3f(0, 255, 0);
drawLine(controlPoints[i + 1], reverseControlPoints[i + 1]);
glColor3f(0, 0, 255);
drawDot(controlPoints[i + 1]);
drawDot(reverseControlPoints[i + 1]);
vector<Point> finalPoints = final4Points();
vector<Point> finalPointsReverseP1 = final4PointsReverseP1();
Point p1;
if (firstSegmentDrawn == false)
{
p1.setxy(pointsVector[0].x, pointsVector[0].y);
}
else
{
p1.setxy(pointsVector[points - 1].x, pointsVector[points - 1].y);
}
if ((finalPoints[2].x != NULL) && (finalPoints[2].y != NULL))
{
if (firstSegmentDrawn == true)
{
float i;
// draw bezier curve
for (float j = 0; j <= 100; j++)
{
i = j / 100;
// The Green Lines
int xa = getPt(finalPointsReverseP1[0].x, finalPointsReverseP1[1].x, i);
int ya = getPt(finalPointsReverseP1[0].y, finalPointsReverseP1[1].y, i);
int xb = getPt(finalPointsReverseP1[1].x, finalPointsReverseP1[2].x, i);
int yb = getPt(finalPointsReverseP1[1].y, finalPointsReverseP1[2].y, i);
int xc = getPt(finalPointsReverseP1[2].x, finalPointsReverseP1[3].x, i);
int yc = getPt(finalPointsReverseP1[2].y, finalPointsReverseP1[3].y, i);
// The Blue Line
int xm = getPt(xa, xb, i);
int ym = getPt(ya, yb, i);
int xn = getPt(xb, xc, i);
int yn = getPt(yb, yc, i);
// The Black Dot
int x2 = getPt(xm, xn, i);
int y2 = getPt(ym, yn, i);
Point p2;
p2.setxy(x2, y2);
drawLine(p1, p2);
//drawDot(p1);
p1 = p2;
bezierPointsMyDisplay.push_back(p2);
}
}
else
{
float i;
// draw bezier curve
for (float j = 0; j <= 100; j++)
{
i = j / 100;
// The Green Lines
int xa = getPt(finalPoints[0].x, finalPoints[1].x, i);
int ya = getPt(finalPoints[0].y, finalPoints[1].y, i);
int xb = getPt(finalPoints[1].x, finalPoints[2].x, i);
int yb = getPt(finalPoints[1].y, finalPoints[2].y, i);
int xc = getPt(finalPoints[2].x, finalPoints[3].x, i);
int yc = getPt(finalPoints[2].y, finalPoints[3].y, i);
// The Blue Line
int xm = getPt(xa, xb, i);
int ym = getPt(ya, yb, i);
int xn = getPt(xb, xc, i);
int yn = getPt(yb, yc, i);
// The Black Dot
int x2 = getPt(xm, xn, i);
int y2 = getPt(ym, yn, i);
Point p2;
p2.setxy(x2, y2);
drawLine(p1, p2);
//drawDot(p1);
p1 = p2;
bezierPointsMyDisplay.push_back(p2);
}
}
}
}
for (int i = 1; i < bezierPointsMyDisplay.size(); i++)
{
drawLine(bezierPointsMyDisplay[i - 1], bezierPointsMyDisplay[i]);
}
glutSwapBuffers();
}
My drawLine()
function:
void drawLine(Point p1, Point p2)
{
glBegin(GL_LINE_STRIP);
glVertex2f(p1.x, p1.y);
glVertex2f(p2.x, p2.y);
glEnd();
}
drawLine()
function? (I've shown it above in the question now) I tried doing what Luser said but that didn't really do anything. Maybe I didn't implement it right...? $\endgroup$