Multiple changes to prepare for the basic render engine.

* Rendering 2 cubes
* per cube transform panels
* Updated TODO.md
* Updated README.md
This commit is contained in:
Nigel Barink 2022-05-28 21:19:16 +02:00
parent 76c051e407
commit 8cc6ed1f15
12 changed files with 265 additions and 115 deletions

View File

@ -1,106 +1,53 @@
#include "BarinkEngine.h"
#include <imgui.h>
extern void Start(int argc, char* argv[]);
extern void Start();
extern void Update();
extern void ImmediateGraphicsDraw();
extern void Stop();
using namespace BarinkEngine;
void DrawMyGUI();
BarinkWindow* MainWindow;
int main(int argc, char* argv[]) {
// Startup services
MainWindow = new BarinkWindow(800, 600);
BarinkWindow MainWindow = BarinkWindow(800, 600);
Renderer renderer = Renderer();
InputManager InputSystem = InputManager();
InputSystem.attach(&MainWindow);
InputSystem.attach(MainWindow);
GUIManager GUISystem = GUIManager(MainWindow);
GUIManager GUISystem = GUIManager(&MainWindow);
// First call to setup game
Start(argc, argv);
Start();
// Runtime loop
while (!MainWindow->WindowShouldClose()) {
while (!MainWindow.WindowShouldClose()) {
InputSystem.PollEvents();
Update();
renderer.Render();
DrawMyGUI();
ImmediateGraphicsDraw();
GUISystem.Render();
MainWindow->SwapBuffers();
MainWindow.SwapBuffers();
}
// Shutdown game
Stop();
// Shutdown Services
delete MainWindow;
return 0;
}
void WARN(std::string message) {
spdlog::warn(message);
}
void DrawMyGUI() {
ImGui::NewFrame();
ImGui::Begin("Transform");
ImGui::Text("Cube");
/*
ImGui::InputFloat3("Position:", (float*)nullptr);
ImGui::InputFloat3("Rotation:", (float*)nullptr);
ImGui::InputFloat3("Scale:", (float*)nullptr);
*/
ImGui::End();
ImGui::Begin("Camera");
//ImGui::SliderFloat("Zoom:", &NULL, 10, 190);
ImGui::End();
ImGui::Begin("Scripting!!");
//ImGui::InputTextMultiline("Lua Script", nullptr, 255);
//runCode = ImGui::Button("Run");
ImGui::End();
ImGui::ShowDemoWindow();
}

View File

@ -14,6 +14,7 @@
#include "Input/InputManager.h"
#include "Graphics/Renderer.h"
#include "Graphics/GUI/GUIManager.h"
#include "Scene.h"
void WARN(std::string message);

View File

@ -1,26 +1,18 @@
#pragma once
#include <vector>
#include "Mesh.h"
#include "Transform.h"
#include "Buffer.h"
#include "VertexArray.h"
#include "Scene.h"
/*
#include <MyGraphicsEngine/AssetManager/ModelImporter.h>
#include <MyGraphicsEngine/MyGraphicsEngine/Buffer.h>
#include <MyGraphicsEngine/MyGraphicsEngine/VertexArray.h>
*/
class Renderable {
class Renderable : public SceneNode {
public:
Buffer vertexBuffer;
Buffer elementBuffer;
VertexArray VAO;
Transform transform;
~Renderable();
static Renderable Load();
static Renderable* Load();
void Draw();
private:

View File

@ -1,8 +0,0 @@
#pragma once
#include <glm/glm.hpp>
struct Transform {
glm::vec3 Position;
glm::vec3 Rotation;
glm::vec3 Scale;
};

View File

@ -0,0 +1,47 @@
#pragma once
#include <string>
#include <vector>
#include "glm/glm.hpp"
/*
* Scene should be a description of a game world
*/
struct Transform {
glm::vec3 Position;
glm::vec3 Rotation;
glm::vec3 Scale;
glm::mat4 ModelMatrix;
};
class SceneNode {
public:
std::string name;
Transform transform;
SceneNode* parent;
std::vector<SceneNode*> children;
void addChild(SceneNode& node);
};
class Scene {
public:
SceneNode& GetSceneNode(std::string);
SceneNode& GetRoot();
Scene(std::string SceneName = "Default Scene");
~Scene();
private:
SceneNode* root;
};

52
BarinkEngine/Scene.cpp Normal file
View File

@ -0,0 +1,52 @@
#include "Scene.h"
SceneNode* SearchInChildren(SceneNode* root, std::string name ) {
if (root->name == name)
return root;
SceneNode* found = nullptr;
for (auto child : root->children) {
found = SearchInChildren(child, name);
}
return found;
}
SceneNode& Scene::GetSceneNode(std::string name)
{
return *SearchInChildren(root, name);
}
SceneNode& Scene::GetRoot()
{
return *root;
}
Scene::Scene(std::string sceneName)
{
// Create a root node
root = new SceneNode();
root->name = sceneName;
root->transform = Transform();
root->transform.Position = glm::vec3(0);
root->transform.Rotation = glm::vec3(0);
root->transform.Scale = glm::vec3(0);
root->transform.ModelMatrix = glm::mat4(0);
}
Scene::~Scene()
{
// Destruct scene!
}
void SceneNode::addChild(SceneNode& node)
{
children.push_back(&node);
}

View File

@ -94,8 +94,6 @@ BarinkEngine::Mesh ModelImporter::processMesh(aiMesh* mesh, const aiScene* scene
vertices.push_back(vector);
}
//spdlog::info("{} == {}", mesh->mNumVertices, vertices.size());
// Process Indices
for (unsigned int i = 0; i < mesh->mNumFaces; i++) {
aiFace face = mesh->mFaces[i];

View File

@ -3,9 +3,9 @@
Renderable Renderable::Load()
Renderable* Renderable::Load()
{
return Renderable();
return new Renderable();
}
Renderable::Renderable()

View File

@ -43,13 +43,34 @@
## Screenshots
<img src="Screenshots/screen1.png" ></img>
<img src="Screenshots/screen1.png" width="300"></img>
<img src="Screenshots/screen2.png" width="300"></img>
## Planning
see [TODO](docs/TODO.md)
_NOTE:_
The planning is moving away from markdown in favor
of gitea Projects. New planning will be visible on [this page](https://git.barink.dev/Nigel/MyGameEngine/projects).
## Requirements
#### Software
* Premake
* Git
* C++ Compiler
## Windows development workflow
__added soon__
User premake to generate project files for the approperiate build method.
On Windows I assume you'll build with visual studio
```bash
User:~$ premake vs2022
```
## Linux development workflow
__added soon__
Use premake to generate project files for the approperiate build method.
On Linux I assume you'll build with something like make.
```bash
User@Machine:~$ premake gmake2
```

View File

@ -1,53 +1,148 @@
#include "BarinkEngine.h"
#include "imgui.h"
using namespace BarinkEngine;
Camera* cam;
Renderable* Cube;
Shader* shader;
Renderable* Cube2;
char* code = new char[254];
void Start(int argc, char* argv[]) {
std::cout << "Hello start!" << std::endl;
void PrintSceneTree(SceneNode& node, int depth ){
// Indent name based on depth
std::cout << " ";
for (int i = 0; i < depth; i++) {
std::cout << "-";
}
std::cout << " " << node.name << std::endl;
cam = new Camera (glm::vec3(0.0f, 1.5f, -10.0f), glm::vec3(0.0f, 0.0f, 0.0f), 90.0f);
Cube = &Renderable::Load();
depth++;
for (auto child : node.children) {
PrintSceneTree(*child, depth);
}
}
spdlog::info("==== Load Shader(s) ====");
std::string vertexShaderSource = "build/SandboxApplication/Debug/test.vs";
std::string fragmentShaderSource = "build/SandboxApplication/Debug/test.fs";
shader = new Shader(vertexShaderSource, fragmentShaderSource);
void Start() {
SceneNode MyCube = SceneNode();
MyCube.name = "MyCube";
SceneNode MyBaby = SceneNode();
MyBaby.name = "Baby";
SceneNode MySecondCube = SceneNode();
MySecondCube.name = "MySecondCube";
MyCube.addChild(MyBaby);
Scene scene = Scene("My awesome Game Scene");
scene.GetRoot().addChild(MyCube);
scene.GetRoot().addChild(MySecondCube);
// Walk scene graph
PrintSceneTree(scene.GetRoot(),0);
Cube = Renderable::Load();
Cube2 = Renderable::Load();
Cube->addChild(*Cube2);
cam = new Camera(glm::vec3(0.0f, 1.5f, -10.0f), glm::vec3(0.0f, 0.0f, 0.0f), 90.0f);
memset(code, '\0', 254);
}
void transformWindow(Transform& transform, std::string PanelName) {
ImGui::Begin(PanelName.c_str());
ImGui::InputFloat3("Position:", (float*)&transform.Position[0]);
ImGui::InputFloat3("Rotation:", (float*)&transform.Rotation[0]);
ImGui::InputFloat3("Scale:", (float*)&transform.Scale[0]);
ImGui::End();
}
void ImmediateGraphicsDraw() {
ImGui::NewFrame();
ImGui::Begin("Camera");
ImGui::SliderFloat("Zoom:", &cam->Zoom, 10, 190);
ImGui::End();
transformWindow(Cube->transform, "Transform (Cube)");
transformWindow(Cube2->transform, "Transform (Cube2)");
ImGui::Begin("Scripting!!");
ImGui::InputTextMultiline("Lua Script", code, 255);
bool runCode = ImGui::Button("Run");
ImGui::End();
ImGui::ShowDemoWindow();
}
glm::mat4 CalculateModelMat(Transform& transform) {
glm::mat4 tran = glm::translate(glm::mat4(), transform.Position);
glm::mat4 scale = glm::scale(glm::mat4(), transform.Scale);
glm::mat4 rot =
glm::rotate(glm::mat4(), glm::radians(transform.Rotation.x), glm::vec3(1.0f, 0.0f, 0.0f)) *
glm::rotate(glm::mat4(), glm::radians(transform.Rotation.y), glm::vec3(0.0f, 1.0f, 0.0f)) *
glm::rotate(glm::mat4(), glm::radians(transform.Rotation.z), glm::vec3(0.0f, 0.0f, 1.0f));
return tran * rot * scale;
}
void Update()
{
glm::mat4 tran = glm::translate(glm::mat4(), Cube->transform.Position);
glm::mat4 scale = glm::scale(glm::mat4(), Cube->transform.Scale);
glm::mat4 rot =
glm::rotate(glm::mat4(), glm::radians(Cube->transform.Rotation.x), glm::vec3(1.0f, 0.0f, 0.0f)) *
glm::rotate(glm::mat4(), glm::radians(Cube->transform.Rotation.y), glm::vec3(0.0f, 1.0f, 0.0f)) *
glm::rotate(glm::mat4(), glm::radians(Cube->transform.Rotation.z), glm::vec3(0.0f, 0.0f, 1.0f));
std::string vertexShaderSource = "build/SandboxApplication/Debug/test.vs";
std::string fragmentShaderSource = "build/SandboxApplication/Debug/test.fs";
Shader shader = Shader(vertexShaderSource, fragmentShaderSource);
glm::mat4 model = tran * rot * scale;
glm::mat4 projection = glm::perspective(glm::radians(cam->Zoom), (800.0f / 600.0f), 0.001f, 100.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
shader->Use();
shader->setUniformMat4("P", projection);
shader->setUniformMat4("M", model);
shader->setUniformMat4("V", cam->GetViewMatrix());
shader.Use();
shader.setUniformMat4("P", projection);
shader.setUniformMat4("M", CalculateModelMat(Cube->transform));
shader.setUniformMat4("V", cam->GetViewMatrix());
shader.setUniformVec3("MatColour", glm::vec3(1.0f, 0.0f, 0.0f));
Cube->Draw();
shader.setUniformMat4("M", CalculateModelMat(Cube2->transform));
shader.setUniformVec3("MatColour", glm::vec3(0.0f, 1.0f, 0.0f));
Cube2->Draw();
}
@ -56,7 +151,9 @@ void Stop() {
Cube->VAO.Delete();
Cube->elementBuffer.Delete();
Cube2->VAO.Delete();
Cube2->elementBuffer.Delete();
delete Cube2;
delete Cube;
delete cam;
delete shader;
}

BIN
Screenshots/screen2.png (Stored with Git LFS) Normal file

Binary file not shown.

View File

@ -13,7 +13,7 @@
<input type="checkbox" checked></input> Work on basic logging \
<input type="checkbox"></input> Input handling \
<input type="checkbox"></input> More shader work \
<input type="checkbox"></input> Load FBX model files \
<input type="checkbox" checked></input> Load FBX model files \
<input type="checkbox"></input> Basic Physics \
<input type="checkbox" checked> Running LUA \
<input type="checkbox"> Lua Scripting \