资源简介
通用扫描线填充算法OpenGL glut实现

代码片段和文件信息
//通用扫描线填充算法
//袁国武改写调试。2008年4月10日
#include
#include
#include
#define NULL 0 //C++中没有NULL这个符号常量,这里用宏定义
#define WINDOW_HEIGHT 400 //定义窗口高为400
#define WINDOW_WIDTH 400 //定义窗口宽为400
struct dcPt { //dcPt实际上是一个点的结构体
int x;
int y;
};
void setPixel(GLint xGLint y) //用OpenGL函数改写setPixel
{
glBegin(GL_POINTS);
glVertex2i(x y);
glEnd();
}
//以下完全来自ppt,未做任何修改
typedef struct tEdge {
int yUpper;
float xIntersect dxPerScan;
struct tEdge * next;
} Edge;
/* 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;
if ((k+1) > (cnt-1))
j = 0;
else
j = k + 1;
while (pts[k].y == pts[j].y)
if ((j+1) > (cnt-1))
j = 0;
else
j++;
return (pts[j].y);
}
/* Store lower-y coordinate and inverse slope for each edge. Adjust and store upper-y coordinate for edges that are the lower member of a monotically increasing or decreasing pair of edges */
void makeEdgeRec
(dcPt lower dcPt upper int yComp Edge * edge Edge * edges[])
{
edge->dxPerScan =
(float) (upper.x - lower.x) / (upper.y - lower.y);
edge->xIntersect = lower.x;
if (upper.y < yComp)
edge->yUpper = upper.y - 1;
else
edge->yUpper = upper.y;
insertEdge (edges[lower.y] edge);
}
void buildEdgeList (int cnt dcPt * pts Edge * edges[])
{
Edge * edge;
dcPt v1 v2;
int i yPrev = pts[cnt - 2].y;
v1.x = pts[cnt-1].x; v1.y = pts[cnt-1].y;
for (i=0; i v2 = pts[i];
if (v1.y != v2.y) { /* nonhorizontal line */
edge = (Edge *) malloc (sizeof (Edge));
if (v1.y < v2.y) /* up-going edge */
makeEdgeRec (v1 v2 yNext (i cnt pts) edge edges);
else /* down-going edge */
makeEdgeRec (v2 v1 yPrev edge edges);
}
yPrev = v1.y;
v1 = v2;
}
}
void buildActiveList (int scan Edge * active Edge * edges[])
{
Edge * p * q;
p = edges[scan]->next;
while (p) {
q = p->next;
insertEdge (active p);
p = q;
}
}
void fillScan (int scan Edge * active)
{
Edge * p1 * p2;
int i;
p1 = active->next;
while (p1) {
p2 = p1->next;
for (i=p1->xIntersect; ixIntersect; i++)
setPixel ((int) i scan);
p1 = p2->next;
}
}
void deleteAfter (Edge * q)
{
Edge * p = q->next;
q->next = p->next;
free (p);
}
/* Delete completed edges. Update ‘xIntersect‘ field for others */
void updateActiveList (int scan Edge * active)
{
Ed
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 5591 2009-04-13 10:02 scanFill\scanFill.cpp
文件 45056 2009-04-13 10:03 scanFill\scanFill.exe
目录 0 2008-04-09 11:25 scanFill
----------- --------- ---------- ----- ----
50647 3
相关资源
- OpenGL参考手册
- The direction of synaptic plasticity mediated
- 用foobar2000听google音乐[更新一下]
- Google Earth KML文件生成工具
- google earth 高程点坐标提取软件
- Qt Creator opengl实现四元数鼠标控制轨迹
- OpenGL文档,api大全,可直接查询函数
- opengl轮廓字体源代码
- MFC读三维模型obj文件
- 利用OpenGL写毛笔字算法
- MFC中OpenGL面和体的绘制以及动画效果
- 基于OPENGL的光线跟踪源代码368758
- VC 实现三维旋转(源码)
- 自编用openGL实现3D分形树,分形山
- OpenGL球形贴图自旋程序
- OpenGL导入贴图的Texture类
- Douglas-Peucker 曲线离散化算法.rar
- 计算机图形学(openGL)代码
- 用OpenGL开发的机械臂运动仿真程序(
- OpenGL-3D坦克模拟
- Thermal stability and glass-forming ability of
- GlowtoolsA-wdf网易游戏wdf查看及解包
- LvglFontTool_V0.4.rar
- OPENGL实现世界上最小的3D游戏
- Software Engineering(10th Edition)(Globa
- VS2012OpenGL配置所需要的全部libdllh文件
- Google架构安全白皮书
- A Globally Convergent and Closed Analytical So
- Intel 845GL/G/GE/GV/865G/915G显卡驱动 v14.
- Exact Conditions of Blow-up and Global Existen
评论
共有 条评论