From 204d0827e376dd94d48c1ad6473a0c6e19bae239 Mon Sep 17 00:00:00 2001 From: "Dear.Va" Date: Fri, 20 Dec 2024 01:09:32 +0800 Subject: [PATCH 1/2] fix issue #12 --- genesis/ext/pyrender/numba_gl_wrapper.py | 43 +++++++++++++++++++++--- genesis/vis/viewer.py | 2 +- genesis/vis/visualizer.py | 4 +-- 3 files changed, 41 insertions(+), 8 deletions(-) diff --git a/genesis/ext/pyrender/numba_gl_wrapper.py b/genesis/ext/pyrender/numba_gl_wrapper.py index c47a304..84a5ba2 100644 --- a/genesis/ext/pyrender/numba_gl_wrapper.py +++ b/genesis/ext/pyrender/numba_gl_wrapper.py @@ -12,8 +12,25 @@ ) from numba.core import cgutils from contextlib import ExitStack + +import platform +if platform.platform().lower().startswith("windows"): + import glfw + glfw.init() + glfw.window_hint(glfw.CONTEXT_VERSION_MAJOR, 2) + glfw.window_hint(glfw.CONTEXT_VERSION_MINOR, 0) + glfw.window_hint(glfw.VISIBLE, glfw.FALSE) + window = glfw.create_window(1, 1, "OpenGL Window", None, None) + if not window: + glfw.terminate() + raise Exception("Failed to create GLFW window") + + glfw.make_context_current(window) # This is necessary for Windows OpenGL to work + import OpenGL.GL as GL from OpenGL.GL import GLint, GLuint, GLvoidp, GLvoid, GLfloat, GLsizei, GLboolean, GLenum, GLsizeiptr, GLintptr +from OpenGL.raw.GL.VERSION.GL_2_0 import _EXTENSION_NAME +from OpenGL import platform as GLplatform class GLWrapper: @@ -49,11 +66,27 @@ def __init__(self): def load_func(self, func_name, *signature): dll = GL.platform.PLATFORM.GL - func_ptr = GL.platform.ctypesloader.buildFunction( - GL.platform.PLATFORM.functionTypeFor(dll)(*signature), - func_name, - dll, - ) + func_type = GL.platform.PLATFORM.functionTypeFor(dll)(*signature) + try: + func_ptr = GL.platform.ctypesloader.buildFunction( + func_type, + func_name, + dll, + ) + except: + func_type = func_type() + func_ptr = glplatform.createExtensionFunction( + func_name, + dll, + resultType=func_type.restype, + argTypes=func_type.argtypes, + doc='', + argNames=tuple(map(lambda x: str(x), func_type.argtypes)), + extension=_EXTENSION_NAME, + ) + func_ptr.argtypes = func_type.argtypes + func_ptr.restype = func_type.restype + self.gl_funcs[func_name] = func_ptr def build_wrapper(self): diff --git a/genesis/vis/viewer.py b/genesis/vis/viewer.py index e7ae239..7d54e3d 100644 --- a/genesis/vis/viewer.py +++ b/genesis/vis/viewer.py @@ -64,7 +64,7 @@ def build(self, scene): elif gs.platform == "Windows": run_in_thread = False auto_start = False - gs.raise_exception("Viewer has some issues on Windows. Can anyone help?") + # gs.raise_exception("Viewer has some issues on Windows. Can anyone help?") self._pyrender_viewer = pyrender.Viewer( context=self.context, diff --git a/genesis/vis/visualizer.py b/genesis/vis/visualizer.py index ea40365..ba6e384 100644 --- a/genesis/vis/visualizer.py +++ b/genesis/vis/visualizer.py @@ -68,8 +68,8 @@ def __init__(self, scene, show_viewer, vis_options, viewer_options, renderer): self._cameras = gs.List() def add_camera(self, res, pos, lookat, up, model, fov, aperture, focus_dist, GUI, spp, denoise): - if gs.platform == "Windows": - gs.raise_exception("Camera not yet supported on Windows but is supposed to. Can anyone help?") + # if gs.platform == "Windows": + # gs.raise_exception("Camera not yet supported on Windows but is supposed to. Can anyone help?") # if self._viewer is None and gs.platform == 'macOS': # gs.raise_exception(f'Headless rendering not yet supported on {gs.platform}.') From 3993e6757bbbd0642c18f9b14e888575cf87033b Mon Sep 17 00:00:00 2001 From: "Dear.Va" Date: Fri, 20 Dec 2024 14:42:49 +0800 Subject: [PATCH 2/2] fix typo --- genesis/ext/pyrender/numba_gl_wrapper.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/genesis/ext/pyrender/numba_gl_wrapper.py b/genesis/ext/pyrender/numba_gl_wrapper.py index 84a5ba2..bc46b7a 100644 --- a/genesis/ext/pyrender/numba_gl_wrapper.py +++ b/genesis/ext/pyrender/numba_gl_wrapper.py @@ -30,7 +30,6 @@ import OpenGL.GL as GL from OpenGL.GL import GLint, GLuint, GLvoidp, GLvoid, GLfloat, GLsizei, GLboolean, GLenum, GLsizeiptr, GLintptr from OpenGL.raw.GL.VERSION.GL_2_0 import _EXTENSION_NAME -from OpenGL import platform as GLplatform class GLWrapper: @@ -75,7 +74,7 @@ def load_func(self, func_name, *signature): ) except: func_type = func_type() - func_ptr = glplatform.createExtensionFunction( + func_ptr = GL.platform.createExtensionFunction( func_name, dll, resultType=func_type.restype,