Reorganising the game engine structure. Getting things ready for real development of the engine
This commit is contained in:
		@ -1,4 +1,4 @@
 | 
			
		||||
#include <MyGraphicsEngine/Buffer.h>
 | 
			
		||||
#include "include/MyGraphicsEngine/Buffer.h"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
int Buffer::getBufferID() {
 | 
			
		||||
 | 
			
		||||
@ -1,4 +1,4 @@
 | 
			
		||||
#include <MyGraphicsEngine/Camera.h>
 | 
			
		||||
#include "include/MyGraphicsEngine/Camera.h"
 | 
			
		||||
 | 
			
		||||
Camera::Camera(glm::vec3 position, glm::vec3 rotation, float zoom)
 | 
			
		||||
: Position(position), Rotation(rotation), Zoom(zoom) {
 | 
			
		||||
 | 
			
		||||
@ -3,27 +3,27 @@
 | 
			
		||||
 | 
			
		||||
void ModelImporter::ImportFBX(std::string path)
 | 
			
		||||
{
 | 
			
		||||
    spdlog::warn("ImportFBX not implemented!");
 | 
			
		||||
    //spdlog::warn("ImportFBX not implemented!");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ModelImporter::ImportBlend(std::string path)
 | 
			
		||||
{
 | 
			
		||||
    spdlog::warn("ImportBlend not implemented!");
 | 
			
		||||
    //spdlog::warn("ImportBlend not implemented!");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ModelImporter::ImportGLTF(std::string path)
 | 
			
		||||
{
 | 
			
		||||
    spdlog::warn("ImportGLTF not implemented!");
 | 
			
		||||
    //spdlog::warn("ImportGLTF not implemented!");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ModelImporter::ImportOBJ(std::string path)
 | 
			
		||||
{
 | 
			
		||||
    spdlog::warn("ImportOBJ not implemented!");
 | 
			
		||||
    //spdlog::warn("ImportOBJ not implemented!");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ModelImporter::Import(std::string path)
 | 
			
		||||
{
 | 
			
		||||
    spdlog::warn("Import not implemented!");
 | 
			
		||||
    //spdlog::warn("Import not implemented!");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
std::vector<BarinkEngine::Mesh> ModelImporter::Test() {
 | 
			
		||||
@ -51,7 +51,7 @@ std::vector<BarinkEngine::Mesh> ModelImporter::Test() {
 | 
			
		||||
    */
 | 
			
		||||
    
 | 
			
		||||
   
 | 
			
		||||
    spdlog::info("======= Assimp ======");
 | 
			
		||||
    //spdlog::info("======= Assimp ======");
 | 
			
		||||
 | 
			
		||||
    Assimp::Importer importer;
 | 
			
		||||
    const aiScene* scene = importer.ReadFile("build/SandboxApplication/Debug/Cube.obj", aiProcess_Triangulate | aiProcess_FlipUVs);
 | 
			
		||||
@ -94,7 +94,7 @@ BarinkEngine::Mesh ModelImporter::processMesh(aiMesh* mesh, const aiScene* scene
 | 
			
		||||
        vertices.push_back(vector);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    spdlog::info("{} == {}", mesh->mNumVertices, vertices.size());
 | 
			
		||||
    //spdlog::info("{} == {}", mesh->mNumVertices, vertices.size());
 | 
			
		||||
 | 
			
		||||
    // Process Indices
 | 
			
		||||
    for (unsigned int i = 0; i < mesh->mNumFaces; i++) {
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										51
									
								
								MyGraphicsEngine/Renderable.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										51
									
								
								MyGraphicsEngine/Renderable.cpp
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,51 @@
 | 
			
		||||
#include "include/MyGraphicsEngine/Renderable.h"
 | 
			
		||||
#include "include/AssetManager/ModelImporter.h"
 | 
			
		||||
 | 
			
		||||
Renderable Renderable::Load()
 | 
			
		||||
{
 | 
			
		||||
    return Renderable();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
Renderable::Renderable()
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
    meshes = ModelImporter::Test();
 | 
			
		||||
 | 
			
		||||
    transform.Scale = glm::vec3(1.0f);
 | 
			
		||||
    transform.Rotation = glm::vec3(0.0f, 90.0f, 0.0f);
 | 
			
		||||
    transform.Position = glm::vec3(0.0f, 0.0f, -10.0f);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    VAO.Create();
 | 
			
		||||
    VAO.Bind();
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    vertexBuffer.createBuffer();
 | 
			
		||||
    vertexBuffer.Bind(false);
 | 
			
		||||
    vertexBuffer.setBufferData(&meshes[0].vertices[0], meshes[0].vertices.size() * sizeof(glm::vec3), false);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    elementBuffer.createBuffer();
 | 
			
		||||
    elementBuffer.Bind(true);
 | 
			
		||||
    elementBuffer.setBufferData(&meshes[0].elements[0], meshes[0].elements.size() * sizeof(unsigned int), true);
 | 
			
		||||
 | 
			
		||||
    VAO.AttachAttribute(0, 3, 0);
 | 
			
		||||
 | 
			
		||||
    vertexBuffer.Unbind(false);
 | 
			
		||||
    VAO.Unbind();
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
Renderable::~Renderable()
 | 
			
		||||
{
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Renderable::Draw()
 | 
			
		||||
{
 | 
			
		||||
    VAO.Bind();
 | 
			
		||||
    elementBuffer.Bind(true);
 | 
			
		||||
    glDrawElements(GL_TRIANGLES, static_cast<unsigned int>(meshes[0].elements.size()), GL_UNSIGNED_INT, NULL);
 | 
			
		||||
    VAO.Unbind();
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@ -1,4 +1,4 @@
 | 
			
		||||
#include "MyGraphicsEngine/Shader.h"
 | 
			
		||||
#include "include/MyGraphicsEngine/Shader.h"
 | 
			
		||||
 | 
			
		||||
Shader::Shader(const std::string vertexShaderPath, const std::string fragmentShaderPath)
 | 
			
		||||
{
 | 
			
		||||
@ -6,7 +6,7 @@ Shader::Shader(const std::string vertexShaderPath, const std::string fragmentSha
 | 
			
		||||
    int succes;
 | 
			
		||||
    
 | 
			
		||||
    char* vertexCode = readFile(vertexShaderPath.c_str());
 | 
			
		||||
    spdlog::info(vertexCode);
 | 
			
		||||
    //spdlog::info(vertexCode);
 | 
			
		||||
    unsigned int vertId = glCreateShader(GL_VERTEX_SHADER);
 | 
			
		||||
    
 | 
			
		||||
    glShaderSource(vertId, 1, &vertexCode, NULL);
 | 
			
		||||
@ -15,13 +15,13 @@ Shader::Shader(const std::string vertexShaderPath, const std::string fragmentSha
 | 
			
		||||
    glGetShaderiv(vertId, GL_COMPILE_STATUS, &succes);
 | 
			
		||||
    if(!succes){
 | 
			
		||||
        glGetShaderInfoLog(vertId, 512, NULL, infoLog);
 | 
			
		||||
        spdlog::error( "Vertex shader has compile error {}", infoLog);
 | 
			
		||||
        //spdlog::error( "Vertex shader has compile error {}", infoLog);
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    char* fragmentCode = readFile(fragmentShaderPath.c_str());
 | 
			
		||||
    spdlog::info(fragmentCode); 
 | 
			
		||||
    //spdlog::info(fragmentCode); 
 | 
			
		||||
    unsigned int fragId = glCreateShader(GL_FRAGMENT_SHADER);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -33,7 +33,7 @@ Shader::Shader(const std::string vertexShaderPath, const std::string fragmentSha
 | 
			
		||||
    glGetShaderiv(fragId, GL_COMPILE_STATUS, &succes);
 | 
			
		||||
    if(!succes){
 | 
			
		||||
        glGetShaderInfoLog(fragId, 512, NULL, infoLog);
 | 
			
		||||
        spdlog::error("Fragment shader has compile error {}", infoLog);
 | 
			
		||||
        //spdlog::error("Fragment shader has compile error {}", infoLog);
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -63,7 +63,7 @@ char* Shader::readFile (const char* filePath){
 | 
			
		||||
    file.open(filePath);
 | 
			
		||||
 | 
			
		||||
    if(file.is_open() == false){
 | 
			
		||||
        spdlog::info("File not found.");
 | 
			
		||||
        //spdlog::info("File not found.");
 | 
			
		||||
         return nullptr;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -74,7 +74,7 @@ char* Shader::readFile (const char* filePath){
 | 
			
		||||
 | 
			
		||||
    // Undo previous seek.
 | 
			
		||||
    file.seekg(0, std::ios::beg);
 | 
			
		||||
    spdlog::info("filesize: {}", filesize);
 | 
			
		||||
    //spdlog::info("filesize: {}", filesize);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    // Create a big enough buffer for the file
 | 
			
		||||
 | 
			
		||||
@ -1,4 +1,4 @@
 | 
			
		||||
#include <MyGraphicsEngine/VertexArray.h>
 | 
			
		||||
#include "include/MyGraphicsEngine/VertexArray.h"
 | 
			
		||||
#include <glad/glad.h>
 | 
			
		||||
 | 
			
		||||
void VertexArray::Create(){
 | 
			
		||||
 | 
			
		||||
@ -4,11 +4,10 @@
 | 
			
		||||
#define STB_IMAGE_WRITE_IMPLEMENTATION
 | 
			
		||||
#define TINYGLTF_NO_EXTERNAL_IMAGE
 | 
			
		||||
 | 
			
		||||
#include <MyGraphicsEngine/Mesh.h>
 | 
			
		||||
#include "../MyGraphicsEngine/Mesh.h"
 | 
			
		||||
#include <assimp/Importer.hpp>
 | 
			
		||||
#include <assimp/scene.h>
 | 
			
		||||
#include <assimp/postprocess.h> 
 | 
			
		||||
#include <spdlog/spdlog.h>
 | 
			
		||||
#include <string>
 | 
			
		||||
 | 
			
		||||
class ModelImporter {
 | 
			
		||||
 | 
			
		||||
@ -1,6 +1,7 @@
 | 
			
		||||
#pragma once
 | 
			
		||||
#include <vector>
 | 
			
		||||
#include <glm/glm.hpp>
 | 
			
		||||
 | 
			
		||||
namespace BarinkEngine{
 | 
			
		||||
 | 
			
		||||
	class Mesh {
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										30
									
								
								MyGraphicsEngine/include/MyGraphicsEngine/Renderable.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										30
									
								
								MyGraphicsEngine/include/MyGraphicsEngine/Renderable.h
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,30 @@
 | 
			
		||||
#pragma once
 | 
			
		||||
#include <vector>
 | 
			
		||||
#include "Mesh.h"
 | 
			
		||||
#include "Transform.h"
 | 
			
		||||
#include "Buffer.h"
 | 
			
		||||
#include "VertexArray.h"
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
#include <MyGraphicsEngine/AssetManager/ModelImporter.h>
 | 
			
		||||
#include <MyGraphicsEngine/MyGraphicsEngine/Buffer.h>
 | 
			
		||||
#include <MyGraphicsEngine/MyGraphicsEngine/VertexArray.h>
 | 
			
		||||
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
class Renderable {
 | 
			
		||||
private:
 | 
			
		||||
	std::vector<BarinkEngine::Mesh> meshes;
 | 
			
		||||
	Renderable();
 | 
			
		||||
	
 | 
			
		||||
public:
 | 
			
		||||
	Buffer vertexBuffer;
 | 
			
		||||
	Buffer elementBuffer;
 | 
			
		||||
	VertexArray VAO;
 | 
			
		||||
	Transform transform;
 | 
			
		||||
	~Renderable();
 | 
			
		||||
 | 
			
		||||
	static Renderable Load();
 | 
			
		||||
	void Draw();
 | 
			
		||||
 | 
			
		||||
};
 | 
			
		||||
@ -1,9 +1,9 @@
 | 
			
		||||
#pragma once
 | 
			
		||||
 | 
			
		||||
#include <glad/glad.h>
 | 
			
		||||
#include <string>
 | 
			
		||||
#include <iostream>
 | 
			
		||||
#include <fstream>
 | 
			
		||||
#include <spdlog/spdlog.h>
 | 
			
		||||
#include <glm/glm.hpp>
 | 
			
		||||
#include <glm/gtc/type_ptr.hpp>
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -1,9 +1,13 @@
 | 
			
		||||
#pragma once 
 | 
			
		||||
#include <glad/glad.h>
 | 
			
		||||
#define GLFW_STATIC
 | 
			
		||||
 | 
			
		||||
#include <glad/glad.h>
 | 
			
		||||
#include <GLFW/glfw3.h>
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class BarinkWindow{
 | 
			
		||||
    private:
 | 
			
		||||
        GLFWwindow* window;
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										49
									
								
								MyGraphicsEngine/premake5.lua
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										49
									
								
								MyGraphicsEngine/premake5.lua
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,49 @@
 | 
			
		||||
 | 
			
		||||
	project "MyGraphicsEngine"
 | 
			
		||||
  kind "StaticLib"
 | 
			
		||||
 | 
			
		||||
  buildmessage "Building MyGraphicsEngine ..."
 | 
			
		||||
  
 | 
			
		||||
  includedirs {
 | 
			
		||||
    "../libs/assimp/include",
 | 
			
		||||
    "../libs/glad/include",
 | 
			
		||||
    "../libs/glfw/include",
 | 
			
		||||
    "../libs/tinygltf",
 | 
			
		||||
    "../libs/glew/include",
 | 
			
		||||
    "../libs/glm",
 | 
			
		||||
    "../libs/ImGui",
 | 
			
		||||
    
 | 
			
		||||
    }
 | 
			
		||||
  
 | 
			
		||||
  
 | 
			
		||||
  libdirs{
 | 
			
		||||
    "../libs/assimp/lib/Debug",
 | 
			
		||||
    "../libs/glfw/build/src/Debug",
 | 
			
		||||
    "../libs/ImGui"
 | 
			
		||||
  }	
 | 
			
		||||
 | 
			
		||||
  links {
 | 
			
		||||
    "assimp-vc143-mtd",
 | 
			
		||||
    "glfw3",
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  files {
 | 
			
		||||
    "../libs/ImGui/*.cpp",
 | 
			
		||||
    "../libs/ImGui/backends/imgui_impl_glfw.cpp",
 | 
			
		||||
    "../libs/ImGui/backends/imgui_impl_Opengl3.cpp",
 | 
			
		||||
    "../libs/glad/src/glad.c",
 | 
			
		||||
    "./*.cpp",
 | 
			
		||||
    "./*.h",
 | 
			
		||||
    "./**/*.cpp",
 | 
			
		||||
    "./**/*.shader",
 | 
			
		||||
    "./**/*.h"
 | 
			
		||||
  
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  
 | 
			
		||||
  -- NOTE: make these copy instructions more flexible
 | 
			
		||||
  ok, err = os.copyfile("shaders/fragment.shader", "../build/SandboxApplication/Debug/test.fs")
 | 
			
		||||
  if err then error("Copy fragment shader source failed!") end
 | 
			
		||||
 | 
			
		||||
  ok, err = os.copyfile("shaders/vertex.shader", "../build/SandboxApplication/Debug/test.vs")
 | 
			
		||||
  if err then error("Copy vertex shader source failed!") end
 | 
			
		||||
@ -1,11 +1,12 @@
 | 
			
		||||
#include "MyGraphicsEngine/Window.h"
 | 
			
		||||
#include <spdlog/spdlog.h>
 | 
			
		||||
#include "include/MyGraphicsEngine/Window.h"
 | 
			
		||||
#include <stdlib.h>
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
bool BarinkWindow::InitGLFW(){
 | 
			
		||||
	if(!glfwInit())
 | 
			
		||||
	{
 | 
			
		||||
		spdlog::error("Failed to initialise GLFW!");
 | 
			
		||||
//		spdlog::error("Failed to initialise GLFW!");
 | 
			
		||||
		return false;
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
@ -22,7 +23,7 @@ Width(width), Height(height), FullScreen(false){
 | 
			
		||||
 | 
			
		||||
	if( !window)
 | 
			
		||||
	{
 | 
			
		||||
		spdlog::error("GLFW failed to create window!");
 | 
			
		||||
//		spdlog::error("GLFW failed to create window!");
 | 
			
		||||
		glfwTerminate();
 | 
			
		||||
		return;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user