Vivid
Loading...
Searching...
No Matches
bump_map.cpp
1#include "Vivid.h"
2
4{
5private:
6 Vivid::Mesh lightMesh;
7 Ref<Vivid::Shader> lightShader;
8 Ref<Vivid::Entity> plane = Vivid::ECS::CreateEntity("plane");
9 Ref<Vivid::Entity> light = Vivid::ECS::CreateEntity("DirectionalLight");
10 Ref<Vivid::ModelComponent> planeModelComponent;
11 Ref<Vivid::TransformComponent> planeTransformComponent = Vivid::ECS::CreateComponent<Vivid::TransformComponent>();
12 Vivid::Mesh* planeMesh;
13
14 Ref<Vivid::DirectionalLightComponent> directionalLightComponent;
15 Ref<Vivid::Shader> shader;
16
17public:
18 void Setup() override
19 {
20 // Can write custom opengl confs here
21 OPENGL_CONFS
22
23 shader = MakeRef<Vivid::Shader>("./../assets/shaders/phong.vertexShader.glsl",
24 "./../assets/shaders/phong.pixelShader.glsl");
25
26 planeMesh = new Vivid::Mesh("./../assets/obj/plane.obj");
27 planeMesh->BindShader(shader);
28
29 planeModelComponent = Vivid::ECS::CreateComponent<Vivid::ModelComponent>();
30 planeModelComponent->AddMesh(planeMesh);
31
32 directionalLightComponent = Vivid::ECS::CreateComponent<Vivid::DirectionalLightComponent>();
33 directionalLightComponent->SetDirection(Vivid::Maths::Vec3(0.0f, -1.0f, 0.0f));
34
35 planeTransformComponent->SetScale(Vivid::Maths::Vec3(50.0f, 50.0f, 50.0f));
36 planeTransformComponent->SetRotation(Vivid::Maths::Vec3(90, 0, 0));
37
38 Vivid::ECS::AddComponent(planeModelComponent->GetComponentID(), plane->GetEntityID());
39 Vivid::ECS::AddComponent(planeTransformComponent->GetComponentID(), plane->GetEntityID());
40
41 Vivid::ECS::AddComponent(directionalLightComponent->GetComponentID(), light->GetEntityID());
42
43 MovableCamera* cam = static_cast<MovableCamera*>(Application::GetInstance()->GetCamera());
44 cam->SetPosition({ 0.0f, 0.0f, 100.0f });
45 cam->MoveBackward();
46
47 planeMesh->AddTexture("./../assets/textures/HighResBrickWall/brickwall.jpg");
48 planeMesh->AddTexture("./../assets/textures/HighResBrickWall/normal_mapping_normal_map.png");
49 planeMesh->GetTexture(0)->SetName("DiffuseTexture");
50 planeMesh->GetTexture(1)->SetName("NormalMap");
51 }
52
53 void Draw() override
54 {
55 Vector<Vivid::DirectionalLightComponent*> directionalLights;
56 Vivid::ECS::GetAllComponents(Vivid::ComponentType::DirectionalLightComponent, directionalLights);
57 Vivid::Maths::Vec3 lightColor = directionalLights[0]->GetLightColor();
58 float intensity = directionalLights[0]->GetIntensity();
59 Vivid::Maths::Vec3 lightDir = directionalLights[0]->GetDirection();
60
61 planeMesh->BindShader(shader);
62 shader->Bind();
63 shader->SetUniform3f("LightDir", lightDir);
64 shader->SetUniform1f("LightIntensity", intensity);
65 shader->SetUniform3f("LightColor", lightColor);
66 }
67
68 void ImGuiRender() override
69 {
70 ImGui::Begin("Debug");
71
72 ImGui::Text("Application average %.3f ms/frame (%.1f FPS)",
73 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate);
74
75 ImGui::End();
76 }
77};
78
79Application* Vivid::CreateApplication()
80{
81 Application* app = Application::GetInstance(1920, 1080, "Vivid: Bump Map Example");
82
83 app->SetRenderingInterface(new ExampleInterface);
84
85 return app;
86}
87
88int main()
89{
90 return Vivid::main(0, nullptr);
91}
Application class.
Definition: Application.h:19
void Setup() override
Setup function.
Definition: bump_map.cpp:18
void ImGuiRender() override
ImGuiRender function.
Definition: bump_map.cpp:68
void Draw() override
Draw function.
Definition: bump_map.cpp:53
A class for the MovableCamera's.
Definition: MovableCamera.h:15
RenderingInterface class.
Contains a Mesh.
Definition: Mesh.h:32
Contains a 3D vector.
Definition: Vec.h:51