This repository was archived by the owner on Sep 17, 2021. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathWindow.java
More file actions
174 lines (129 loc) · 4.52 KB
/
Copy pathWindow.java
File metadata and controls
174 lines (129 loc) · 4.52 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
package Gprocessing.graphics;
import static org.lwjgl.glfw.GLFW.GLFW_FALSE;
import static org.lwjgl.glfw.GLFW.GLFW_RESIZABLE;
import static org.lwjgl.glfw.GLFW.GLFW_TRUE;
import static org.lwjgl.glfw.GLFW.GLFW_VISIBLE;
import static org.lwjgl.glfw.GLFW.glfwCreateWindow;
import static org.lwjgl.glfw.GLFW.glfwDefaultWindowHints;
import static org.lwjgl.glfw.GLFW.glfwDestroyWindow;
import static org.lwjgl.glfw.GLFW.glfwGetPrimaryMonitor;
import static org.lwjgl.glfw.GLFW.glfwGetVideoMode;
import static org.lwjgl.glfw.GLFW.glfwMakeContextCurrent;
import static org.lwjgl.glfw.GLFW.glfwPollEvents;
import static org.lwjgl.glfw.GLFW.glfwSetErrorCallback;
import static org.lwjgl.glfw.GLFW.glfwSetWindowSizeCallback;
import static org.lwjgl.glfw.GLFW.glfwSetWindowPos;
import static org.lwjgl.glfw.GLFW.glfwSetWindowTitle;
import static org.lwjgl.glfw.GLFW.glfwShowWindow;
import static org.lwjgl.glfw.GLFW.glfwSwapBuffers;
import static org.lwjgl.glfw.GLFW.glfwSwapInterval;
import static org.lwjgl.glfw.GLFW.glfwTerminate;
import static org.lwjgl.glfw.GLFW.glfwWindowHint;
import static org.lwjgl.glfw.GLFW.glfwWindowShouldClose;
import static org.lwjgl.glfw.GLFW.glfwGetTime;
import static org.lwjgl.opengl.GL11.GL_BLEND;
import static org.lwjgl.opengl.GL11.GL_COLOR_BUFFER_BIT;
import static org.lwjgl.opengl.GL11.GL_ONE;
import static org.lwjgl.opengl.GL11.GL_ONE_MINUS_SRC_ALPHA;
import static org.lwjgl.opengl.GL11.glBlendFunc;
import static org.lwjgl.opengl.GL11.glClear;
import static org.lwjgl.opengl.GL11.glEnable;
import org.lwjgl.glfw.GLFWVidMode;
import org.lwjgl.opengl.GL;
import Gprocessing.Editor;
import Gprocessing.Main;
import Gprocessing.ImGui.ImGuiLayer;
import Gprocessing.input.Mouse;
import Gprocessing.util.Engine;
import Gprocessing.util.Scene;
public class Window {
public static long frameCount = 0;
String title;
public static long window;
private GLFWVidMode videoMode = glfwGetVideoMode(glfwGetPrimaryMonitor());
private ImGuiLayer imguiLayer;
public static int width;
public static int height;
public double dt = 0; // deltaTime
static Shader defaultShader;
public static Scene main = new Main();
public static Scene editor = new Editor();
public static Scene currentScene = editor;
public Window(int pwidth, int pheight, String ptitle) {
width = pwidth;
height = pheight;
title = ptitle;
// Configure GLFW
glfwDefaultWindowHints();
glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE);
// Create window
window = glfwCreateWindow(width, height, title, 0, 0);
if (window == 0)
throw new IllegalStateException("[FATAL] Failed to create window.");
glfwSetWindowSizeCallback(window, (w, newWidth, newHeight) -> {
Window.setWidth(newWidth);
Window.setHeight(newHeight);
});
// Make the OpenGL context current
glfwMakeContextCurrent(window);
// Enable V-Sync
glfwSwapInterval(1);
glfwSetWindowPos(window, (videoMode.width() - width) / 2, (videoMode.height() - height) / 2);
}
void getFPS() {
frameCount++;
// glfwSetWindowTitle(window, "GProcessing @ " + Math.round((frameCount / (Engine.millis() / 1000))) + " FPS, " + Engine.deltaTime + " DeltaTime");
}
public void setTitle(String title) {
glfwSetWindowTitle(window, title);
}
public void showWindow() {
/**
* Main game loop
*/
glfwShowWindow(window);
GL.createCapabilities();
glEnable(GL_BLEND);
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
imguiLayer = new ImGuiLayer(window);
imguiLayer.initImGui();
double frameBeginTime = (float)glfwGetTime();
double frameEndTime = (float)glfwGetTime();
currentScene.loadEngineResources();
currentScene.loadJson();
currentScene.awake();
currentScene.startGameObjects();
while (!glfwWindowShouldClose(window)) {
// poll GLFW for input events
Mouse.update();
glfwPollEvents();
glClear(GL_COLOR_BUFFER_BIT);
currentScene.update();
currentScene.updateGameObjects();
imguiLayer.update((float) dt, currentScene);
glfwSwapBuffers(window);
getFPS();
frameEndTime = (float)glfwGetTime();
dt = frameEndTime - frameBeginTime;
Engine.deltaTime = dt;
frameBeginTime = frameEndTime;
}
currentScene.saveExit();
glfwDestroyWindow(window);
glfwTerminate();
glfwSetErrorCallback(null).free();
};
private static void setHeight(int newHeight) {
Window.height = newHeight;
}
private static void setWidth(int newWidth) {
Window.width = newWidth;
}
public static int getWidth () {
return width;
}
public static int getHeight () {
return height;
}
}