-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApplication.cpp
More file actions
262 lines (212 loc) · 7.04 KB
/
Application.cpp
File metadata and controls
262 lines (212 loc) · 7.04 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
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
#include <GL/glew.h>
#include <GLFW/glfw3.h>
#include <string>
#include <iostream>
#include <sstream>
#include <fstream>
#include "Renderer.h"
#include "VertexBuffer.h"
#include "IndexBuffer.h"
#include "VertexArray.h"
#include "Shader.h"
#include "VertexBufferLayout.h"
#include "Texture.h"
#include "Res/Vendor/glm/glm.hpp"
#include "glm/gtc/matrix_transform.hpp"
#include "gui/imgui.h"
#include "gui/imgui_impl_glfw.h"
#include "gui/imgui_impl_opengl3.h"
#include "Tests/TestClearColor.h"
#include <chrono>
class Timer
{
public:
Timer() : m_StartTimepoint(std::chrono::high_resolution_clock::now()) {}
~Timer()
{
Stop();
}
void Stop()
{
auto endTimepoint = std::chrono::high_resolution_clock::now();
auto start = std::chrono::time_point_cast<std::chrono::microseconds>(m_StartTimepoint).time_since_epoch().count();
auto end = std::chrono::time_point_cast<std::chrono::microseconds>(endTimepoint).time_since_epoch().count();
auto duration = end - start;
double ms = duration * 0.001;
std::cout << "Duration: " << duration << "us (" << ms << "ms)\n";
}
private:
std::chrono::time_point<std::chrono::high_resolution_clock> m_StartTimepoint;
};
//#include "gui/imgui_impl_opengl3_loader.h"
int main(void)
{
Timer timer;
GLFWwindow* window;
/* Initialize the library */
if (!glfwInit())
return -1;
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
/* Create a windowed mode window and its OpenGL context */
window = glfwCreateWindow(960, 540, "Hello World", NULL, NULL);
if (!window)
{
glfwTerminate();
return -1;
}
/* Make the window's context current */
glfwMakeContextCurrent(window);
glfwSwapInterval(1);
glewInit();
{
//GLCall(glClearColor(1,1,1, 0));
/*float positions[] = {
-50.0f, -50.0f, 0.0f, 0.0f,
50.0f, -50.0f, 1.0f, 0.0f,
50.0f, 50.0f, 1.0f, 1.0f,
-50.0f, 50.0f, 0.0f, 1.0f
};
unsigned int indices[] = {
0, 3, 2,
2, 1, 0
};*/
GLCall(glEnable(GL_BLEND));
GLCall(glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA));
//GLCall(glBlendEquation(GL_FUNC_SUBTRACT));
/*VertexArray va;
VertexBuffer vb(positions, 4 * 4 * sizeof(float));
VertexBufferLayout layout;
layout.Push<float>(2);
layout.Push<float>(2);
va.addBuffer(vb, layout);
glm::mat4 proj = glm::ortho(0.0f, 960.0f, 0.0f, 540.0f, -1.0f, 1.0f);
glm::mat4 view = glm::translate(glm::mat4(1.0f), glm::vec3(0.0f, 0.0f, 0.0f));
IndexBuffer ib(indices, 6);
Shader shader("Res/Shader/Basic.shader");
shader.Bind();
shader.setUniform4f("u_Color", 1.0f, 1.0f, 0.0f, 1.0f);
Texture texture("Res/textures/img.png");
texture.Bind(0);
shader.setUniform1i("u_Texture", 0);
va.Unbind();
vb.Unbind();
ib.Unbind();
shader.Unbind();
float r = 0.0f;
float g = 0.0f;
float b = 0.0f;
float incr = 0.005f;
glm::vec3 translationA(200.0f, 200.0f, 0.0f);
glm::vec3 translationB(400.0f, 200.0f, 0.0f);
bool show_demo_window = true;
bool show_another_window = false;
ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);*/
Renderer renderer;
ImGui::CreateContext();
ImGuiIO& io = ImGui::GetIO(); (void)io;
/*io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;
io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad;*/
ImGui_ImplGlfw_InitForOpenGL(window, true);
ImGui::StyleColorsDark();
ImGui_ImplOpenGL3_Init();
/* Loop until the user closes the window */
test::TestClearColor test;
while (!glfwWindowShouldClose(window))
{
renderer.Clear();
test.OnUpdate(0.0f);
test.OnRender();
ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplGlfw_NewFrame();
ImGui::NewFrame();
/* Swap front and back buffers */
test.OnImGuiRender();
ImGui::Render();
int display_w, display_h;
glfwGetFramebufferSize(window, &display_w, &display_h);
glViewport(0, 0, display_w, display_h);
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
glfwSwapBuffers(window);
/* Poll for and process events */
glfwPollEvents();
}
/*GLCall(glDeleteProgram(shader));*/
}
ImGui_ImplOpenGL3_Shutdown();
ImGui_ImplGlfw_Shutdown();
ImGui::DestroyContext();
glfwDestroyWindow(window);
glfwTerminate();
return 0;
}
//Extra
//glClearColor(clear_color.x* clear_color.w, clear_color.y* clear_color.w, clear_color.z* clear_color.w, clear_color.w);
//glClear(GL_COLOR_BUFFER_BIT);
//
//{
// glm::mat4 model = glm::translate(glm::mat4(1.0f), translationA);
// glm::mat4 mvp = proj * view * model;
//
// shader.Bind();
// /*shader.setUniform4f("u_Color", r, g, b, 1.0f);*/
// shader.setUniformMat4f("u_MVP", mvp);
//
// renderer.Draw(va, ib, shader);
//}
//
//{
// glm::mat4 model = glm::translate(glm::mat4(1.0f), translationB);
// glm::mat4 mvp = proj * view * model;
//
// shader.Bind();
// /*shader.setUniform4f("u_Color", r, g, b, 1.0f);*/
// shader.setUniformMat4f("u_MVP", mvp);
//
// renderer.Draw(va, ib, shader);
//}
//
//
//
//r += incr;
//if (r >= 1)
//{
// incr = -incr;
// r = 1;
//
//}
//else if (r <= 0)
//{
// incr = -incr;
// r = 0;
//}
//
//
//
//// 2. Show a simple window that we create ourselves. We use a Begin/End pair to create a named window.
//{
// static float f = 0.0f;
// static int counter = 0;
//
// // Create a window called "Hello, world!" and append into it.
// ImGui::Begin("Hello, world!");
//
// //ImGui::Text("This is some useful text."); // Display some text (you can use a format strings too)
// //ImGui::Checkbox("Demo Window", &show_demo_window); // Edit bools storing our window open/close state
// //ImGui::Checkbox("Another Window", &show_another_window);
//
// ImGui::SliderFloat3("Translation A", &translationA.x, 0.0f, 960.0f); // Edit 1 float using a slider from 0.0f to 1.0f
// ImGui::SliderFloat3("Translation B", &translationB.x, 0.0f, 960.0f); // Edit 1 float using a slider from 0.0f to 1.0f
// //ImGui::ColorEdit3("clear color", (float*)&clear_color); // Edit 3 floats representing a color
//
// //if (ImGui::Button("Button")) // Buttons return true when clicked (most widgets return true when edited/activated)
// // counter++;
// //ImGui::SameLine();
// //ImGui::Text("counter = %d", counter);
//
// ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / io.Framerate, io.Framerate);
// ImGui::End();
//
//
//}