- 6
- 0
- 约4.17千字
- 约 4页
- 2017-11-20 发布于北京
- 举报
VC将灰度图转化为三维图
将灰度图的X、Y坐标作为三维图的X、Y坐标,将灰度图中各点灰度值作为Z坐标代码:/* L6.c OpenGL Framework using GLUT 3.7 Rob Fletcher 2001 Draw a quad and apply various transformations.*/#include stdio.h#include stdlib.h /* For exit prototype */#include GL/glut.h /* Header File For The GLUT Library *//* ASCII code for the escape key. */#define ESCAPE 27GLint window; /* The number of our GLUT window */GLintXsize=400;GLintYsize=400;GLfloatxs=1.0,ys=1.0,zs=1.0; /* scale *//* Simple window transformation routine */GLvoidTransform(GLfloat Width, GLfloat Height){glViewport(0, 0, Width, Height); /* Set the viewport */glMatrixMode(GL_PROJECTION); /* Select the projection matrix */glLoadIdentity();/* Reset The Projection Matrix */gluPerspective(45.0,Width/Height,0.1,100.0); /* Calculate The Aspect Ratio Of The Window */glMatrixMode(GL_MODELVIEW); /* Switch back to the modelview matrix */}/* A general OpenGL initialization function. Sets all of the initial parameters. */GLvoidInitGL(GLfloat Width, GLfloat Height){glClearColor(0.0, 0.0, 0.0, 0.0);/* This Will Clear The Background Color To Black */glShadeModel(GL_SMOOTH);Transform( Width, Height ); /* Perform the transformation */}/* The function called when our window is resized */GLvoidReSizeGLScene(GLint Width, GLint Height){if (Height==0) Height=1; /* Sanity checks */if (Width==0) Width=1;Transform( Width, Height ); /* Perform the transformation */}/* The main drawing function In here we put all the OpenGL and calls to routines which manipulatethe OpenGL state and environment. This is the function which will be called when a redisplay is requested.*/GLvoidDrawGLScene(){glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);/* Clear The Screen And The Depth Buffer */glPushMatrix();glLoadIdentity();glTranslatef(0.0,0.0,-6.0);glScalef(xs,ys,zs);glBegin(GL_QUADS); glColor3f(1.0,1.0,0.0);
原创力文档

文档评论(0)