资源描述:
《vc将灰度图转化为三维图》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库。
1、将灰度图的X、Y坐标作为三维图的X、Y坐标,将灰度图中各点灰度值作为Z坐标代码:/*L6.cOpenGLFrameworkusingGLUT3.7RobFletcher2001Drawaquadandapplyvarioustransformations.*/#include#include/*For"exit"prototype*/#include/*HeaderFileForTheGLUTLibrary*//*ASCIIcodefortheesca
2、pekey.*/#defineESCAPE27GLintwindow;/*ThenumberofourGLUTwindow*/GLintXsize=400;GLintYsize=400;GLfloatxs=1.0,ys=1.0,zs=1.0;/*scale*//*Simplewindowtransformationroutine*/GLvoidTransform(GLfloatWidth,GLfloatHeight){glViewport(0,0,Width,Height);/*Settheviewport*/
3、glMatrixMode(GL_PROJECTION);/*Selecttheprojectionmatrix*/glLoadIdentity();/*ResetTheProjectionMatrix*/gluPerspective(45.0,Width/Height,0.1,100.0);/*CalculateTheAspectRatioOfTheWindow*/glMatrixMode(GL_MODELVIEW);/*Switchbacktothemodelviewmatrix*/}/*AgeneralOp
4、enGLinitializationfunction.Setsalloftheinitialparameters.*/GLvoidInitGL(GLfloatWidth,GLfloatHeight){glClearColor(0.0,0.0,0.0,0.0);/*ThisWillClearTheBackgroundColorToBlack*/glShadeModel(GL_SMOOTH);Transform(Width,Height);/*Performthetransformation*/}/*Thefunc
5、tioncalledwhenourwindowisresized*/GLvoidReSizeGLScene(GLintWidth,GLintHeight){if(Height==0)Height=1;/*Sanitychecks*/if(Width==0)Width=1;Transform(Width,Height);/*Performthetransformation*/}/*ThemaindrawingfunctionInhereweputalltheOpenGLandcallstoroutineswhic
6、hmanipulatetheOpenGLstateandenvironment.Thisisthefunctionwhichwillbecalledwhena"redisplay"isrequested.*/GLvoidDrawGLScene(){glClear(GL_COLOR_BUFFER_BIT
7、GL_DEPTH_BUFFER_BIT);/*ClearTheScreenAndTheDepthBuffer*/glPushMatrix();glLoadIdentity();glTranslatef(0.0,0
8、.0,-6.0);glScalef(xs,ys,zs);glBegin(GL_QUADS);glColor3f(1.0,1.0,0.0);glVertex3f(1.0,1.0,1.0);glColor3f(1.0,0.0,0.0);glVertex3f(-1.0,1.0,1.0);glColor3f(1.0,1.0,0.0);glVertex3f(-1.0,-1.0,1.0);glColor3f(1.0,0.0,0.0);glVertex3f(1.0,-1.0,1.0);glEnd();glPopMatrix(
9、);glFlush();}/*Thefunctioncalledwhenevera"normal"keyispressed.*/voidNormalKey(GLubytekey,GLintx,GLinty){switch(key){caseESCAPE:printf("escapepressed.exit.");glutDestroyWindow(window);/*Killour