-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
82 lines (66 loc) · 2.01 KB
/
main.cpp
File metadata and controls
82 lines (66 loc) · 2.01 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<iostream>
#include<glad/glad.h>
#include<GLFW/glfw3.h>
const float WINDOW_WIDTH = 400;
const float WINDOW_HEIGHT = 225;
int main()
{
// Initialize GLFW
glfwInit();
// Set OpenGL version to 3.3
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
// Set version to core to also use new functions
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
// Create 800x800 window with title YoutubeOpenGL
GLFWwindow* window = glfwCreateWindow(WINDOW_WIDTH, WINDOW_HEIGHT, "I made this!", NULL, NULL);
if (window == NULL)
{
// Terminate GLFW in case window cannot be created
std::cout << "Failed to create GLFW window" << std::endl;
glfwTerminate();
return -1;
}
// Introduce the window in the current context
glfwMakeContextCurrent(window);
// Make GLAD configure OpenGL
gladLoadGL();
// Specify the OpenGL viewport in the window, 0,0 is the top right corner,
// 800,800 the bottom corner
glViewport(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT);
float timeElapsedSinceStart = 0.0f;
float redValue = 1.0f;
bool updateColor = false;
while (!glfwWindowShouldClose(window))
{
timeElapsedSinceStart = static_cast<float>(glfwGetTime());
if (std::fmod(timeElapsedSinceStart, 2) == 0) {
redValue = 0.25f;
updateColor = true;
}
if (std::fmod(timeElapsedSinceStart, 3) == 0) {
redValue = 0.65f;
updateColor = true;
}
if (std::fmod(timeElapsedSinceStart, 5) == 0) {
redValue = 10.f;
updateColor = true;
}
if (updateColor) {
// Set background color according to redValue with opacity 1
glClearColor(redValue, 0.65f, 0.0f, 1.0f);
// Clean the back buffer and set the new color
glClear(GL_COLOR_BUFFER_BIT);
// Swap the back buffer (original window color)
// with the front buffer (color just set before)
glfwSwapBuffers(window);
updateColor = false;
}
glfwPollEvents();
}
// Make GLAD destroy the window and terminate itself,
// then exit without errors
glfwDestroyWindow(window);
glfwTerminate();
return 0;
}