forked from Zygahedron/Parabox-Editor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathglfw_start.py
141 lines (116 loc) · 3.61 KB
/
glfw_start.py
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
# -*- coding: utf-8 -*-
import multiprocessing
import glfw
import OpenGL.GL as gl
import sys
import os
sys.path.append(os.getcwd())
import imgui
from imgui.integrations.glfw import GlfwRenderer
import glob
import platform
import traceback
from level import *
from editor import *
import style as imgui_style
# TODO: pick different default per os
if platform.system() == "Windows":
levels_folder = "~\Appdata\LocalLow\Patrick Traynor\Patrick's Parabox\custom_levels"
elif platform.system() == "Darwin": # Mac OS X
levels_folder = "~/Library/Application Support/com.PatrickTraynor.PatricksParabox/custom_levels"
elif platform.system() == "Linux":
levels_folder = "~/.config/unity3d/Patrick Traynor/Patrick's Parabox"
class Key:
def __init__(self):
self.pressed = False
self.down = False
self.released = False
class Keyboard:
def __init__(self):
self.n = Key()
self.b = Key()
self.a = Key()
self.o = Key()
self.s = Key()
self.up = Key()
self.left = Key()
self.down = Key()
self.right = Key()
self.enter = Key()
self.map = {
glfw.KEY_N: self.n,
glfw.KEY_O: self.o,
glfw.KEY_S: self.s,
glfw.KEY_B: self.b,
glfw.KEY_A: self.a,
glfw.KEY_UP: self.up,
glfw.KEY_LEFT: self.left,
glfw.KEY_DOWN: self.down,
glfw.KEY_RIGHT: self.right,
glfw.KEY_ENTER: self.enter
}
keyboard = Keyboard()
def main():
global levels_folder
imgui.create_context()
window = impl_glfw_init()
impl = GlfwRenderer(window)
style = imgui.get_style()
imgui_style.set(style)
levels_search = ""
files = None
open_level_name = ""
open_level = None
error = None
cursor_held = None
editor = Editor()
while not glfw.window_should_close(window):
glfw.poll_events()
impl.process_inputs()
if not glfw.get_window_attrib(window, glfw.FOCUSED):
# use fewer resources when not in front
continue
imgui.new_frame()
if not editor.main_loop(keyboard):
break
for id, key in keyboard.map.items():
if glfw.get_key(window, id):
key.pressed = not key.down
key.down = True
key.released = False
else:
key.released = key.down
key.down = False
key.pressed = False
gl.glClearColor(0.1, 0.1, 0.1, 1)
gl.glClear(gl.GL_COLOR_BUFFER_BIT)
imgui.render()
impl.render(imgui.get_draw_data())
glfw.swap_buffers(window)
impl.shutdown()
glfw.terminate()
def impl_glfw_init():
width, height = 800, 600
window_name = "Zygan's Parabox Editor"
if not glfw.init():
print("Could not initialize OpenGL context")
exit(1)
# OS X supports only forward-compatible core profiles from 3.2
glfw.window_hint(glfw.CONTEXT_VERSION_MAJOR, 3)
glfw.window_hint(glfw.CONTEXT_VERSION_MINOR, 3)
glfw.window_hint(glfw.OPENGL_PROFILE, glfw.OPENGL_CORE_PROFILE)
glfw.window_hint(glfw.OPENGL_FORWARD_COMPAT, gl.GL_TRUE)
# Create a windowed mode window and its OpenGL context
window = glfw.create_window(
int(width), int(height), window_name, None, None
)
glfw.make_context_current(window)
if not window:
glfw.terminate()
print("Could not initialize Window")
exit(1)
return window
if __name__ == "__main__":
# pyinstaller infinite loop fix???
multiprocessing.freeze_support()
main()