-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
58 lines (49 loc) · 1.74 KB
/
main.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
#include <iostream>
#include <glad/glad.h> //glad needs to be included before glfw
#include <GLFW/glfw3.h>
// Declare a function to be called when the window is resized
void frameBufferSizeCallback(GLFWwindow* window, int width, int height)
{
std::cout << "Window resized to " << width << "x" << height << std::endl;
}
// Declare a function to be called when the key is pressed
void keyCallBack(GLFWwindow* window, int key, int scancode, int action, int mods)
{
std::cout << "Key pressed: " << key << std::endl;
//std::cout << "Scancode: " << scancode << std::endl;
std::cout << "Action: " << action << std::endl;
std::cout << "Mods: " << mods << std::endl;
}
// Create a window
int main() {
// Initialize the GLFW basic environment
glfwInit();
// Set the GLFW Major version to 3.4
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
// Set the GLFW Minor version to 3.6
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 6);
// Set the GLFW profile to core
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
// Create a window object
GLFWwindow* window = glfwCreateWindow(800, 600, "LearnOpenGL", NULL, NULL);
// Set the window to the current context
glfwMakeContextCurrent(window);
// Set the frame buffer size callback
glfwSetFramebufferSizeCallback(window, frameBufferSizeCallback);
// Set the key callback
glfwSetKeyCallback(window, keyCallBack);
// Load the OpenGL function pointers
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress))
{
std::cout << "Failed to initialize GLAD" << std::endl;
return -1;
}
// Execute window loop
while (!glfwWindowShouldClose(window))
{
glfwPollEvents(); //Receive events
}
// Terminate the GLFW environment
glfwTerminate();
return 0;
}