#include<gl/glut.h>
#include<stdio.h>
#include "stdlib.h"
void init (void)
{
glClearColor (1.0, 1.0, 1.0, 0.0); // 指定清空颜色(背景色)为白色
glMatrixMode (GL_PROJECTION); //指定投影矩阵
gluOrtho2D (0.0, 400.0, 0.0, 400.0); //指定二维坐标系中被显示的区域
}
typedef struct tEdge {
int yUpper;
float xIntersect, dxPerScan;
struct tEdge * next;
} Edge;
struct dcPt { //dcPt 实际上是一个点的结构体
int x;
int y;
};
void setPixel(GLint x, GLint y){
glBegin(GL_POINTS);
glVertex2i(x, y);
glEnd();
}
/* Inserts edge into list in order of increasing xIntersect field. */
void insertEdge (Edge * list, Edge * edge)
{
Edge * p, * q = list;
p = q->next;
while (p != NULL) {
if (edge->xIntersect < p->xIntersect)
p = NULL;
else {
q = p;
p = p->next;
}
}
edge->next = q->next;
q->next = edge;
}
/* For an index, return y-coordinate of next nonhorizontal line */
int yNext (int k, int cnt, dcPt * pts)
{
int j;