www.pudn.com > 林海血原源代码.zip > RLMManager.cpp


// RLMManager.cpp: implementation of the CRLMManager class. 
// 
////////////////////////////////////////////////////////////////////// 
 
#include "stdafx.h" 
#include "RLMManager.h" 
#include "texture.h" 
#include  
////////////////////////////////////////////////////////////////////// 
// Construction/Destruction 
////////////////////////////////////////////////////////////////////// 
CRLMManager::CRLMManager() 
{ 
    m_bMultitexEnable=false; 
	m_pLight=NULL; 
	m_pQuads=NULL; 
	m_pTexID=NULL; 
	m_pVertPool=NULL; 
} 
CRLMManager::~CRLMManager() 
{ 
	if(m_pLight!=NULL) 
		delete [] m_pLight; 
	if(m_pQuads!=NULL) 
		delete [] m_pQuads; 
	if(m_pTexID!=NULL) 
		delete [] m_pTexID; 
	if(m_pVertPool!=NULL) 
		delete [] m_pVertPool; 
} 
 
bool CRLMManager::ReadRLMFile() 
{ 
	FILE *fp=NULL; 
    fp=fopen("lightmap2.rlm", "rb"); 
	if(fp==NULL) 
	{ 
		MessageBox(0, "Can not open rlm file !", "Error", MB_OK | MB_ICONERROR); 
	    return false; // 
	} 
	/////////////////////// check the file 
	char id[24],version; 
	fread(id,      sizeof(char),24,fp); 
	fread(&version,sizeof(char),1 ,fp); 
	if(strncmp( id, "Radiosity Lighting Model", 24 ) != 0 ) 
	{ 
		MessageBox(0, "Not a avalid rlm file !", "Error", MB_OK | MB_ICONERROR); 
	    fclose(fp); 
	    return false; // "Not a valid .skn file." 
	} 
	if ( version !=1 ) 
	{ 
	    MessageBox(0, "Version error !", "Error", MB_OK | MB_ICONERROR); 
	    fclose(fp); 
	    return false; // "Not a valid .skn file." 
	} 
	////////////////read light info 
	fread(&m_diffuse, sizeof(unsigned char),1 ,fp); 
	fread(&m_lightnum,sizeof(int),          1 ,fp);	 
    m_pLight=new LIGHT[m_lightnum]; 
    fread(m_pLight ,sizeof(LIGHT), m_lightnum ,fp);	 
	////////////////read texture info 
	fread(&m_texnum, sizeof(int),1 ,fp); 
	m_pTexID=new unsigned int [m_texnum]; 
	char filename[64]; 
	CTexture  cTexture; 
	for(int i=0;i