本文整理汇总了C++中MaterialManager::loadBitmap方法的典型用法代码示例。如果您正苦于以下问题:C++ MaterialManager::loadBitmap方法的具体用法?C++ MaterialManager::loadBitmap怎么用?C++ MaterialManager::loadBitmap使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MaterialManager
的用法示例。
在下文中一共展示了MaterialManager::loadBitmap方法的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);
}
}
//.........这里部分代码省略.........