# Thread: Midpoint Algorithm, Bresenham, Drawing a parabola

1. ## Midpoint Algorithm, Bresenham, Drawing a parabola

So I've been trying to make a source code using OpenGL that plots a parabola (y=(1/100)*x^2) with the range of x being (-50<=x<=50). However, whenever I try running the dumb script, I'd only get a blank window. Could anyone show me where I goofed up? I'm trying to plot this using the Bresenham (Midpoint) Algorithm (My professor won't allow any other methods than the Midpoint method)
Code :
```#include <gl\glut.h>
#include <stdlib.h>
#include <math.h>
#include <stdio.h>

void init(void)
{
glutInitWindowPosition(100,100);
glutInitWindowSize(640,480);
glutCreateWindow("Parabola: Midpoint Algorithm");
glClearColor(1.0,1.0,1.0,0.0);
glColor3f(0.0,0.0,0.0);
gluOrtho2D(-100.0,100.0,100.0,100.0);
glPointSize(10);
}
void setPixel(GLint xCoord, GLint yCoord)
{
glBegin(GL_POINTS);
glVertex2i(xCoord, yCoord);
glEnd();
}

void bres_para(int x0, int y0, int xEnd, int yEnd)
{
int k;
float p, xIncrement, yIncrement, x=x0,y=y0, xx, yy;

//x가 50이하일 경우를 먼저 작성한다
for (k=0;k<=50;k++)
{
xIncrement=1.0;
x+=xIncrement;
yIncrement=(2*x+1)/100;
y+=yIncrement;
p=((x+1)*(x+1))-100*(y+0.5);
xx=x+1;
yy=y+1;
if (p<=0)
{
p=p+2*x+1;
setPixel(xx,round(y));
setPixel(-(xx),round(y));
}
else
{
p=p+2*x-99;
setPixel(xx,round(yy));
setPixel(-(xx),round(yy));
}
printf("%f,%f\n",x,y);
}

//x가 50보다 클 경우를 다음으로 작성한다
}

void draw(void)
{
glClear(GL_COLOR_BUFFER_BIT);
bres_para(0,0,50,25);
glFlush();
}

int main(int argc, char**argv)
{
glutInit(&argc,argv);
init();
glutDisplayFunc(draw);
glutMainLoop();
}```

2. Originally Posted by thickmelon
Code :
`    gluOrtho2D(-100.0,100.0,100.0,100.0);`
You're missing a negative sign for the bottom parameter.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•