当前位置: 首页>>代码示例>>C++>>正文


C++ MaterialManager::getGLTexID方法代码示例

本文整理汇总了C++中MaterialManager::getGLTexID方法的典型用法代码示例。如果您正苦于以下问题:C++ MaterialManager::getGLTexID方法的具体用法?C++ MaterialManager::getGLTexID怎么用?C++ MaterialManager::getGLTexID使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MaterialManager的用法示例。


在下文中一共展示了MaterialManager::getGLTexID方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: v

//Loads the MD2 model
MD2Model* MD2Model::load(const char* filename) {
	Vec3f xyzMin;
	Vec3f xyzMax;



	ifstream input;
	input.open(filename, istream::binary);
	
	Con_print("****MD2LOAD:START****");

	char buffer[64];
	input.read(buffer, 4); //Should be "IPD2", if this is an MD2 file
	if (buffer[0] != 'I' || buffer[1] != 'D' ||
		buffer[2] != 'P' || buffer[3] != '2') {
		Con_print("MD2 Error: Wrong MD2 Version Found!");
		return NULL;
	}
	if (readInt(input) != 8) { //The version number
		Con_print("MD2 Error: Wrong MD2 Version Number Found!");
		return NULL;
	}
	
	int textureWidth = readInt(input);   //The width of the textures
	int textureHeight = readInt(input);  //The height of the textures
	readInt(input);                      //The number of bytes per frame
	int numTextures = readInt(input);    //The number of textures
	if (numTextures != 1) {
		Con_print("MD2 Error: No Textures Found!");
		return NULL;
	}
	int numVertices = readInt(input);    //The number of vertices
	int numTexCoords = readInt(input);   //The number of texture coordinates
	int numTriangles = readInt(input);   //The number of triangles
	readInt(input);                      //The number of OpenGL commands
	int numFrames = readInt(input);      //The number of frames
	
	//Offsets (number of bytes after the beginning of the file to the beginning
	//of where certain data appear)
	int textureOffset = readInt(input);  //The offset to the textures
	int texCoordOffset = readInt(input); //The offset to the texture coordinates
	int triangleOffset = readInt(input); //The offset to the triangles
	int frameOffset = readInt(input);    //The offset to the frames
	readInt(input);                      //The offset to the OpenGL commands
	readInt(input);                      //The offset to the end of the file
	
	MD2Model* model = new MD2Model();
	MaterialManager* matsMgr = getMaterialManager();


	//Load the texture
	input.seekg(textureOffset, ios_base::beg);
	input.read(buffer, 64);

	// FIXME
	// Hack to get the md2 models with pcx textures to load bmp version instead
	string s = buffer;
	s = s.substr(0, s.find_last_of("."));
	s = s + ".bmp";
	strcpy(buffer, s.c_str());
	// END FIXME
	////////////////////////

	if (strlen(buffer) < 5 || strcmp(buffer + strlen(buffer) - 4, ".bmp") != 0 ) {
		Con_print("MD2 Error: Couldn't parse texture name: %s", buffer);

		// Set texture not found because we can't load the texture that was set
		model->textureId = matsMgr->getGLTexID("not-found.bmp");
	}
	else	{
		if( !matsMgr->hasMaterial(buffer) )
			matsMgr->loadBitmap(buffer);

		model->textureId = matsMgr->getGLTexID(buffer);
	}
	
	//Load the texture coordinates
	input.seekg(texCoordOffset, ios_base::beg);
	model->texCoords = new MD2TexCoord[numTexCoords];
	for(int i = 0; i < numTexCoords; i++) {
		MD2TexCoord* texCoord = model->texCoords + i;
		texCoord->texCoordX = (float)readShort(input) / textureWidth;
		texCoord->texCoordY = 1 - (float)readShort(input) / textureHeight;
	}
	
	//Load the triangles
	input.seekg(triangleOffset, ios_base::beg);
	model->triangles = new MD2Triangle[numTriangles];
	model->numTriangles = numTriangles;
	for(int i = 0; i < numTriangles; i++) {
		MD2Triangle* triangle = model->triangles + i;
		for(int j = 0; j < 3; j++) {
			triangle->vertices[j] = readUShort(input);
		}
		for(int j = 0; j < 3; j++) {
			triangle->texCoords[j] = readUShort(input);
		}
	}
	
//.........这里部分代码省略.........
开发者ID:nonsensicalthinking,项目名称:rendar,代码行数:101,代码来源:md2model.cpp


注:本文中的MaterialManager::getGLTexID方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。