-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWindow.hpp
More file actions
98 lines (71 loc) · 2.51 KB
/
Copy pathWindow.hpp
File metadata and controls
98 lines (71 loc) · 2.51 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
#pragma once
#include <glad/glad.h>
#include <GLFW/glfw3.h>
#include <stdexcept>
#include <iostream>
#include "imgui.h"
#include "imgui_impl_glfw.h"
#include "imgui_impl_opengl3.h"
class Window {
private:
GLFWwindow* window = nullptr;
public:
Window(int width, int height, const char* title){
glfwInit();
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
this -> window = glfwCreateWindow(width, height, title, NULL, NULL);
if (window == NULL) {
std::cout << "Failed to create GLFW window" << std::endl;
glfwTerminate();
}
glfwMakeContextCurrent(window);
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) {
std::cout << "Failed to initialize GLAD" << std::endl;
}
}
~Window(){
if(window){
glfwDestroyWindow(window);
glfwTerminate();
}
glfwDestroyWindow(window);
}
bool isLeftClickPressed(){
return glfwGetMouseButton(window, GLFW_MOUSE_BUTTON_LEFT) == GLFW_PRESS;
}
bool isRightClickPressed(){
return glfwGetMouseButton(window, GLFW_MOUSE_BUTTON_RIGHT) == GLFW_PRESS;
}
void getMousePos(double &normalizedMouseX, double &normalizedMouseY){
double mouseX, mouseY = 0;
glfwGetCursorPos(window, &mouseX, &mouseY);
int viewPort[4];
glGetIntegerv(GL_VIEWPORT, viewPort);
double screenX = viewPort[2];
double screenY = viewPort[3];
normalizedMouseX = (mouseX / screenX) * 2 - 1;
normalizedMouseY = (mouseY / screenY) * 2 - 1;
}
bool shouldClose(){
return glfwWindowShouldClose(window);
}
void processInput(){
if(glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS){
glfwSetWindowShouldClose(window, true);
}
}
void swapBuffers(){
glfwSwapBuffers(window);
}
void pollEvents(){
glfwPollEvents();
}
void initializeUI() {
IMGUI_CHECKVERSION();
ImGui::CreateContext();
ImGui_ImplGlfw_InitForOpenGL(window, true);
ImGui_ImplOpenGL3_Init("#version 330 core");
}
};