opengl绘制教室大作业源代码wp.docx
- 文档编号:1221693
- 上传时间:2023-04-30
- 格式:DOCX
- 页数:31
- 大小:35.86KB
opengl绘制教室大作业源代码wp.docx
《opengl绘制教室大作业源代码wp.docx》由会员分享,可在线阅读,更多相关《opengl绘制教室大作业源代码wp.docx(31页珍藏版)》请在冰点文库上搜索。
wp.h
#include
#include
#include
#include
#include
#include
#include
#include
//..................................定义变量区............................................................//
//.............................用于场景漫游有关变量........................................//
GLfloat xrot=0.0f; //X旋转量
GLfloat yrot=0.0f; //Y旋转量
GLfloat x=0.0f; //X平移量
GLfloat y=0.0f; //Y平移量
GLfloat z=-40.0f; //深入屏幕的距离
//.............................用于键盘操作有关变量.......................................//
BOOL light=TRUE; //光源的开/关
BOOL lp; //L键按下了么?
BOOL fp; //F键按下了么?
BOOLTurnOn=FALSE;//开灯
GLUquadricObj*qobj;
intfantheta=0;//风扇转过角度
HGLRChRC=NULL; //窗口着色描述表句柄
HDChDC=NULL; //OpenGL渲染描述表句柄
HWNDhWnd=NULL; //保存我们的窗口句柄
HINSTANCEhInstance; //保存程序的实例
bool keys[256]; //保存键盘按键的数组
bool active=TRUE; //窗口的活动标志,缺省为TRUE
bool fullscreen=TRUE; //全屏标志缺省,缺省设定成全屏模式
//.................................光照材质有关变量......................................//
GLfloatlight_Ambient[]={0.1f,0.1f,0.1f,1.0f}; //环境光参数
GLfloatlight_Diffuse[]={1.0f,1.0f,0.45f,1.0f}; //漫射光参数
GLfloatlight_position[]={0.0,29.9,0.0,1.0};//光源位置
GLfloatlight_position1[]={20.0,29.9,0.0,1.0};
GLfloatmat_ambient[]={0.05f,0.05f,0.05f,1.0f};//材质环境光参数
GLfloatmat_specular[]={0.8,1.0,1.0,1.0};//材质镜面光参数
GLfloatmat_shininess[]={5.0};
GLfloatwhite_light[]={1.0,1.0,1.0,1.0};//光
GLfloat no_mat[]={0.0f,0.0f,0.0f,1.0f}; //无材质色
GLfloat no_shininess[]={0.0f}; //无反光
GLfloat mat_diffuse[]={1.0f,1.0f,1.0f,1.0f}; //漫反射
GLfloatdiffusion[]={0.521f,0.121f,0.0547f,1.0};
//......................................纹理...........................................................//
GLuint texture[6]; //7种纹理的储存空间
//.....................................时钟有关变量...................................................//
GLfloatcx=35.0,cy=15.0,cz=-79.9,radius=5.0;
GLfloathradius=2.0,mradius=3.0,sradius=4.0;
GLfloatsangle,mangle,hangle;
GLuintsecond,miniter,hour;
chartimebuffer[9];
LRESULT CALLBACKWndProc(HWND,UINT,WPARAM,LPARAM); //WndProc的定义
wp.cpp
#include"wp.h"
//......................................创建纹理..........................................................//
AUX_RGBImageRec*LoadBMP(char*Filename) //载入位图图象
{
FILE*File=NULL; //文件句柄
if(!
Filename) //确保文件名已提供
{
returnNULL; //如果没提供,返回NULL
}
File=fopen(Filename,"r"); //尝试打开文件
if(File) //文件存在么?
{
fclose(File); //关闭句柄
returnauxDIBImageLoad(Filename); //载入位图并返回指针
}
returnNULL;
} //如果载入失败,返回NULL
intLoadGLTextures() //载入位图并转换成纹理
{
intStatus=FALSE; //状态指示器
AUX_RGBImageRec*TextureImage[6]; //创建纹理的存储空间
memset(TextureImage,0,sizeof(void*)*1); //将指针设为NULL
//载入位图,检查有无错误,如果位图没找到则退出
Status=TRUE; //将Status设为TRUE
//...............................创建第一个纹理,地板.......................................//
if(TextureImage[0]=LoadBMP("floor.bmp"))
{
glGenTextures(1,&texture[0]);//创建纹理
glBindTexture(GL_TEXTURE_2D,texture[0]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);//远处采用线性滤波
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);//近处采用MipMapped滤波
gluBuild2DMipmaps(GL_TEXTURE_2D,3,TextureImage[0]->sizeX,TextureImage[0]->sizeY,GL_RGB,GL_UNSIGNED_BYTE,TextureImage[0]->data);//绑定纹理
}
if(TextureImage[0])//纹理是否存在
{
if(TextureImage[0]->data)//纹理图像是否存在
{
free(TextureImage[0]->data);//释放纹理图像占用的内存
}
free(TextureImage[0]);//释放图像结构
}
//...............................创建第二个纹理,墙.......................................//
if(TextureImage[1]=LoadBMP("wall.bmp"))
{
glGenTextures(1,&texture[1]);//创建纹理
glBindTexture(GL_TEXTURE_2D,texture[1]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);//远处采用线性滤波
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);//近处采用MipMapped滤波
gluBuild2DMipmaps(GL_TEXTURE_2D,3,TextureImage[1]->sizeX,TextureImage[1]->sizeY,GL_RGB,GL_UNSIGNED_BYTE,TextureImage[1]->data);//绑定纹理
}
if(TextureImage[1])//纹理是否存在
{
if(TextureImage[1]->data)//纹理图像是否存在
{
free(TextureImage[1]->data);//释放纹理图像占用的内存
}
free(TextureImage[1]);//释放图像结构
}
//...............................创建第三个纹理,窗户.......................................//
if(TextureImage[2]=LoadBMP("glass.bmp"))
{
glGenTextures(1,&texture[2]);//创建纹理
glBindTexture(GL_TEXTURE_2D,texture[2]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);//远处采用线性滤波
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);//近处采用MipMapped滤波
gluBuild2DMipmaps(GL_TEXTURE_2D,3,TextureImage[2]->sizeX,TextureImage[2]->sizeY,GL_RGB,GL_UNSIGNED_BYTE,TextureImage[2]->data);//绑定纹理
}
if(TextureImage[2])//纹理是否存在
{
if(TextureImage[2]->data)//纹理图像是否存在
{
free(TextureImage[2]->data);//释放纹理图像占用的内存
}
free(TextureImage[2]);//释放图像结构
}
//...............................创建第四个纹理,门.......................................//
if(TextureImage[3]=LoadBMP("door.bmp"))
{
glGenTextures(1,&texture[3]);//创建纹理
glBindTexture(GL_TEXTURE_2D,texture[3]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);//远处采用线性滤波
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);//近处采用MipMapped滤波
gluBuild2DMipmaps(GL_TEXTURE_2D,3,TextureImage[3]->sizeX,TextureImage[3]->sizeY,GL_RGB,GL_UNSIGNED_BYTE,TextureImage[3]->data);//绑定纹理
}
if(TextureImage[3])//纹理是否存在
{
if(TextureImage[3]->data)//纹理图像是否存在
{
free(TextureImage[3]->data);//释放纹理图像占用的内存
}
free(TextureImage[3]);//释放图像结构
}
//...............................创建第五个纹理,灯.......................................//
if(TextureImage[4]=LoadBMP("lamp.bmp"))
{
Status=TRUE;
glGenTextures(1,&texture[4]);//创建纹理
glBindTexture(GL_TEXTURE_2D,texture[4]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);//远处采用线性滤波
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);//近处采用MipMapped滤波
gluBuild2DMipmaps(GL_TEXTURE_2D,3,TextureImage[4]->sizeX,TextureImage[4]->sizeY,GL_RGB,GL_UNSIGNED_BYTE,TextureImage[4]->data);//绑定纹理
}
if(TextureImage[4])//纹理是否存在
{
if(TextureImage[4]->data)//纹理图像是否存在
{
free(TextureImage[4]->data);//释放纹理图像占用的内存
}
free(TextureImage[4]);//释放图像结构
}
//...............................创建第六个纹理,黑板.......................................//
if(TextureImage[5]=LoadBMP("blackwall.bmp"))
{
glGenTextures(1,&texture[5]);//创建纹理
glBindTexture(GL_TEXTURE_2D,texture[5]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);//远处采用线性滤波
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);//近处采用MipMapped滤波
gluBuild2DMipmaps(GL_TEXTURE_2D,3,TextureImage[5]->sizeX,TextureImage[5]->sizeY,GL_RGB,GL_UNSIGNED_BYTE,TextureImage[5]->data);//绑定纹理
}
if(TextureImage[5])//纹理是否存在
{
if(TextureImage[5]->data)//纹理图像是否存在
{
free(TextureImage[5]->data);//释放纹理图像占用的内存
}
free(TextureImage[5]);//释放图像结构
}
returnStatus;
}
//...................................重置OpenGL窗口大小..............................................//
GLvoidReSizeGLScene(GLsizeiwidth,GLsizeiheight) //重置OpenGL窗口大小
{
if(height==0) //防止被零除
{
height=1; //将Height设为1
}
glViewport(0,0,width,height); //重置当前的视口
glMatrixMode(GL_PROJECTION); //选择投影矩阵
glLoadIdentity(); //重置投影矩阵
//设置视口的大小
gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,1000.0f);
glMatrixMode(GL_MODELVIEW); //选择模型观察矩阵
glLoadIdentity(); //重置模型观察矩阵
}
//.........
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- opengl 绘制 教室 作业 源代码 wp
![提示](https://static.bingdoc.com/images/bang_tan.gif)