Put model name on window title

This commit is contained in:
Epicalert 2021-02-07 19:03:27 +08:00
parent 4ce0e0e10d
commit 557111d5c4
No known key found for this signature in database
GPG key ID: CAA46F858D0979BD
3 changed files with 26 additions and 1 deletions

View file

@ -87,6 +87,8 @@ void initGraphics () {
model = new Model(resolvePath(("models/"+optData.model+".fma").c_str()).c_str());
glutSetWindowTitle((PROJECT_NAME " - " + model->getName()).c_str());
//enable blending for alpha textures
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

View file

@ -21,7 +21,6 @@ void textureFromArchive(zip_t* archive, const char* path, ModelPart* part, size_
}
}
Model::Model(const char* path) {
int zipError;
zip_t* archive = zip_open(path, ZIP_RDONLY, &zipError);
@ -43,6 +42,21 @@ Model::Model(const char* path) {
std::cerr << "cannot parse model.toml! " << std::endl << modelDesc.errmsg << std::endl;
}
// get name
auto modelInfo = modelDesc.table->getTable("model_info");
if (!modelInfo) {
std::cerr << "Model does not have a model_info table!" << std::endl;
} else {
auto nameResult = modelInfo->getString("name");
if (!nameResult.first) {
std::cerr << "Model does not have a name!" << std::endl;
} else {
name = nameResult.second;
}
}
auto partsDescArray = modelDesc.table->getArray("part");
auto partsVec = *partsDescArray->getTableVector();
@ -111,3 +125,8 @@ void Model::updateTransforms(struct FaceData faceData) {
parts[i].processFaceData(faceData);
}
}
std::string Model::getName() {
return name;
}

View file

@ -8,12 +8,16 @@
class Model {
std::vector<ModelPart> parts;
std::string name;
public:
Model(const char* path);
void draw();
void updateTransforms(struct FaceData faceData);
std::string getName();
};
#endif