void init (void)
{
glClearColor (1.0, 1.0, 1.0, 0.0);
glMatrixMode (GL_PROJECTION);
gluOrtho2D (0.0, 200.0, 0.0, 150.0);
}
class screenPt
{
private:
GLint x, y;
public:
/* Default Constructor: initializes coordinate position to (0. 0). */
screenPt ( ) {
x = y = 0;
}
void setCoords (GLint xCoordValue, GLint yCoordValue) {
x = xCoordValue;
y = yCoordValue;
}
GLint getx ( ) const {
return x;
}
GLint gety ( ) const {
return y;
}
void incrementx ( ) {
x++;
}
void decrementy ( ) {
y--;
}
};
void setPixel (GLint xCoord, GLint yCoord)
{
glBegin (GL_POINTS);
glVertex2i (xCoord, yCoord);
glEnd ( );
}
void circleMidpoint (GLint xc, GLint yc, GLint radius)
{
screenPt circPt;
GLint p = 1 - radius;
circPt.setCoords (0, radius); // Set coords for top point of circle.
void circlePlotPoints (GLint, GLint, screenPt);
/* plot the inital point in each circle quadrant. */
circlePlotPoints (xc, yc, circPt);
/* Calculate next point and plot in each octant. */
while (circPt.getx ( ) < circPt.gety ( )) {
circPt.incrementx ( );
if (p < 0)
p += 2 * circPt.getx ( ) + 1;
else {
circPt.decrementy ( );
p += 2 * (circPt.getx ( ) - circPt.gety ( )) + 1;
}
circlePlotPoints (xc, yc, circPt);
}
}
void circlePlotPoints (GLint xc, GLint yc, screenPt circPt)
{
setPixel (xc + circPt.getx ( ), yc + circPt.gety ( ));
setPixel (xc - circPt.getx ( ), yc + circPt.gety ( ));
setPixel (xc + circPt.getx ( ), yc - circPt.gety ( ));
setPixel (xc - circPt.getx ( ), yc - circPt.gety ( ));
setPixel (xc + circPt.gety ( ), yc + circPt.getx ( ));
setPixel (xc - circPt.gety ( ), yc + circPt.getx ( ));
setPixel (xc + circPt.gety ( ), yc - circPt.getx ( ));
setPixel (xc - circPt.gety ( ), yc - circPt.getx ( ));
}
void linesegment (void)
{
glClear (GL_COLOR_BUFFER_BIT);
glColor3f (1.0, 0.0, 0.0);
void circleMidPoint (180, 80, 50);
{
}
glBegin (GL_LINES);
glVertex2i (180, 15);
glVertex2i (10, 145);
glEnd ( );
glFlush ( );
}
void main (int argc, char** argv)
{
glutInit (&argc, argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
glutInitWindowPosition (50, 100);
glutInitWindowSize (400, 300);
glutCreateWindow ("An Example OpenGL Program");
init ( );
glutDisplayFunc (linesegment);
glutMainLoop ( );