www.pudn.com > 地表贴图.zip > GeoObj.cpp


// GeoObj.cpp : implementation file 
#include "stdafx.h" 
#include "GeoObj.h" 
CGeoObj::CGeoObj() 
{ 
	 
	m_BasePnt.x=0.0;m_BasePnt.y=0.0;m_BasePnt.z=0.0; 
	m_DrawShape=OBJECT_BUILD1;	 
} 
 
CGeoObj::CGeoObj(int index) 
{ 
	 
	m_BasePnt.x=0.0;m_BasePnt.y=0.0;m_BasePnt.z=0.0; 
	m_DrawShape=index; 
	 
} 
 
CGeoObj::~CGeoObj() 
{ 
	 
} 
 
bool CGeoObj::CreateTexture(UINT texturearray[],char* FileName,int textureID) 
{ 
	AUX_RGBImageRec *pBitmap = NULL;	 
	if(!FileName)										 
		return false;	 
	pBitmap = auxDIBImageLoad(FileName);				 
	if(pBitmap == NULL)									 
		return false;	 
	glGenTextures(1, &texturearray[textureID]);		 
	glPixelStorei (GL_UNPACK_ALIGNMENT, 1); 
	glBindTexture(GL_TEXTURE_2D, texturearray[textureID]); 
	gluBuild2DMipmaps(GL_TEXTURE_2D, 3, pBitmap->sizeX, pBitmap->sizeY, GL_RGB, GL_UNSIGNED_BYTE, pBitmap->data); 
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); 
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); 
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST); 
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR_MIPMAP_LINEAR);	 
	if (pBitmap)										 
	{ 
		if (pBitmap->data)						 
		{ 
			free(pBitmap->data);				 
		}		 
		free(pBitmap);	 
	} 
	return true;		 
} 
 
/***********************************************/ 
//*************CReadDSN类实现******************/ 
/*********************************************/ 
CObject3D CReadDSN::m_ObjDsn; 
CBmpFiles**  CReadDSN::m_ppTexturelist; 
CReadDSN::CReadDSN():CGeoObj(OBJECT_READDSN) 
{ 
	m_ppTexturelist =(CBmpFiles**)malloc(sizeof(CBmpFiles)*(m_dsn.m_MaxTexs)); 
} 
CReadDSN::~CReadDSN() 
{  } 
 
void CReadDSN::InitDSN1(CString FileName) 
{ 
  m_dsn.ImportDSN(&m_ObjDsn,m_ppTexturelist,FileName); 
   
} 
 
void CReadDSN::InitDSN(CString FileName) 
{ 
  m_dsn.ImportDSN(&m_ObjDsn,m_ppTexturelist,FileName); 
  for(int i=0; ifname,i); 
} 
 
void CReadDSN::InitDSN2(char* FileName) 
{ 
  CreateTexture(m_TextureDsn,FileName,0); 
} 
 
void CReadDSN::Draw(CVertex3D pos,CDC*pDC,int mode) 
{	 
    m_dsn.DrawDSN(pDC,&m_ObjDsn,m_TextureDsn,mode); 
}