資源簡介
用的是vc軟件,在MFC框架下用opengl和c++編寫的,實現了下雪的畫面,場景不錯,感覺對初學者有幫助

代碼片段和文件信息
//////////////////////////////////////////////?
//?Double?buffered?resizeable?2D?GL?windowing?environment?using?GLUT?
//////////////////////////////////////////////?
#include??
#include??
#include??
#include??
//?
//globale?variables?
//?
const?int?milliseconds_per_frame?=?500;?
float?posX?posY;?
float?posXA[100];?
float?posYA[100];?
int?sizeA[100];?
float?angleA[100];?
int?cnt=0;?
int?size=1;?
int?angle=0;?
int?filled?=?1;?
int?animation=1;?
int?windowWidth=700;?
int?windowHeight=600;?
//?
//?Forward?declarations?
//?
void?DrawScene();?
void?DrawSnow();?
void?DrawEdge();?
void?FillEdge();?
//?
//?Initialisation?functions?
//?
static?void?DrawInit()?
{?
????//?OpenGL?one-time?initialisation?
????glClearColor(0.65F?0.65F0.9F?1.0F);?
????cnt=0;?
}?
//?
//?Callbacks?
//?
void?Timer(int?id)?
{?int?i;
for(i=0;?i{?
????angleA[i]+=(0.1+5/sizeA[i]);?
????posXA[i]+=0.25;?
????posYA[i]-=0.5;?
????if(posXA[i]>(windowWidth+50))?
????{?
?????posXA[i]-=windowWidth;?
????}?
????if(posYA[i]<-50)?
????{?
??????posYA[i]+=windowHeight;?
????}?
}?
glutPostRedisplay();?
}?
void?DisplayFunc()?
{?
????glShadeModel(GL_SMOOTH);?
????glClearColor(0.65F?0.65F0.9F?1.0F);?
????glClear(GL_COLOR_BUFFER_BIT);?
????if(animation)?
??????glutTimerFunc(milliseconds_per_frameTimer1);?
????glMatrixMode(GL_MODELVIEW);?
????glLoadIdentity();?
????DrawScene();?
????glutSwapBuffers();?
}?
void?PainSnow(int?btn?int?state?int?x?int?y)?
{?
if(btn==GLUT_LEFT_BUTTON?&&?state==GLUT_DOWN)?
{?
????size?=?rand()%3+1;?
????angle?=?rand()%3;?
????posX=x;?
????posY?=?windowHeight-y;?
????posXA[cnt]=posX;?
????posYA[cnt]=posY;?
????sizeA[cnt]=size;?
????angleA[cnt]=angle;?
????cnt++;?
}?
}?
void?KeyboardFunc(unsigned?char?key?int?x?int?y)?
{?
????switch(key)?
????{?
????????case?‘a‘?:?
????????case?‘A‘?:?
????????{?
??????????if(animation==0)?
??????????{?
????????????animation=1;?
??????????}else{?
????????????animation=0;?
??????????}?
????????}?
????????case?‘x‘?:?
????????case?(‘X‘):?
????????{?
??????????cnt=0;?
??????????DrawInit();?
??????????break;?
????????}?
????????case?‘f‘:?
????????case?‘F‘:?
????????{?
??????????if(filled==1)?
??????????{?
????????????filled=0;?
??????????}?
???????????else?
??????????{?
???????????filled=1;?
??????????}?
??????????break;?
????????}?
????????case?27:?//?escape?key?pressed?
????????{?
????????????exit(0);?
????????????break;?
????????}?
????}?
}?
void?ReshapeFunc(?int?x?int?y?)?
{?
????//?Orthographic?view?fills?the?window?
????glMatrixMode(GL_PROJECTION);?
????glLoadIdentity();?
????gluOrtho2D(?0.0?x?0.0?y?);?
????glViewport(?0?0?x?y?);?
????windowWidth=x;?
????windowHeight=y;?
}?
void?IdleFunc()?
{?
????glutPostRedisplay();?
}?
void?FillEdge()?
{?
??????glColor3f(0.70f?0.70f?1.0f);?
??????glBegin(GL_POLYGON);?
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????7441??2013-01-10?16:42??下雪\下.cpp
?????文件???????3355??2013-01-10?16:38??下雪\下.dsp
?????文件????????512??2013-01-10?16:44??下雪\下.dsw
?????文件??????50176??2013-01-10?16:44??下雪\下.ncb
?????文件??????48640??2013-01-10?16:44??下雪\下.opt
?????文件???????1164??2013-01-10?16:42??下雪\下.plg
?????文件???????4260??2012-12-06?15:10??下雪\下雪.dsp
?????文件????????533??2012-12-06?15:07??下雪\下雪.dsw
?????文件??????50176??2012-12-07?14:33??下雪\下雪.ncb
?????文件????1056256??2012-12-07?14:33??下雪\下雪.opt
?????文件???????1571??2012-12-07?14:28??下雪\下雪.plg
?????文件??????45056??2013-01-10?16:42??下雪\Debug\vc60.pdb
?????文件?????196687??2013-01-10?16:42??下雪\Debug\下.exe
?????文件??????19378??2013-01-10?16:42??下雪\Debug\下.obj
?????文件?????467968??2013-01-10?16:42??下雪\Debug\下.pdb
?????文件?????196653??2012-12-06?15:09??下雪\Debug\下雪.exe
?????文件?????369664??2012-12-07?14:28??下雪\Debug\下雪.pdb
?????目錄??????????0??2013-03-31?20:33??下雪\Debug
?????目錄??????????0??2013-03-31?20:33??下雪
-----------?---------??----------?-----??----
??????????????2519490????????????????????19
- 上一篇:哈夫曼編碼譯碼器 C語言 數據結構課設
- 下一篇:k-means多維數據聚類
評論
共有 條評論