diff --git a/genesis/ext/pyrender/numba_gl_wrapper.py b/genesis/ext/pyrender/numba_gl_wrapper.py index c47a304..bc46b7a 100644 --- a/genesis/ext/pyrender/numba_gl_wrapper.py +++ b/genesis/ext/pyrender/numba_gl_wrapper.py @@ -12,8 +12,24 @@ ) 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 class GLWrapper: @@ -49,11 +65,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 = GL.platform.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}.')