-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRenderSystem.cpp
More file actions
82 lines (51 loc) · 2.5 KB
/
Copy pathRenderSystem.cpp
File metadata and controls
82 lines (51 loc) · 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include "RenderSystem.h"
#include <GLFW/glfw3.h>
RenderSystem::RenderSystem(int width, int height) {
this->width = width;
this->height = height;
rend.Init();
}
void RenderSystem::setCamera(Entity* camera)
{
this->camera = camera;
}
double prevTime = glfwGetTime();
void RenderSystem::tick(World* world, float deltaTime)
{
t += glfwGetTime() - prevTime;
prevTime = glfwGetTime();
rend.SetTime(t);
world->each<Skybox>([&](Entity* ent, ComponentHandle<Skybox> meshComp) {
Texture texture = textureManager.GetTexture(meshComp->textureFilepath);
Mesh mesh = meshManager.GetMesh(meshComp->meshFilepath);
glm::mat4 proj = glm::perspective(glm::radians(45.0f), (float)(width / height), 0.1f, 100.0f);
ComponentHandle<Camera> cam = camera->get<Camera>();
rend.DrawSkybox(mesh, texture, proj, cam.get());
});
glEnable(GL_CULL_FACE);
world->each<MeshComponent>([&](Entity* ent, ComponentHandle<MeshComponent> meshComp) {
ComponentHandle<Transform3D> transform = ent->get<Transform3D>();
Texture texture = textureManager.GetTexture(meshComp->textureFilepath);
Texture normalsTexture = textureManager.GetTexture(meshComp->normalsFilepath);
Mesh mesh = meshManager.GetMesh(meshComp->meshFilepath);
glm::mat4 proj = glm::perspective(glm::radians(45.0f), (float)(width / height), 0.1f, 100.0f);
ComponentHandle<Camera> cam = camera->get<Camera>();
rend.DrawMesh(mesh, texture, proj, transform->position, transform->xrotation, transform->yrotation, transform->scale, cam.get(), normalsTexture, meshComp->shaderName);
});
glDisable(GL_CULL_FACE);
glDisable(GL_DEPTH_TEST);
world->each<Sprite>([&](Entity* ent, ComponentHandle<Sprite> sprite) {
ComponentHandle<Transform2D> transform = ent->get<Transform2D>();
Texture texture = textureManager.GetTexture(sprite->filepath);
glm::mat4 projection = glm::ortho(0.0f, static_cast<float>(width), static_cast<float>(height), 0.0f, -1.0f, 1.0f);
if (sprite->visible) {
if (sprite->autoSize) {
rend.DrawSprite(texture, projection, transform->position, texture.GetSize(), transform->rotation, sprite->color, sprite->shaderName);
}
else {
rend.DrawSprite(texture, projection, transform->position, sprite->size, transform->rotation, sprite->color, sprite->shaderName);
}
}
});
glEnable(GL_DEPTH_TEST);
}