資源簡介
基于AEL(活化邊表)的掃描線填充算法的OpenGL實現。該算法包含一個基于GLUT的事件捕獲框架用于繪制多邊形。

代碼片段和文件信息
#include?
#include?
#ifdef?__APPLE__
#include?
#else
#include?
#endif
#include?
int?windowHeight;
int?windowWidth;
void?init(void)
{
??? glClearColor?(0000);
}
//points
short?idx?=?-1;
struct?Point{
????int?x;
????int?y;
}vertexes[65536];
int?lowLine?=?windowHeight?highLine?=?0;
//AEL
struct?ET{
????float?x;
????float?dX;
????float?dY;
????struct?ET?*next;
};
//mouse?event
int?countVertex;
void?mouse(int?button?int?state?int?x?int?y){
if(button?==?GLUT_LEFT_BUTTON?&&?state?==?GLUT_DOWN){
????if(idx?==?-1){
????????idx?=?1;
????????countVertex?=?0;
????????int?i;
????????for(i?=?0;?i?65536;?i++){
????????????vertexes[i].x?=?-1;
????????????vertexes[i].y?=?-1;
????????}
????}else{
????????????glClear?(GL_COLOR_BUFFER_BIT);
????????glBegin(GL_LINE_LOOP);
????????????glColor3f(0.5?0.5?0.5);
????????????glPolygonMode(GL_FRONTGL_FILL);
????????????//start?draw
????????????int?i;
????????????for(i?=?0;?i?????????????????glVertex2i(vertexes[i].x?vertexes[i].y);
????????????}
????????????glVertex2i(x?windowHeight-y);
????????????glEnd();
????????????glFlush();
????}
????vertexes[countVertex].x?=?x;
????vertexes[countVertex].y?=?windowHeight?-?y;
????if(windowHeight?-?y?>?highLine)?highLine?=?windowHeight?-?y;
????if(windowHeight?-?y? ????printf(“x?=?%d?y?=?%d\n“?vertexes[countVertex].x?vertexes[countVertex].y);
????countVertex++;
????printf(“countVertex?=?%d\n“?countVertex);
int?cxcy;
?? GLubyte?*?image1?=?(GLubyte?*)?malloc(sizeof(GLubyte)?*3);
cx?=?x;?cy?=?windowHeight-y;
//?read?infomation?stroed?in?the?front-buffer
glReadPixels(cxcy11GL_RGBGL_UNSIGNED_BYTEimage1);
printf(“image1=%d?image2=%dimage3=%d\n“?image1[0]image1[1]image1[2]);
printf(“Lower?boundry:?%d\nTop?boundry:?%d\n“?lowLine?highLine);
}
if(button?==?GLUT_RIGHT_BUTTON?&&?state?==?GLUT_DOWN){
????//glClear?(GL_COLOR_BUFFER_BIT);
????glBegin(GL_LINE_LOOP);
????//glBegin(GL_POLYGON);
????????glColor3f?(0.5?0.5?0.8);
????????glPolygonMode(GL_FRONTGL_FILL);
????????//start?draw
????????int?i;
????????for(i?=?0;?i?????????????glVertex2i(vertexes[i].x?vertexes[i].y);
????????}
????????//glVertex2i(x?y);
????glEnd();
????glFlush();
????????//start?fill
????????//initialize?ET?array?to?be?empty
????????struct?ET?*etArray?=?(struct?ET?*)malloc(windowHeight?*?sizeof(struct?ET));
????????for(i?=?0;?i?????????????etArray[i].x?=?0;
????????????etArray[i].dX?=?0;
????????????etArray[i].dY?=?0;
????????????etArray[i].next?=?NULL;
//etArray[i].next?=?0;
????????}
????????//construct?SET
????????printf(“Now?construct?SET:\n“);
????????for(i?=?0;?i?????????????int?flag;
????????????for(flag?=?-1;?flag?<=?1;?flag?=?flag?+?2){//detect?neighbou
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件?????469916??2011-12-12?23:28??ScanLineAlgorithm.odt
?????文件?????249638??2011-12-12?20:41??ScanLineFillAlgorithm_page1.png
?????文件?????206039??2011-12-12?20:40??ScanLineFillAlgorithm_page2.png
?????文件????1119232??2011-12-13?11:15??090834101葉輕舟_cg_ex4.doc
?????文件??????22533??2011-12-13?08:27??Scanline_Polygon_Fill\bin\Debug\Scanline_Polygon_Fill
?????文件???????4082??2011-12-13?08:42??Scanline_Polygon_Fill\Debug\BuildLog.htm
?????文件????????764??2011-12-13?08:54??Scanline_Polygon_Fill\Debug\cl.command.1.tlog
?????文件???????2312??2011-12-13?08:54??Scanline_Polygon_Fill\Debug\CL.read.1.tlog
?????文件????????298??2011-12-13?08:54??Scanline_Polygon_Fill\Debug\CL.write.1.tlog
?????文件?????176219??2011-12-14?14:45??Scanline_Polygon_Fill\Debug\main.exe
?????文件???????2048??2011-12-13?08:42??Scanline_Polygon_Fill\Debug\main.exe.em
?????文件?????237584??2011-12-14?14:45??Scanline_Polygon_Fill\Debug\main.ilk
?????文件?????????87??2011-12-13?08:54??Scanline_Polygon_Fill\Debug\main.lastbuildstate
?????文件???????1092??2011-12-13?08:54??Scanline_Polygon_Fill\Debug\main.log
?????文件??????17587??2011-12-14?14:45??Scanline_Polygon_Fill\Debug\main.obj
?????文件?????344544??2011-12-14?14:44??Scanline_Polygon_Fill\Debug\main.pch
?????文件?????443392??2011-12-14?14:45??Scanline_Polygon_Fill\Debug\main.pdb
?????文件??????????0??2011-12-13?08:54??Scanline_Polygon_Fill\Debug\main.unsuccessfulbuild
?????文件??????27648??2011-12-13?08:54??Scanline_Polygon_Fill\Debug\vc100.idb
?????文件??????45056??2011-12-13?08:54??Scanline_Polygon_Fill\Debug\vc100.pdb
?????文件??????41984??2011-12-14?14:45??Scanline_Polygon_Fill\Debug\vc60.idb
?????文件??????53248??2011-12-14?14:45??Scanline_Polygon_Fill\Debug\vc60.pdb
?????文件??????19456??2011-12-13?08:42??Scanline_Polygon_Fill\Debug\vc80.idb
?????文件??????36864??2011-12-13?08:42??Scanline_Polygon_Fill\Debug\vc80.pdb
?????文件???????8527??2011-12-14?14:45??Scanline_Polygon_Fill\main.cpp
?????文件???????3377??2011-12-13?08:32??Scanline_Polygon_Fill\main.dsp
?????文件????????531??2011-12-13?08:41??Scanline_Polygon_Fill\main.dsw
?????文件??????41984??2011-12-14?14:45??Scanline_Polygon_Fill\main.ncb
?????文件??????53760??2011-12-14?14:45??Scanline_Polygon_Fill\main.opt
?????文件???????1155??2011-12-14?14:45??Scanline_Polygon_Fill\main.plg
............此處省略22個文件信息
評論
共有 條評論