《实验04_纹理映射.doc》由会员分享,可在线阅读,更多相关《实验04_纹理映射.doc(10页珍藏版)》请在金锄头文库上搜索。
1、计算机图形学实验报告04北方工业大学 计算机图形学课程实验报告题 目:实验04_纹理映射学 院:计算机学院专 业:数字媒体技术指导教师:蔡兴泉学生班级:数媒13-2学生学号:13101090212学生姓名:常乐教师评定:1计算机图形学实验报告03学号:13101090212班级:数媒13-2姓名:常乐实验报告4 纹理映射一实验目的1熟悉OpenGL图形库;2掌握纹理映射实现方法。二实验环境1软件环境:操作系统:WinXp应用软件:VC6.0,OpenGL2硬件环境(查看自己的机子)CPU: Intel PIV 2.80GHz内存RAM: 1GB 显卡:NVIDIA GeForce7650,25
2、6M显存三实验内容1实现简单纹理映射。三维空间中画一个三角形,贴纹理。纹理图自己从网上下载给出源程序及效果截图。void RenderScene(void) GLTVector3 vNormal; GLTVector3 vCorners5 = 0.0f, .80f, 0.0f , / Top 0 -0.5f, 0.0f, -.50f , / Back left 1 0.5f, 0.0f, -0.50f , / Back right 2 0.5f, 0.0f, 0.5f , / Front right 3 -0.5f, 0.0f, 0.5f ; / Front left 4 / Clear th
3、e window with current clearing color glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); / Save the matrix state and do the rotations glPushMatrix(); / Move object back and do in place rotation glTranslatef(0.0f, -0.25f, -4.0f); glRotatef(xRot, 1.0f, 0.0f, 0.0f); glRotatef(yRot, 0.0f, 1.0f, 0.0f); /
4、 Draw the Pyramid glColor3f(1.0f, 1.0f, 1.0f); glBegin(GL_TRIANGLES); / Bottom section - two triangles glNormal3f(0.0f, -1.0f, 0.0f); glTexCoord2f(1.0f, 1.0f); glVertex3fv(vCorners2); glTexCoord2f(0.0f, 0.0f); glVertex3fv(vCorners4); glTexCoord2f(0.0f, 1.0f); glVertex3fv(vCorners1); glTexCoord2f(1.0
5、f, 1.0f); glVertex3fv(vCorners2); glTexCoord2f(1.0f, 0.0f); glVertex3fv(vCorners3); glTexCoord2f(0.0f, 0.0f); glVertex3fv(vCorners4); / Front Face gltGetNormalVector(vCorners0, vCorners4, vCorners3, vNormal); glNormal3fv(vNormal); glTexCoord2f(0.5f, 1.0f); glVertex3fv(vCorners0); glTexCoord2f(0.0f,
6、0.0f); glVertex3fv(vCorners4); glTexCoord2f(1.0f, 0.0f); glVertex3fv(vCorners3); / Left Face gltGetNormalVector(vCorners0, vCorners1, vCorners4, vNormal); glNormal3fv(vNormal); glTexCoord2f(0.5f, 1.0f); glVertex3fv(vCorners0); glTexCoord2f(0.0f, 0.0f); glVertex3fv(vCorners1); glTexCoord2f(1.0f, 0.0f
7、); glVertex3fv(vCorners4); / Back Face gltGetNormalVector(vCorners0, vCorners2, vCorners1, vNormal); glNormal3fv(vNormal); glTexCoord2f(0.5f, 1.0f); glVertex3fv(vCorners0); glTexCoord2f(0.0f, 0.0f); glVertex3fv(vCorners2); glTexCoord2f(1.0f, 0.0f); glVertex3fv(vCorners1); / Right Face gltGetNormalVe
8、ctor(vCorners0, vCorners3, vCorners2, vNormal); glNormal3fv(vNormal); glTexCoord2f(0.5f, 1.0f); glVertex3fv(vCorners0); glTexCoord2f(0.0f, 0.0f); glVertex3fv(vCorners3); glTexCoord2f(1.0f, 0.0f); glVertex3fv(vCorners2); glEnd(); / Restore the matrix state glPopMatrix(); / Buffer swap glutSwapBuffers
9、(); 四实验内容2实现简单纹理映射。三维空间中画一个立方体,六个面贴同一张纹理。纹理图自己从网上下载。给出源程序及效果截图。int DrawGLScene(GLvoid)/ Heres Where We Do All The DrawingglClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);/ Clear The Screen And The Depth BufferglLoadIdentity();/ Reset The ViewglTranslatef(0.0f,0.0f,z);glRotatef(xrot,1.0f,0.0f,0.0f)
10、;glRotatef(yrot,0.0f,1.0f,0.0f);GLint texture6; /glGenTextures(6,&texture0); /glBindTexture(GL_TEXTURE_2D, texturefilter);glBegin(GL_QUADS);/ Front FaceglBindTexture(GL_TEXTURE_2D, texture0);/ glNormal3f( 0.0f, 0.0f, 1.0f);glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f);glTexCoord2f(1.0f, 0
11、.0f); glVertex3f( 1.0f, -1.0f, 1.0f);glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 1.0f);glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 1.0f);/ Back FaceglNormal3f( 0.0f, 0.0f,-1.0f);glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f);glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f);glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f);glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f);/ Top FaceglNormal3f( 0.0f, 1.0f, 0.0f