Added a uniform die function
This commit is contained in:
parent
a0620bd760
commit
472e269b01
@ -32,8 +32,7 @@ Texture Texture::FromFile(const char *filename) {
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, tex.width, tex.height, 0, GL_RGB, GL_UNSIGNED_BYTE, data);
|
||||
glGenerateMipmap(GL_TEXTURE_2D);
|
||||
} else {
|
||||
std::cout << "Error loading texture file: " << filename << std::endl;
|
||||
exit(1);
|
||||
Util::Die("Error loading texture file: ", filename);
|
||||
}
|
||||
|
||||
stbi_image_free(data);
|
||||
|
@ -1,13 +1,11 @@
|
||||
#ifndef MATERIAL_H
|
||||
#define MATERIAL_H
|
||||
|
||||
#include <iostream>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <GL/glew.h>
|
||||
#include "stb_image.h"
|
||||
|
||||
#include "types.h"
|
||||
#include "Util.h"
|
||||
|
||||
struct Color {
|
||||
cfloat r, g, b;
|
||||
|
@ -52,16 +52,33 @@ Mesh* Mesh::FromFile(const char *filename) {
|
||||
);
|
||||
|
||||
if (!scene) {
|
||||
std::cerr << importer.GetErrorString() << std::endl;
|
||||
exit(1);
|
||||
Util::Die(importer.GetErrorString());
|
||||
}
|
||||
|
||||
aiNode *root = scene->mRootNode;
|
||||
aiMesh *mesh_to_import = scene->mMeshes[root->mMeshes[0]];
|
||||
|
||||
return Util::aiMesh2Mesh(mesh_to_import);
|
||||
return aiMesh2Mesh(mesh_to_import);
|
||||
}
|
||||
|
||||
Mesh *Mesh::aiMesh2Mesh(aiMesh *aimesh){
|
||||
Mesh *mymesh = new Mesh();
|
||||
for (int i = 0; i < aimesh->mNumVertices; i++) {
|
||||
aiVector3D aiPosition = aimesh->mVertices[i];
|
||||
aiVector3D aiUV = aimesh->mTextureCoords[0][i]; // TODO get ALL texture coords
|
||||
Vertex vertex(aiPosition.x, aiPosition.y, aiPosition.z, aiUV.x, aiUV.y);
|
||||
mymesh->vertices.push_back(vertex);
|
||||
}
|
||||
for (int i = 0; i < aimesh->mNumFaces; i++) {
|
||||
// We're importing triangulated meshes, so each face is three indices
|
||||
unsigned int *face = aimesh->mFaces[i].mIndices;
|
||||
Index index(face[0], face[1], face[2]);
|
||||
mymesh->indices.push_back(index);
|
||||
}
|
||||
return mymesh;
|
||||
}
|
||||
|
||||
|
||||
void Mesh::Draw() {
|
||||
glBindVertexArray(VAO);
|
||||
glDrawElements(GL_TRIANGLES, indices.size() * 3, GL_UNSIGNED_INT, 0);
|
||||
|
@ -2,8 +2,6 @@
|
||||
#define MESH_H
|
||||
|
||||
#include <list>
|
||||
#include <iostream>
|
||||
#include <stdlib.h>
|
||||
|
||||
// Thirdpart includes
|
||||
#include <assimp/Importer.hpp>
|
||||
@ -31,6 +29,7 @@ public:
|
||||
virtual void SetupMesh();
|
||||
private:
|
||||
Id VAO, VBO, EBO;
|
||||
static Mesh *aiMesh2Mesh(aiMesh *mesh);
|
||||
};
|
||||
|
||||
typedef std::list<Mesh*> MeshList;
|
||||
|
@ -25,8 +25,7 @@ void Lua::Initialize() {
|
||||
Error();
|
||||
}
|
||||
} else if (err == LUA_ERRFILE) {
|
||||
std::cerr << "Could not find main.lua." << std::endl;
|
||||
exit(1);
|
||||
Util::Die("Could not find main.lua.");
|
||||
} else {
|
||||
// Syntax error
|
||||
Error();
|
||||
@ -38,8 +37,7 @@ void Lua::Initialize() {
|
||||
input->keyHandlers.push_back(LuaKeyHandler);
|
||||
input->mousePositionHandlers.push_back(LuaMousePositionHandler);
|
||||
#else // LUA_SCRIPTING
|
||||
std::cerr << "Lua is selected as scripting language, but this binary was built without Lua support." << std::endl;
|
||||
exit(1);
|
||||
Util::Die("Lua is selected as scripting language, but this binary was built without Lua support.");
|
||||
#endif // LUA_SCRIPTING
|
||||
}
|
||||
|
||||
@ -60,9 +58,9 @@ void Lua::Close() {
|
||||
void Lua::Error() {
|
||||
#ifdef LUA_SCRIPTING
|
||||
const char *error = lua_tolstring(L, -1, 0);
|
||||
std::cerr << error << std::endl;
|
||||
Util::Die(error);
|
||||
#endif // LUA_SCRIPTING
|
||||
exit(1);
|
||||
Util::Die("Whut?");
|
||||
}
|
||||
|
||||
void Lua::LuaKeyHandler(Window *window, int key, int code, int action, int mods) {
|
||||
|
@ -1,10 +1,8 @@
|
||||
#ifndef LUA_H
|
||||
#define LUA_H
|
||||
|
||||
#include <iostream>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "Input.h"
|
||||
#include "Util.h"
|
||||
|
||||
#ifdef LUA_SCRIPTING
|
||||
// Lua includes
|
||||
|
@ -1,18 +1,16 @@
|
||||
#include "Util.h"
|
||||
|
||||
Mesh *Util::aiMesh2Mesh(aiMesh *aimesh){
|
||||
Mesh *mymesh = new Mesh();
|
||||
for (int i = 0; i < aimesh->mNumVertices; i++) {
|
||||
aiVector3D aiPosition = aimesh->mVertices[i];
|
||||
aiVector3D aiUV = aimesh->mTextureCoords[0][i]; // TODO get ALL texture coords
|
||||
Vertex vertex(aiPosition.x, aiPosition.y, aiPosition.z, aiUV.x, aiUV.y);
|
||||
mymesh->vertices.push_back(vertex);
|
||||
}
|
||||
for (int i = 0; i < aimesh->mNumFaces; i++) {
|
||||
// We're importing triangulated meshes, so each face is three indices
|
||||
unsigned int *face = aimesh->mFaces[i].mIndices;
|
||||
Index index(face[0], face[1], face[2]);
|
||||
mymesh->indices.push_back(index);
|
||||
}
|
||||
return mymesh;
|
||||
void Util::Die(const char * msg) {
|
||||
std::cerr << msg << std::endl;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
void Util::Die(const char * msg, const char * more) {
|
||||
std::cerr << msg << more << std::endl;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
void Util::Die(std::string msg) {
|
||||
std::cerr << msg << std::endl;
|
||||
exit(1);
|
||||
}
|
||||
|
13
core/Util.h
13
core/Util.h
@ -1,15 +1,14 @@
|
||||
#ifndef UTIL_H
|
||||
#define UTIL_H
|
||||
|
||||
// Thirdparty includes
|
||||
#include <assimp/mesh.h>
|
||||
|
||||
// Gahhhhhh mutual inclusion!
|
||||
#include "Mesh.h"
|
||||
class Mesh;
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <stdlib.h>
|
||||
|
||||
namespace Util {
|
||||
Mesh *aiMesh2Mesh(aiMesh *mesh);
|
||||
void Die(const char *msg);
|
||||
void Die(const char * msg, const char * more);
|
||||
void Die(std::string msg);
|
||||
}
|
||||
|
||||
#endif /* UTIL_H */
|
||||
|
Loading…
Reference in New Issue
Block a user