資源簡(jiǎn)介
opengl繪制的立體樹場(chǎng)景,能鼠標(biāo)鍵盤互動(dòng),立體美觀,技術(shù)實(shí)用

代碼片段和文件信息
//?class.cpp?:?Defines?the?entry?point?for?the?console?application.
//
#include?“stdafx.h“
#include
#include??????????????//計(jì)算旋轉(zhuǎn)角
#include??
#include
#include??
#pragma?comment(lib“OpenGL32.lib“)
#pragma?comment(lib“glu32.lib“)
#pragma?comment(lib“glaux.lib“)
GLuint?texture[4];?//?Storage?For?One?Texture?(?NEW?)
GLfloat?LightAmbient[]=?{?0.92f?0.92f?0.38f?0.0f?};
GLfloat?LightDiffuse[]=?{?0.92f?0.92f?0.38f?0.0f?};
GLfloat?LightPosition[]=?{?0.0f?0.0f?1.0f?0.0f?};/**/
?//angle繞y軸的旋轉(zhuǎn)角允許我們旋轉(zhuǎn)照相機(jī);ratio:窗口寬高比(width/height)
GLfloat?xRot;?//?繞X軸旋轉(zhuǎn)的角度
GLfloat?yRot;?//?繞Y軸旋轉(zhuǎn)的角度
//GLfloat?LightAmbient[]=?{?0.5f?0.5f?0.5f?1.0f?};
//GLfloat?LightDiffuse[]=?{?1.0f?1.0f?1.0f?1.0f?};
//GLfloat?LightPosition[]=?{?0.0f?0.0f?2.0f?1.0f?};
int?LastXPosLastYPos;?//上次鼠標(biāo)點(diǎn)擊處x、y坐標(biāo)
BOOL?IsLBDown?=?FALSE;?//鼠標(biāo)左鍵是否按下
static?float?angle=0.0ratio;????
static?float?x=0.0fy=1.75fz=5.0f;????//照相機(jī)位置
static?float?lx=0.0fly=0.0flz=-1.0f;??//一個(gè)向量用來(lái)指示我們的視線方向
static?GLint?picture_display_list;???//一個(gè)雪人的顯示列表索引/*
void?SetupRC()
?{
//?設(shè)置光源參數(shù)
????GLfloat?ambientLight[]?=?{?1.0f?1.0f?1.0f?1.0f?};//環(huán)境光
GLfloat?diffuseLight[]?=?{?0.92f?0.92f?0.38f?1.0f?};//漫反射
GLfloat?specularLight[]?=?{?1.0f?1.0f?1.0f?1.0f?};//鏡面反射
GLfloat?lightPos[]?=?{?-1000.0f?1000.0f?1000.0f?1.0f?};//齊次坐標(biāo)中的光源位置
glEnable(?GL_DEPTH_TEST?);?//?使能深度檢測(cè)
glEnable(?GL_COLOR_MATERIAL?);?//?使能材質(zhì)
glEnable(?GL_LIGHTING?);?//?使能光照
glLightfv(?GL_LIGHT0?GL_AMBIENT?ambientLight?);
glLightfv(?GL_LIGHT0?GL_DIFFUSE?diffuseLight?);
glLightfv(?GL_LIGHT0?GL_SPECULAR?specularLight?);
glLightfv(?GL_LIGHT0?GL_POSITION?lightPos?);
glEnable(?GL_LIGHT0?);?//?使能燈光?0
glColorMaterial(?GL_FRONT?GL_AMBIENT_AND_DIFFUSE?);
glMaterialfv(?GL_FRONT?GL_SPECULAR?specularLight?);
glMateriali(?GL_FRONT?GL_SHININESS?100?);//鏡面反射指數(shù)
glClearColor(?0.0f?0.0f?0.0f?1.0f?);?//?設(shè)置背景色
?}/**/
#define?BLACK?1
#define?BROWN?2
#define?BLUE?3
#define?YELLOW?4
//預(yù)定義顏色值
float?red=1.0;
float?green=0.0;
float?blue=0.0;
//響應(yīng)窗口位置、大小改變事件的回調(diào)函輸
void?processMenuEvents(int?option)
{
//option,就是傳遞過(guò)來(lái)的value的值。
???switch?(option)
???{
?????case?BLACK?:
?????????red?=?0.0;
?????????green?=?0.0;
?????????blue?=?0.0;
?????break;
?????case?BROWN?:
?????????red?=?0.55;
?????????green?=?0.55;
?????????blue?=?0.32;
?break;
?case?BLUE?:
?red?=?0.0;
?green?=?0.0;
?blue?=?1.0;
?break;
?case?YELLOW?:
?red?=?1.0;
?green?=?1.0;
?blue?=?0.0;?
?break;
???}
}
void?createGLUTMenus()
{
int?menu;
//?創(chuàng)建菜單并告訴GLUT,processMenuEvents處理菜單事件。
???menu?=?glutCreateMenu(processMenuEvents);//給菜單增加條目
???glutAddMenuEntry(“Black“BLACK);
???glutAddMenuEntry(“Blue“BLUE);
???glutAddMenuEntry(“Brown“BROWN);
???glutAddMenuEntry(“Yellow“YELLOW);
???//?把菜單和鼠標(biāo)右鍵關(guān)聯(lián)起來(lái)。
???glutAttachMenu(GLUT_RIGHT_BUTTON);
}
void?changeSize(int?w?int?h)?????????
{??????????
//?防止被0除.????????
if(h?==?0)??????
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2012-12-25?14:42??3dtree\
?????文件???????48465??2010-02-14?05:24??3dtree\042.bmp
?????文件???????74373??2010-02-14?05:26??3dtree\044?.bmp
?????文件??????393272??2011-12-29?14:44??3dtree\045.bmp
?????文件??????786486??2005-06-03?16:49??3dtree\5.bmp
?????文件???????94103??2010-02-14?05:35??3dtree\BG.bmp
?????文件???????66614??1999-09-25?20:19??3dtree\Crate.bmp
?????目錄???????????0??2012-12-25?14:42??3dtree\Debug\
?????文件????????1939??2011-12-27?10:40??3dtree\Debug\StdAfx.obj
?????文件??????245834??2011-12-29?14:45??3dtree\Debug\class.exe
?????文件??????440232??2011-12-29?14:45??3dtree\Debug\class.ilk
?????文件???????67982??2011-12-29?14:45??3dtree\Debug\class.obj
?????文件??????187200??2011-12-27?10:40??3dtree\Debug\class.pch
?????文件??????680960??2011-12-29?14:12??3dtree\Debug\class.pdb
?????文件??????156672??2011-12-29?15:55??3dtree\Debug\vc60.idb
?????文件??????233472??2011-12-29?14:12??3dtree\Debug\vc60.pdb
?????文件??????196664??1999-09-09?03:50??3dtree\FLOOR.BMP
?????文件??????196664??1999-09-27?13:13??3dtree\Ground.BMP
?????文件????????1202??2011-12-27?10:32??3dtree\ReadMe.txt
?????文件?????????292??2011-12-27?10:32??3dtree\StdAfx.cpp
?????文件?????????667??2011-12-27?10:32??3dtree\StdAfx.h
?????文件???????11185??2011-12-29?14:12??3dtree\class.cpp
?????文件????????4546??2011-12-28?16:30??3dtree\class.dsp
?????文件?????????535??2011-12-27?10:32??3dtree\class.dsw
?????文件???????58368??2011-12-29?15:59??3dtree\class.ncb
?????文件???????59904??2011-12-29?15:59??3dtree\class.opt
?????文件?????????904??2011-12-29?14:45??3dtree\class.plg
?????目錄???????????0??2012-12-25?14:42??3dtree\data\
?????文件??????393272??2011-12-29?14:44??3dtree\data\045.bmp
?????文件???????49208??2011-12-29?14:45??3dtree\data\w2.bmp
?????文件???????49208??2011-12-29?14:45??3dtree\w2.bmp
............此處省略0個(gè)文件信息
評(píng)論
共有 條評(píng)論