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