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
167 lines (119 loc) · 3.75 KB
/
Copy pathWindow.java
File metadata and controls
167 lines (119 loc) · 3.75 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
package Gprocessing.graphics;
import Gprocessing.ImGui.ImGuiLayer;
import Gprocessing.Main;
import Gprocessing.breakout.Breakout;
import Gprocessing.civ.CivScene;
import Gprocessing.editor.EditorGui;
import Gprocessing.input.Mouse;
import Gprocessing.porfolioManager.PortfolioManager;
import Gprocessing.util.Engine;
import Gprocessing.util.Scene;
import Gprocessing.chickenCoup.ChickenCoup;
import org.lwjgl.glfw.GLFWVidMode;
import org.lwjgl.opengl.GL;
import static org.lwjgl.glfw.GLFW.*;
import static org.lwjgl.opengl.GL11.*;
public class Window {
// Define and set the current scene
public static Scene main = new Main();
public static Scene bScene = new Breakout();
public static Scene cc = new ChickenCoup();
public static Scene civ = new CivScene();
public static Scene pf = new PortfolioManager();
// public static ArrayList<Scene> scenes = new ArrayList<Scene>();
public static Scene currentScene = civ;
// Window Variables
public 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;
private float dt = 0; // deltaTime (accessible from Engine.deltaTime)
static Shader defaultShader;
public static EditorGui 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);
// currentScene.camera.adjustProjection();
});
// Make the OpenGL context current
glfwMakeContextCurrent(window);
// Enable V-Sync
glfwSwapInterval(1);
// Center the window
glfwSetWindowPos(window, (videoMode.width() - width) / 2, (videoMode.height() - height) / 2);
if (Engine.showEditor) {
editor = new EditorGui();
}
}
void getFPS() {
frameCount++;
glfwSetWindowTitle(window, title + " @ " + Math.round((frameCount / (Engine.millis() / 1000))) + " FPS");
}
public void setTitle(String title) {
glfwSetWindowTitle(window, title);
}
public void showWindow() {
/*
* Main game loop
*/
glfwShowWindow(window);
GL.createCapabilities();
// https://www.youtube.com/watch?v=h4u-wrGdx_U
glEnable(GL_BLEND);
// glBlendFunc(GL_ONE, GL_SRC_ALPHA);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
float frameBeginTime = (float)glfwGetTime();
float frameEndTime = (float)glfwGetTime();
imguiLayer = new ImGuiLayer(window);
imguiLayer.initImGui();
currentScene.loadEngineResources();
currentScene.awake();
currentScene.startGameObjects();
while (!glfwWindowShouldClose(window)) {
Engine.deltaTime = dt;
// 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;
}
glfwDestroyWindow(window);
glfwTerminate();
glfwSetErrorCallback(null).free();
};
private static void setHeight(int newHeight) {
height = newHeight;
}
private static void setWidth(int newWidth) {
width = newWidth;
}
public static int getWidth () {
return width;
}
public static int getHeight () {
return height;
}
}