-
Notifications
You must be signed in to change notification settings - Fork 0
/
TheCube.cpp
167 lines (124 loc) · 4.37 KB
/
TheCube.cpp
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#define GLAD_GL_IMPLEMENTATION
#include "GLAD/glad.h"
#define GLFW_INCLUDE_NONE
#include "GLFW/glfw3.h"
#define GLT_IMPLEMENTATION
#include "gltext.h"
#define SOL_LUAJIT 1
#define SOL_PRINT_ERRORS 1
#include "SOL/sol.hpp"
#include "ImGUI/imgui.h"
#include "ImGUI/imgui_impl_glfw.h"
#include "ImGUI/imgui_impl_opengl3.h"
#include <stdlib.h>
#include <stddef.h>
#include <stdio.h>
#include "Window.hpp"
#include "Shader.hpp"
#include "ShaderProgram.hpp"
#include "VertexBufferObject.hpp"
#include "Texture2D.hpp"
#include "ElementBufferObject.hpp"
#include "VertexArrayObject.hpp"
#include "GLGlobals.hpp"
#include "Vertex.hpp"
#include "Mesh.hpp"
#include "Model.hpp"
#include "PrimitiveActor.hpp"
#include "Cube.hpp"
#include "Text.hpp"
#include "Sprite.hpp"
#include "Math.hpp"
#include "ChunkSystem.hpp"
#include "LuaRuntime.hpp"
#pragma comment(lib, "GLFW/glfw3_mt.lib")
int main(int argc, char** argv)
{
auto MainWindow = Window();
gltInit();
IMGUI_CHECKVERSION();
ImGui::CreateContext();
ImGuiIO& io = ImGui::GetIO();
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls
io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls
ImGui::StyleColorsDark();
const char* glsl_version = "#version 130";
ImGui_ImplGlfw_InitForOpenGL(MainWindow.window, true);
ImGui_ImplOpenGL3_Init(glsl_version);
glfwSetInputMode(MainWindow.window, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
LuaRuntime::Init();
auto LuaRenderFunctions = LuaRuntime::CollectAllRenderFunctions();
auto LuaDebugUIFunctions = LuaRuntime::CollectAllDebugFunctions();
// auto HitScanText = std::make_shared<Text>(0, 35, "", Color::FromInt(136, 137, 150, 255));
// HitScanText->Push();
// ChunkSystem CS;
// CS.GenerateTerrainChunk();
/* auto FragmentShader = Shader(GL_FRAGMENT_SHADER);
FragmentShader.Source("E:\\source\\repos\\TheCube\\Shaders\\shader3d.frag");
FragmentShader.Compile();
auto VertexShader = Shader(GL_VERTEX_SHADER);
VertexShader.Source("E:\\source\\repos\\TheCube\\Shaders\\shader3d.vert");
VertexShader.Compile();
auto ShaderProg = std::make_shared<ShaderProgram>();
ShaderProg->Attach(VertexShader);
ShaderProg->Attach(FragmentShader);
ShaderProg->Link();
ShaderProg->Use();
auto DefaultCamera = DebugCamera();
DefaultCamera.SetupInput();
auto GrassTexture = std::make_shared<Texture2D>("E:\\source\\repos\\TheCube\\Textures\\grass.png", 6408);
auto GrassBlock = std::make_shared<Cube>(Location::FromWorldCoords({ 200, 200, 200 }), GrassTexture);
GrassBlock->Push();
ShaderProg->Location<Vertex, offsetof(Vertex, Position), 3>("aPos");
ShaderProg->Location<Vertex, offsetof(Vertex, TextureCoord), 2>("aTexCoord");
*/
while (!MainWindow.ShouldClose())
{
if (glfwGetWindowAttrib(MainWindow.window, GLFW_ICONIFIED) != 0)
{
ImGui_ImplGlfw_Sleep(10);
continue;
}
glfwPollEvents();
UpdateDeltaTime();
auto WindowSize = MainWindow.GetSize();
glViewport(0, 0, WindowSize.first, WindowSize.second);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
/*
ShaderProg->Use();
DefaultCamera.Update();
ShaderProg->Uniform("projection", DefaultCamera.Projection);
ShaderProg->Uniform("view", DefaultCamera.View);
Drawlist::Draw(ShaderProg);
*/
for (auto&& Render : LuaRenderFunctions)
{
Render();
}
/*
auto HitTargets = CheckHitScanTargets(DefaultCamera.CameraPos, DefaultCamera.CameraFront);
if (!HitTargets.empty())
{
HitScanText->SetText("Aiming at a target");
}
else
{
HitScanText->SetText("NOT Aiming at a target");
}*/
ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplGlfw_NewFrame();
ImGui::NewFrame();
// ImGui::ShowDemoWindow(&show_demo_window);
ImGui::Begin("Debug UI");
for (auto&& DebugUI : LuaDebugUIFunctions)
{
DebugUI();
ImGui::Separator();
}
ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / io.Framerate, io.Framerate);
ImGui::End();
ImGui::Render();
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
MainWindow.SwapBuffer();
}
}