使用openGl画直线(DDA算法)、画圆、椭圆(Bresenham算法)
#include<stdlib.h>
#include<iostream.h>
#include <GL/glut.h>
/* initialization: */
void myinit(void)
{
/* attributes */
glClearColor(1.0, 1.0, 1.0, 0.0); /* white background */
glColor3f(1.0, 0.0, 0.0); /* draw in red */
/* set up viewing: */
/* 500 x 500 window with origin lower left */
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0, 500.0, 0.0, 500.0);
glMatrixMode(GL_MODELVIEW);
}
void plot_circle_points(int xc,int yc,int x,int y)//画圆
{
glBegin(GL_POINTS);
glVertex3f(xc+x,yc+y,0);
glVertex3f(xc-x,yc+y,0);
glVertex3f(xc+x,yc-y,0);
glVertex3f(xc-x,yc-y,0);
glVertex3f(xc+y,yc+x,0);
glVertex3f(xc-y,yc+x,0);
glVertex3f(xc+y,yc-x,0);
glVertex3f(xc-y,yc-x,0);
glEnd();
}
void drawcircle(int xc,int yc,int radius)
{
int x,y,p;
x=0;
y=radius;
p=3-2*radius;
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_POINTS);