Skip to content

Commit a4f6611

Browse files
committed
works on Ubuntu 24.04.3
1 parent 899cfbb commit a4f6611

5 files changed

Lines changed: 49 additions & 15 deletions

File tree

demo.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ def __init__(self):
1616
def init_mgl(self):
1717
self.mgl = MGL()
1818

19-
self.journey_obj = OBJ('data/models/journey/journey.obj', self.mgl.program('data/shaders/default.vert', 'data/shaders/default.frag'), centered=True)
19+
self.knife_obj = OBJ("data/models/knife/knife.obj", self.mgl.program("data/shaders/default.vert", "data/shaders/default.frag"), centered=True)
2020

21-
self.ak_obj = OBJ('data/models/ak47/ak47.obj', self.mgl.program('data/shaders/default.vert', 'data/shaders/default.frag'), centered=True)
21+
self.m4_obj = OBJ("data/models/m4/m4.obj", self.mgl.program("data/shaders/default.vert", "data/shaders/default.frag"), centered=True)
2222

23-
self.shiba_obj = OBJ('data/models/shiba/shiba.obj', self.mgl.program('data/shaders/default.vert', 'data/shaders/default.frag'), centered=True)
23+
self.watch_obj = OBJ("data/models/watch/watch.obj", self.mgl.program("data/shaders/default.vert", "data/shaders/default.frag"), centered=True)
2424

25-
self.test_entity = self.journey_obj.new_entity()
26-
self.test_entity_2 = self.ak_obj.new_entity()
27-
self.test_entity_3 = self.shiba_obj.new_entity()
25+
self.test_entity = self.knife_obj.new_entity()
26+
self.test_entity_2 = self.m4_obj.new_entity()
27+
self.test_entity_3 = self.watch_obj.new_entity()
2828

2929
self.camera = Camera(up=(0, -1, 0))
3030
self.camera.light_pos = [0.5, 1, 1]

mgllib/camera.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ def __init__(self, pos=[0, 0, 1], target=[0, 0, 0], up=[0, 1, 0]):
88
self.update_matrix()
99

1010
self.light_pos = [0, 1, 0]
11+
self.eye_pos = list(pos)
1112

1213
def lookat(self, target):
1314
self.target = list(target[:3])

mgllib/glfwhack.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import ctypes
22
import os
33
import sys
4+
import platform
45

56
import pygame
67

@@ -13,20 +14,28 @@
1314

1415
class DetectContext:
1516
def __init__(self):
16-
ctypes.windll.opengl32.wglGetCurrentDC.restype = ctypes.c_void_p
17-
ctypes.windll.opengl32.wglGetCurrentContext.restype = ctypes.c_void_p
18-
self.hdc = ctypes.windll.opengl32.wglGetCurrentDC()
19-
self.hglrc = ctypes.windll.opengl32.wglGetCurrentContext()
17+
if platform.system() == "Windows":
18+
ctypes.windll.opengl32.wglGetCurrentDC.restype = ctypes.c_void_p
19+
ctypes.windll.opengl32.wglGetCurrentContext.restype = ctypes.c_void_p
20+
self.hdc = ctypes.windll.opengl32.wglGetCurrentDC()
21+
self.hglrc = ctypes.windll.opengl32.wglGetCurrentContext()
22+
else:
23+
# On Linux, pygame handles context management internally
24+
self.hdc = None
25+
self.hglrc = None
2026

2127
def make_current(self):
22-
ctypes.windll.opengl32.wglMakeCurrent.argtypes = [ctypes.c_void_p, ctypes.c_void_p]
23-
ctypes.windll.opengl32.wglMakeCurrent(self.hdc, self.hglrc)
28+
if platform.system() == "Windows":
29+
ctypes.windll.opengl32.wglMakeCurrent.argtypes = [ctypes.c_void_p, ctypes.c_void_p]
30+
ctypes.windll.opengl32.wglMakeCurrent(self.hdc, self.hglrc)
31+
# On Linux, pygame.display.set_mode already set the current context
2432

2533
class g:
2634
ctx = None
2735

2836
def create_window(*args, **kwargs):
29-
os.environ['SDL_WINDOWS_DPI_AWARENESS'] = 'permonitorv2'
37+
if platform.system() == "Windows":
38+
os.environ['SDL_WINDOWS_DPI_AWARENESS'] = 'permonitorv2'
3039

3140
pygame.init()
3241
pygame.display.set_mode((1280, 720), flags=pygame.OPENGL | pygame.DOUBLEBUF, vsync=False)

mgllib/glfwwin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This implementation is specific to Windows. See PyOpenXR's hello_xr example for a linux variation.
22

3-
from OpenGL import GL, WGL
3+
from OpenGL import GL
44
import glfw
55

66
from .elements import ElementSingleton

mgllib/xr_plugin_hack.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,15 @@
1919
from .const import FORCE_SRGB
2020

2121
def hack_pyopenxr(window_size, window_title='VR Test'):
22+
23+
def structure_type_missing_wrapper(cls, value):
24+
25+
# Unknown OpenXR event type (extension event we don't support)
26+
print(f"[WARNING] Unknown StructureType: {value}, returning UNKNOWN", flush=True)
27+
return StructureType.UNKNOWN
28+
29+
StructureType._missing_ = classmethod(structure_type_missing_wrapper)
30+
2231
# hack the default rendering plugin so we don't have to write a custom one
2332
def opengl_graphics_init(self, instance, system, title='glfw OpenGL window'):
2433
if not glfw.init():
@@ -99,6 +108,21 @@ def opengl_graphics_select_color_swapchain_format(runtime_formats):
99108
return sf
100109
raise RuntimeError("No runtime swapchain format supported for color swapchain")
101110

111+
# save begin_frame so we can wrap it
112+
original_begin_frame = OpenGLGraphics.begin_frame
113+
114+
# wrap begin_frame to suppress invalid value error for glBindFramebuffer
115+
def opengl_graphics_begin_frame_wrapper(self, layer_view, color_texture):
116+
try:
117+
return original_begin_frame(self, layer_view, color_texture)
118+
except GL.error.GLError as e:
119+
# Suppress invalid value error for glBindFramebuffer
120+
if e.err == 1281:
121+
print(f"[WARNING] Suppressed expected OpenGL Error manually in begin_frame: {e}")
122+
else:
123+
raise e
124+
102125
# the cursed overrides
103126
OpenGLGraphics.__init__ = opengl_graphics_init
104-
OpenGLGraphics.select_color_swapchain_format = opengl_graphics_select_color_swapchain_format
127+
OpenGLGraphics.select_color_swapchain_format = opengl_graphics_select_color_swapchain_format
128+
OpenGLGraphics.begin_frame = opengl_graphics_begin_frame_wrapper

0 commit comments

Comments
 (0)