SkyBox.cpp
上传用户:hkb425
上传日期:2007-06-16
资源大小:34191k
文件大小:4k
- // SkyBox.cpp: implementation of the CSkyBox class.
- //
- //////////////////////////////////////////////////////////////////////
- #include "stdafx.h"
- #include "Texture.h"
- #include "SkyBox.h"
- //////////////////////////////////////////////////////////////////////
- // Construction/Destruction
- //////////////////////////////////////////////////////////////////////
- CSkyBox::CSkyBox()
- {
- }
- CSkyBox::~CSkyBox()
- {
- for(int i=0;i<5;i++)
- glDeleteTextures(1,&texSky[i]);
- }
- bool CSkyBox::LoadSkyTexture()
- {
- CTexture Texture;
- char filename[64];
- for(int i=0;i<5;i++)
- {
- wsprintf(filename,"sky/skyb%d.bmp",i);
- if(!Texture.MakeTextureBind(filename,&texSky[i],1,0))
- return false;
- }
- return true;
- }
- bool CSkyBox::InitSkyBox(int XLenght, int YLenght,int ZLenght,
- int CenterX,int CenterY,int CenterZ)
- {
- m_XLength=XLenght;
- m_YLength=YLenght;
- m_ZLength=ZLenght;
- m_CenterX=CenterX;
- m_CenterY=CenterY;
- m_CenterZ=CenterZ;
- if(!LoadSkyTexture())return false;
- return true;
- }
- void CSkyBox::DrawSkyBox()
- {
- int lx,ly,lz,cx,cy,cz;
- lx=m_XLength;
- ly=m_YLength;
- lz=m_ZLength;
- cx=m_CenterX;
- cy=m_CenterY;
- cz=m_CenterZ;
- float btmy=0.0f;//This variable indicate how much texture should be cut from 0 to btmy
- // glDisable(GL_FOG);
- ////////front
- glBindTexture(GL_TEXTURE_2D, texSky[0]);
- glEnable(GL_TEXTURE_2D);
- glBegin(GL_QUADS);
- glTexCoord2f(0,btmy);
- glVertex3i(-lx+cx, cy, -lz+cz);
- glTexCoord2f(1,btmy);
- glVertex3i(lx+cx, cy, -lz+cz);
- glTexCoord2f(1,1);
- glVertex3i(lx+cx, ly+cy, -lz+cz);
- glTexCoord2f(0,1);
- glVertex3i(-lx+cx, ly+cy, -lz+cz);
- glEnd();
- glDisable(GL_TEXTURE_2D);
- /// ////////////////sky1
- /////////////////right
- glBindTexture(GL_TEXTURE_2D, texSky[1]);
- glEnable(GL_TEXTURE_2D);
-
- glBegin(GL_QUADS);
- glTexCoord2f(0,btmy);
- glVertex3i(lx+cx, cy, -lz+cz);
- glTexCoord2f(1,btmy);
- glVertex3i(lx+cx, cy, lz+cz);
- glTexCoord2f(1,1);
- glVertex3i(lx+cx, ly+cy, lz+cz);
- glTexCoord2f(0,1);
- glVertex3i(lx+cx, ly+cy, -lz+cz);
- glEnd();
- glDisable(GL_TEXTURE_2D);
- /// ////////////////sky2
- //////////////back
- glBindTexture(GL_TEXTURE_2D, texSky[2]);
- glEnable(GL_TEXTURE_2D);
-
- glBegin(GL_QUADS);
- glTexCoord2f(0,btmy);
- glVertex3i(lx+cx, cy, lz+cz);
- glTexCoord2f(1,btmy);
- glVertex3i(-lx+cx, cy, lz+cz);
- glTexCoord2f(1,1);
- glVertex3i(-lx+cx, ly+cy, lz+cz);
- glTexCoord2f(0,1);
- glVertex3i(lx+cx, ly+cy, lz+cz);
- glEnd();
- glDisable(GL_TEXTURE_2D);
- /// ////////////////sky3
- ////////////////left
- glBindTexture(GL_TEXTURE_2D, texSky[3]);
- glEnable(GL_TEXTURE_2D);
- glBegin(GL_QUADS);
- glTexCoord2f(0,btmy);
- glVertex3i(-lx+cx, cy, lz+cz);
- glTexCoord2f(1,btmy);
- glVertex3i(-lx+cx, cy, -lz+cz);
- glTexCoord2f(1,1);
- glVertex3i(-lx+cx, ly+cy, -lz+cz);
- glTexCoord2f(0,1);
- glVertex3i(-lx+cx, ly+cy, lz+cz);
- glEnd();
- glDisable(GL_TEXTURE_2D);
- /// ////////////////sky4
- /////////////up
- glBindTexture(GL_TEXTURE_2D, texSky[4]);
- glEnable(GL_TEXTURE_2D);
- glBegin(GL_QUADS);
- glTexCoord2f(0,0);
- glVertex3i(-lx+cx, ly+cy, -lz+cz);
- glTexCoord2f(1,0);
- glVertex3i(lx+cx,ly+cy, -lz+cz);
- glTexCoord2f(1,1);
- glVertex3i(lx+cx, ly+cy, lz+cz);
- glTexCoord2f(0,1);
- glVertex3i(-lx+cx, ly+cy, lz+cz);
- glEnd();
- glDisable(GL_TEXTURE_2D);
- // glEnable(GL_FOG);
- }