• 大小: 151KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-06-07
  • 语言: C/C++
  • 标签: OpenGL纹理  

资源简介

用OpenGL在VC++6.0环境下编写的纹理映射茶壶,可以学习OpenGL中纹理映射的方法,效果不错,很漂亮。

资源截图

代码片段和文件信息

#include 
#include 
#include “teapot.h“
using namespace Teapot;

void drawStoolLeg(Position xPosition yPosition z){ //draw stool‘s one leg
glTranslatef(xyz);
glScalef(2210);
glutSolidCube(0.5);
}

void drawScene(){ //Make the components together
glPushMatrix(); //to make up a scene
glScalef(16162); //but without teapot
glTranslatef(000.5);
glutSolidCube(0.5);
glPopMatrix();

glPushMatrix();
drawStoolLeg(22-2.0);
glPopMatrix();

glPushMatrix();
drawStoolLeg(-22-2.0);
glPopMatrix();

glPushMatrix();
drawStoolLeg(-2-2-2.0);
glPopMatrix();

glPushMatrix();
drawStoolLeg(2-2-2.0);
glPopMatrix();
}

void drawTeapot(Position XPosition YPosition Z){  //draw teapot
glPushMatrix();
glTranslatef(XYZ);
glRotatef(90.0100);
glutSolidTeapot(2.0);
glPopMatrix();
}

void redraw(){
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
gluLookAt(lookAt.eyeXlookAt.eyeYlookAt.eyeZ //set the camera‘s coordinate
      lookAt.refCenterXlookAt.refCenterYlookAt.refCenterZ//the reference point
  lookAt.vectorXlookAt.vectorYlookAt.vectorZ); //and the UP vector

glEnable(GL_DEPTH_TEST); //Light arguments
glEnable(GL_LIGHTING);
    GLfloat lightColor[] = {1.0 1.0 1.0 1.0}; //color of light
GLfloat lightPos[] = {1010101}; //position of light

glLightfv(GL_LIGHT0GL_POSITIONlightPos); //set light source parameters
glLightfv(GL_LIGHT0GL_AMBIENTlightColor);
glEnable(GL_LIGHT0);

glRotatef(transformArg.fRotate010); //rotate and scale of scene
glRotatef(-90.0100);
glScalef(111);
drawScene();

glTranslatef(teapot.positionYteapot.positionZ0); //set teapot‘s position
glRotatef(teapot.fRotate001); //rotate of teapot
if(teapot.bRotate)
teapot.fRotate += 0.5;
drawTeapot(003); //redraw the teapot

if(sceneState.bRotate)
transformArg.fRotate += 0.5;
if(sceneState.bWireMode)
glPolygonMode(GL_FRONT_AND_BACKGL_LINE); //Wire mode choice
else
glPolygonMode(GL_FRONT_AND_BACKGL_FILL);

glutSwapBuffers(); //Swap the frame buffers
}

void updateView(int widthint height){
glViewport(00widthheight);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0 - sceneSize.halfLength0 + sceneSize.halfLength
0 - sceneSize.halfHeight0 + sceneSize.halfHeight
0 - sceneSize.halfDepth0 + sceneSize.halfDepth); //Multiplie the current matrix by an orthographic matrix.

glMatrixMode(GL_MODELVIEW);
}

void reshape(int width int height){
if(height == 0){
height = 1;
}

wWidth = width;
wHeight = height;

updateView(wWidthwHeight);
}

void idle(){
glutPostRedisplay();
}

void keyListener(unsigned char keyint xint y){
switch(key){
case ‘ ‘:
sceneState.bRotate = !sceneState.bRotate; //space to contro

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       5202  2008-05-13 17:55  Teapot\Teapot\teapot.cpp

     文件       1590  2008-04-29 11:34  Teapot\Teapot\teapot.h

     文件       4217  2008-05-06 18:46  Teapot\Teapot\Teapot.vcproj

     文件       1413  2008-06-01 18:56  Teapot\Teapot\Teapot.vcproj.PLUTO-PC.忧郁深渊.user

     文件    1010688  2008-06-01 18:56  Teapot\Teapot.ncb

     文件        884  2008-05-06 18:43  Teapot\Teapot.sln

    ..A..H.     12800  2008-06-01 18:56  Teapot\Teapot.suo

     文件       2299  2008-05-06 18:43  Teapot\UpgradeLog.xml

     文件       3348  2008-05-06 18:43  Teapot\_UpgradeReport_Files\UpgradeReport.css

     文件      12579  2007-06-27 17:04  Teapot\_UpgradeReport_Files\UpgradeReport.xslt

     文件         69  2008-05-06 18:43  Teapot\_UpgradeReport_Files\UpgradeReport_Minus.gif

     文件         71  2008-05-06 18:43  Teapot\_UpgradeReport_Files\UpgradeReport_Plus.gif

     目录          0  2008-07-12 08:49  Teapot\Teapot\Debug

     目录          0  2008-07-12 08:49  Teapot\Teapot\Release

     目录          0  2008-07-12 08:49  Teapot\debug

     目录          0  2008-07-09 22:35  Teapot\release

     目录          0  2008-07-09 22:35  Teapot\Teapot

     目录          0  2008-07-12 08:49  Teapot\_UpgradeReport_Files

     目录          0  2008-07-09 22:35  Teapot

----------- ---------  ---------- -----  ----

              1055378                    20


评论

共有 条评论

相关资源