Monad Engine da02fba2
> Undercity Codex_
Loading...
Searching...
No Matches
TestObject.cpp
Go to the documentation of this file.
1#include "TestObject.h"
2#include <GLFW/glfw3.h>
3#include <iostream>
4
6{
7 std::string vertexShaderSource = R"(
8 #version 330 core
9 layout (location = 0) in vec3 position;
10 layout (location = 1) in vec3 color;
11
12 out vec3 vColor;
13
14 uniform mat4 uModel;
15 uniform mat4 uView;
16 uniform mat4 uProjection;
17
18 void main()
19 {
20 vColor = color;
21 gl_Position = uProjection * uView * uModel * vec4(position, 1.0);
22 }
23 )";
24
25 std::string fragmentShaderSource = R"(
26 #version 330 core
27 out vec4 FragColor;
28
29 in vec3 vColor;
30
31 void main()
32 {
33 FragColor = vec4(vColor, 1.0);
34 }
35 )";
36
37 auto& graphicsAPI = eng::Engine::GetInstance().GetGraphicsAPI();
38 auto shaderProgram = graphicsAPI.CreateShaderProgram(vertexShaderSource, fragmentShaderSource);
39
40 auto material = std::make_shared<eng::Material>();
41 material->SetShaderProgram(shaderProgram);
42
43 std::vector<float> vertices =
44 {
45 0.5f, 0.5f, 0.5f, 1.0f, 0.0f, 0.0f,
46 -0.5f, 0.5f, 0.5f, 0.0f, 1.0f, 0.0f,
47 -0.5f, -0.5f, 0.5f, 0.0f, 0.0f, 1.0f,
48 0.5f, -0.5f, 0.5f, 1.0f, 1.0f, 0.0f,
49
50 0.5f, 0.5f, -0.5f, 1.0f, 0.0f, 0.0f,
51 -0.5f, 0.5f, -0.5f, 0.0f, 1.0f, 0.0f,
52 -0.5f, -0.5f, -0.5f, 0.0f, 0.0f, 1.0f,
53 0.5f, -0.5f, -0.5f, 1.0f, 1.0f, 0.0f
54 };
55
56 std::vector<unsigned int> indices =
57 {
58 // front face
59 0, 1, 2,
60 0, 2, 3,
61 // top face
62 4, 5, 1,
63 4, 1, 0,
64 // right face
65 4, 0, 3,
66 4, 3, 7,
67 // left face
68 1, 5, 6,
69 1, 6, 2,
70 // bottom face
71 3, 2, 6,
72 3, 6, 7,
73 // back face
74 4, 7, 6,
75 4, 6, 5
76 };
77
78 eng::VertexLayout vertexLayout;
79
80 // Postion
81 vertexLayout.elements.push_back({
82 0,
83 3,
84 GL_FLOAT,
85 0
86 });
87 // Color
88 vertexLayout.elements.push_back({
89 1,
90 3,
91 GL_FLOAT,
92 sizeof(float) * 3
93 });
94 vertexLayout.stride = sizeof(float) * 6;
95
96 auto mesh = std::make_shared<eng::Mesh>(vertexLayout, vertices, indices);
97
99}
100
101void TestObject::Update(float deltaTime)
102{
103 eng::GameObject::Update(deltaTime);
104}
std::shared_ptr< Material > material
std::shared_ptr< Mesh > mesh
void Update(float deltaTime) override
GraphicsAPI & GetGraphicsAPI()
Definition Engine.cpp:195
static Engine & GetInstance()
Definition Engine.cpp:50
virtual void Update(float deltaTime)
void AddComponent(Component *component)
std::shared_ptr< ShaderProgram > CreateShaderProgram(const std::string &vertexSource, const std::string &fragmentSource)
std::vector< VertexElement > elements