in gym3/internal/renderer.py [0:0]
def __init__(self, width: int, height: int) -> None:
# do late imports of these to avoid any interference with other opengl libraries
try:
import glfw
self._glfw = glfw
except ImportError as e:
raise Exception(
f"failed to import glfw: '{e}', please make sure you have the newest version of glfw with `pip install --upgrade glfw`"
)
import moderngl
self._mgl = moderngl
if not self._glfw.init():
raise Exception("failed to initialize glfw")
self._glfw.window_hint(self._glfw.CLIENT_API, self._glfw.OPENGL_API)
self._glfw.window_hint(self._glfw.CONTEXT_VERSION_MAJOR, 3)
self._glfw.window_hint(self._glfw.CONTEXT_VERSION_MINOR, 3)
self._glfw.window_hint(
self._glfw.OPENGL_PROFILE, self._glfw.OPENGL_CORE_PROFILE
)
self._glfw.window_hint(self._glfw.OPENGL_FORWARD_COMPAT, True)
self._glfw.window_hint(self._glfw.RESIZABLE, False)
self._glfw.window_hint(self._glfw.DOUBLEBUFFER, True)
self._glfw.window_hint(self._glfw.DEPTH_BITS, 24)
self.width = width
self.height = height
self.is_open = True
self._should_close = False
self._window = self._glfw.create_window(
self.width, self.height, "Gym3 Viewer", None, None
)
if not self._window:
self._glfw.terminate()
raise Exception("failed to create window")
# self._glfw.get_key_name doesn't handle non-text keys
self._key_to_name = {
getattr(self._glfw, attr): attr.split("_", 1)[1]
for attr in dir(self._glfw)
if attr.startswith("KEY_")
}
self._keys_clicked = set()
self._keys_pressed = set()
self._glfw.set_key_callback(self._window, self._on_key_event)
self._glfw.make_context_current(self._window)
self._ctx = self._mgl.create_context()
self._ctx.enable_only(self._mgl.BLEND)
self._ctx.blend_func = self._mgl.SRC_ALPHA, self._mgl.ONE_MINUS_SRC_ALPHA
self._bitmap_shader = self._ctx.program(
vertex_shader=BITMAP_VERTEX_SHADER, fragment_shader=BITMAP_FRAGMENT_SHADER
)
self._bitmap_shader["in_width"].value = self.width
self._bitmap_shader["in_height"].value = self.height
self._vbo = None
self._vao = None