Exemplo n.º 1
0
def init():
    global window, imgui_renderer, _ui_state
    glfw.set_error_callback(error_callback)
    imgui.create_context()
    if not glfw.init():
        print("GLFW Initialization fail!")
        return
    graphics_settings = configuration.get_graphics_settings()
    loader_settings = configuration.get_loader_settings()
    if graphics_settings is None:
        print("bla")
        return
    screen_utils.WIDTH = graphics_settings.getint("width")
    screen_utils.HEIGHT = graphics_settings.getint("height")
    screen_utils.MAX_FPS = graphics_settings.getint("max_fps")
    screen = None
    if graphics_settings.getboolean("full_screen"):
        screen = glfw.get_primary_monitor()
    hints = {
        glfw.DECORATED: glfw.TRUE,
        glfw.RESIZABLE: glfw.FALSE,
        glfw.CONTEXT_VERSION_MAJOR: 4,
        glfw.CONTEXT_VERSION_MINOR: 5,
        glfw.OPENGL_DEBUG_CONTEXT: glfw.TRUE,
        glfw.OPENGL_PROFILE: glfw.OPENGL_CORE_PROFILE,
        glfw.SAMPLES: 4,
    }
    window = _create_window(size=(screen_utils.WIDTH, screen_utils.HEIGHT),
                            pos="centered",
                            title="Tremor",
                            monitor=screen,
                            hints=hints,
                            screen_size=glfw.get_monitor_physical_size(
                                glfw.get_primary_monitor()))
    imgui_renderer = GlfwRenderer(window, attach_callbacks=False)
    glutil.log_capabilities()
    glEnable(GL_CULL_FACE)
    glCullFace(GL_BACK)
    glEnable(GL_DEPTH_TEST)
    glDepthMask(GL_TRUE)
    glDepthFunc(GL_LEQUAL)
    glDepthRange(0.0, 1.0)
    glEnable(GL_MULTISAMPLE)
    glEnable(GL_BLEND)
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
    create_branched_programs()
    # create the uniforms
    _create_uniforms()
    # initialize all the uniforms for all the prpograms
    init_all_uniforms()
Exemplo n.º 2
0
    def __GetScreenInfo(self, spec):
        Renderer.screenStats.width, Renderer.screenStats.height = glfw.get_framebuffer_size(
            self.__handle)

        vidmode = glfw.get_video_mode(glfw.get_primary_monitor())
        Renderer.screenStats.refreshRate = vidmode.refresh_rate
        Renderer.screenStats.vsync = spec.vsync
Exemplo n.º 3
0
def start(mode, flags):
    global _window
    global _mode
    global _flags

    monitor = None
    if (flags["fullscreen"]):
        monitor = glfw.get_primary_monitor()

    _mode = mode
    _flags = flags

    _window = glfw.create_window(mode["width"], mode["height"], "Gravithaum",
                                 monitor, None)
    if not _window:
        glfw.terminate()
        raise "couldn't create window"

    glfw.make_context_current(_window)
    glfw.swap_interval(1)

    resize(_window, mode["width"], mode["height"])
    glfw.set_framebuffer_size_callback(_window, resize)

    gl.glEnable(gl.GL_POINT_SMOOTH)
Exemplo n.º 4
0
def _glfw_init(width=0, height=0):
    window_name = 'pliky'

    if not glfw.init():
        print("Could not initialize OpenGL context")
        exit(1)

    mode = glfw.get_video_mode(glfw.get_primary_monitor())
    if width == 0 or height == 0:
        width = mode.size.width / 2 if width == 0 else width
        height = mode.size.height / 2 if height == 0 else height

    # 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.DECORATED, False)

    glfw.window_hint(glfw.OPENGL_FORWARD_COMPAT, gl.GL_TRUE)

    print(f'Window width: {width}, height: {height}')
    # 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 window:
        glfw.set_window_pos(window, int((mode.size.width - width) / 2),
                            int((mode.size.height - height) / 2))
    else:
        glfw.terminate()
        print("Could not initialize Window")
        exit(1)

    return window
Exemplo n.º 5
0
    def __init__(self):
        super().__init__()

        if not glfw.init():
            raise ValueError("Failed to initialize glfw")

        self.check_glfw_version()

        glfw.window_hint(glfw.CONTEXT_VERSION_MAJOR, self.gl_version.major)
        glfw.window_hint(glfw.CONTEXT_VERSION_MINOR, self.gl_version.minor)
        glfw.window_hint(glfw.OPENGL_PROFILE, glfw.OPENGL_CORE_PROFILE)
        glfw.window_hint(glfw.OPENGL_FORWARD_COMPAT, True)
        glfw.window_hint(glfw.RESIZABLE, self.resizable)
        glfw.window_hint(glfw.DOUBLEBUFFER, True)
        glfw.window_hint(glfw.DEPTH_BITS, 24)
        glfw.window_hint(glfw.SAMPLES, self.samples)

        monitor = None
        if self.fullscreen:
            # Use the primary monitors current resolution
            monitor = glfw.get_primary_monitor()
            mode = glfw.get_video_mode(monitor)

            self.width, self.height = mode.size.width, mode.size.height
            print("picked fullscreen mode:", mode)

        print("Window size:", self.width, self.height)
        self.window = glfw.create_window(self.width, self.height, self.title,
                                         monitor, None)

        if not self.window:
            glfw.terminate()
            raise ValueError("Failed to create window")

        if not self.cursor:
            glfw.set_input_mode(self.window, glfw.CURSOR, glfw.CURSOR_DISABLED)

        # Get the actual buffer size of the window
        # This is important for some displays like Apple's Retina as reported window sizes are virtual
        self.buffer_width, self.buffer_height = glfw.get_framebuffer_size(
            self.window)
        print("Frame buffer size:", self.buffer_width, self.buffer_height)
        print("Actual window size:", glfw.get_window_size(self.window))

        glfw.make_context_current(self.window)

        # The number of screen updates to wait from the time glfwSwapBuffers
        # was called before swapping the buffers and returning
        if self.vsync:
            glfw.swap_interval(1)

        glfw.set_key_callback(self.window, self.key_event_callback)
        glfw.set_cursor_pos_callback(self.window, self.mouse_event_callback)
        glfw.set_window_size_callback(self.window, self.window_resize_callback)

        # Create mederngl context from existing context
        self.ctx = moderngl.create_context(require=self.gl_version.code)
        context.WINDOW = self
        self.fbo = self.ctx.screen
        self.set_default_viewport()
Exemplo n.º 6
0
    def __init__(self, width=640, height=480, fullscreen=False, aspect=None):
        self.gl = gl
        if not glfw.init():
            raise Exception("GLFW init failed")

        glfw.window_hint(glfw.CLIENT_API, glfw.OPENGL_ES_API)
        glfw.window_hint(glfw.CONTEXT_VERSION_MAJOR, 2)
        glfw.window_hint(glfw.CONTEXT_VERSION_MINOR, 0)
        glfw.window_hint(glfw.CONTEXT_VERSION_MINOR, 0)
        glfw.window_hint(glfw.DOUBLEBUFFER, True)
        glfw.window_hint(glfw.DEPTH_BITS, 24)
        glfw.window_hint(glfw.ALPHA_BITS, 0)
        if platform.system() == "Linux":
            try:
                glfw.window_hint(GLFW_CONTEXT_CREATION_API, GLFW_EGL_CONTEXT_API)
            except:
                pass

        monitor = glfw.get_primary_monitor() if fullscreen else None
        self.window = glfw.create_window(width, height, "BlitzLoop Karaoke",
                                         monitor, None)
        self.x = 0
        self.y = 0
        glfw.make_context_current(self.window)
        BaseDisplay.__init__(self, width, height, fullscreen, aspect)
        self._on_reshape(self.window, width, height)
        if fullscreen:
            self.saved_size = (0, 0, width, height)
            glfw.set_input_mode(self.window, glfw.CURSOR, glfw.CURSOR_HIDDEN)

        glfw.set_key_callback(self.window, self._on_keyboard)
        glfw.set_window_pos_callback(self.window, self._on_move)
        glfw.set_window_size_callback(self.window, self._on_reshape)

        self._initialize()
Exemplo n.º 7
0
    def __init__ (self, Module, Title, Width, Height):
        global Pyron
        Pyron = Module

        self.Module = Module
        self.Title = Title
        self.Width = Width
        self.Height = Height

        # Change the FPS later idk
        FPS = 100
        self._NextUpdateTime = 0
        self._OneFrameTime = 1 / FPS
        self._Update = None
        self._Draw = None

        Monitor = glfw.get_primary_monitor ()
        DisplayWidth, DisplayHeight = glfw.get_video_mode (Monitor)[0]

        self._Window = glfw.create_window (_Width, _Height, _Title, None, None)
        if not self._Window:
            glfw.terminate ()

        glfw.set_window_pos (
            self._Window,
            (DisplayWidth - _Width) // 2,
            (DisplayHeight - _Height) // 2
        )
Exemplo n.º 8
0
 def init_window(self):
     window_width, window_height = glfw.get_window_size(self.window)
     _, _, center_x, center_y = glfw.get_monitor_workarea(
         glfw.get_primary_monitor())
     window_x = (center_x // 2) - (window_width // 2)
     window_y = (center_y // 2) - (window_height // 2)
     glfw.set_window_pos(self.window, window_x, window_y)
Exemplo n.º 9
0
    def __init__(self, **kwargs):
        super().__init__(**kwargs)

        if not glfw.init():
            raise ValueError("Failed to initialize glfw")

        # Configure the OpenGL context
        glfw.window_hint(glfw.CONTEXT_CREATION_API, glfw.NATIVE_CONTEXT_API)
        glfw.window_hint(glfw.CLIENT_API, glfw.OPENGL_API)
        glfw.window_hint(glfw.CONTEXT_VERSION_MAJOR, self.gl_version[0])
        glfw.window_hint(glfw.CONTEXT_VERSION_MINOR, self.gl_version[1])
        glfw.window_hint(glfw.OPENGL_PROFILE, glfw.OPENGL_CORE_PROFILE)
        glfw.window_hint(glfw.OPENGL_FORWARD_COMPAT, True)
        glfw.window_hint(glfw.RESIZABLE, self.resizable)
        glfw.window_hint(glfw.DOUBLEBUFFER, True)
        glfw.window_hint(glfw.DEPTH_BITS, 24)
        glfw.window_hint(glfw.SAMPLES, self.samples)

        monitor = None
        if self.fullscreen:
            monitor = glfw.get_primary_monitor()
            mode = glfw.get_video_mode(monitor)
            self._width, self._height = mode.size.width, mode.size.height

            glfw.window_hint(glfw.RED_BITS, mode.bits.red)
            glfw.window_hint(glfw.GREEN_BITS, mode.bits.green)
            glfw.window_hint(glfw.BLUE_BITS, mode.bits.blue)
            glfw.window_hint(glfw.REFRESH_RATE, mode.refresh_rate)

        self._window = glfw.create_window(self.width, self.height, self.title,
                                          monitor, None)

        if not self._window:
            glfw.terminate()
            raise ValueError("Failed to create window")

        if not self.cursor:
            glfw.set_input_mode(self._window, glfw.CURSOR,
                                glfw.CURSOR_DISABLED)

        self._buffer_width, self._buffer_height = glfw.get_framebuffer_size(
            self._window)
        glfw.make_context_current(self._window)

        if self.vsync:
            glfw.swap_interval(1)

        glfw.set_key_callback(self._window, self.glfw_key_event_callback)
        glfw.set_cursor_pos_callback(self._window,
                                     self.glfw_mouse_event_callback)
        glfw.set_mouse_button_callback(self._window,
                                       self.glfw_mouse_button_callback)
        glfw.set_window_size_callback(self._window,
                                      self.glfw_window_resize_callback)

        if self._create_mgl_context:
            self.init_mgl_context()

        self.set_default_viewport()
def get_screen_coordinates_per_inch():
    primary_monitor = glfw.get_primary_monitor()
    primary_monitor_mode = glfw.get_video_mode(primary_monitor)
    primary_monitor_width_mm = ffi.new('int*')
    glfw.get_monitor_physical_size(primary_monitor, primary_monitor_width_mm,
                                   ffi.NULL)
    if primary_monitor_width_mm[0] == 0:
        return kdp_per_inch
    return primary_monitor_mode.width / (primary_monitor_width_mm[0] / 25.4)
Exemplo n.º 11
0
    def __init__(self, **kwargs):
        super().__init__(**kwargs)

        if not glfw.init():
            raise ValueError("Failed to initialize glfw")

        # Configure the OpenGL context
        glfw.window_hint(glfw.CONTEXT_CREATION_API, glfw.NATIVE_CONTEXT_API)
        glfw.window_hint(glfw.CLIENT_API, glfw.OPENGL_API)
        glfw.window_hint(glfw.CONTEXT_VERSION_MAJOR, self.gl_version[0])
        glfw.window_hint(glfw.CONTEXT_VERSION_MINOR, self.gl_version[1])
        glfw.window_hint(glfw.OPENGL_PROFILE, glfw.OPENGL_CORE_PROFILE)
        glfw.window_hint(glfw.OPENGL_FORWARD_COMPAT, True)
        glfw.window_hint(glfw.RESIZABLE, self.resizable)
        glfw.window_hint(glfw.DOUBLEBUFFER, True)
        glfw.window_hint(glfw.DEPTH_BITS, 24)
        glfw.window_hint(glfw.SAMPLES, self.samples)

        monitor = None
        if self.fullscreen:
            # Use the primary monitors current resolution
            monitor = glfw.get_primary_monitor()
            mode = glfw.get_video_mode(monitor)
            self.width, self.height = mode.size.width, mode.size.height

            # Make sure video mode switching will not happen by
            # matching the desktops current video mode
            glfw.window_hint(glfw.RED_BITS, mode.bits.red)
            glfw.window_hint(glfw.GREEN_BITS, mode.bits.green)
            glfw.window_hint(glfw.BLUE_BITS, mode.bits.blue)
            glfw.window_hint(glfw.REFRESH_RATE, mode.refresh_rate)

        self.window = glfw.create_window(self.width, self.height, self.title, monitor, None)

        if not self.window:
            glfw.terminate()
            raise ValueError("Failed to create window")

        if not self.cursor:
            glfw.set_input_mode(self.window, glfw.CURSOR, glfw.CURSOR_DISABLED)

        self.buffer_width, self.buffer_height = glfw.get_framebuffer_size(self.window)
        glfw.make_context_current(self.window)

        if self.vsync:
            glfw.swap_interval(1)

        glfw.set_key_callback(self.window, self.key_event_callback)
        glfw.set_cursor_pos_callback(self.window, self.mouse_event_callback)
        glfw.set_mouse_button_callback(self.window, self.mouse_button_callback)
        glfw.set_window_size_callback(self.window, self.window_resize_callback)

        self.ctx = moderngl.create_context(require=self.gl_version_code)
        self.print_context_info()
        self.set_default_viewport()
Exemplo n.º 12
0
    def start(self):
        if not glfw.init():
            return

        glfw.window_hint(glfw.SAMPLES, 4)

        # try stereo if refresh rate is at least 100Hz
        window = None
        stereo_available = False

        _, _, refresh_rate = glfw.get_video_mode(glfw.get_primary_monitor())
        if refresh_rate >= 100:
            glfw.window_hint(glfw.STEREO, 1)
            window = glfw.create_window(500, 500, "Simulate", None, None)
            if window:
                stereo_available = True

        # no stereo: try mono
        if not window:
            glfw.window_hint(glfw.STEREO, 0)
            window = glfw.create_window(500, 500, "Simulate", None, None)

        if not window:
            glfw.terminate()
            return

        self.running = True

        # Make the window's context current
        glfw.make_context_current(window)

        width, height = glfw.get_framebuffer_size(window)
        width1, height = glfw.get_window_size(window)
        self._scale = width * 1.0 / width1

        self.window = window

        mjlib.mjv_makeObjects(byref(self.objects), 1000)

        mjlib.mjv_defaultCamera(byref(self.cam))
        mjlib.mjv_defaultOption(byref(self.vopt))
        mjlib.mjr_defaultOption(byref(self.ropt))

        mjlib.mjr_defaultContext(byref(self.con))

        if self.model:
            mjlib.mjr_makeContext(self.model.ptr, byref(self.con), 150)
            self.autoscale()
        else:
            mjlib.mjr_makeContext(None, byref(self.con), 150)

        glfw.set_cursor_pos_callback(window, self.handle_mouse_move)
        glfw.set_mouse_button_callback(window, self.handle_mouse_button)
        glfw.set_scroll_callback(window, self.handle_scroll)
Exemplo n.º 13
0
    def start(self):
        if not glfw.init():
            return

        glfw.window_hint(glfw.SAMPLES, 4)

        # try stereo if refresh rate is at least 100Hz
        window = None
        stereo_available = False

        _, _, refresh_rate = glfw.get_video_mode(glfw.get_primary_monitor())
        if refresh_rate >= 100:
            glfw.window_hint(glfw.STEREO, 1)
            window = glfw.create_window(500, 500, "Simulate", None, None)
            if window:
                stereo_available = True

        # no stereo: try mono
        if not window:
            glfw.window_hint(glfw.STEREO, 0)
            window = glfw.create_window(500, 500, "Simulate", None, None)

        if not window:
            glfw.terminate()
            return

        self.running = True

        # Make the window's context current
        glfw.make_context_current(window)

        width, height = glfw.get_framebuffer_size(window)
        width1, height = glfw.get_window_size(window)
        self.scale = width * 1.0 / width1

        self.window = window

        mjlib.mjv_makeObjects(byref(self.objects), 1000)

        mjlib.mjv_defaultCamera(byref(self.cam))
        mjlib.mjv_defaultOption(byref(self.vopt))
        mjlib.mjr_defaultOption(byref(self.ropt))

        mjlib.mjr_defaultContext(byref(self.con))

        if self.model:
            mjlib.mjr_makeContext(self.model.ptr, byref(self.con), 150)
            self.autoscale()
        else:
            mjlib.mjr_makeContext(None, byref(self.con), 150)

        glfw.set_cursor_pos_callback(window, self.handle_mouse_move)
        glfw.set_mouse_button_callback(window, self.handle_mouse_button)
        glfw.set_scroll_callback(window, self.handle_scroll)
Exemplo n.º 14
0
    def __init__(
        self,
        size_pix=(760, 760),
        colour=(0.5, 0.5, 0.5),
        event_buffer_size=20,
        gamma=None,
        close_on_exit=True,
        global_quit=True,
    ):

        self._global_quit = global_quit

        self.close_on_exit = close_on_exit

        self._event_buffer = collections.deque(maxlen=event_buffer_size)

        glfw.init()

        glfw.window_hint(glfw.CONTEXT_VERSION_MAJOR, 3)
        glfw.window_hint(glfw.CONTEXT_VERSION_MINOR, 3)
        glfw.window_hint(glfw.OPENGL_FORWARD_COMPAT, 1)

        glfw.window_hint(glfw.DOUBLEBUFFER, glfw.TRUE)

        self.monitor = glfw.get_primary_monitor()

        self._orig_gamma = glfw.get_gamma_ramp(self.monitor)

        if gamma is not None:
            glfw.set_gamma(monitor=self.monitor, gamma=gamma)

        self.win = glfw.create_window(
            width=size_pix[0],
            height=size_pix[1],
            title="window",
            monitor=None,
            share=None,
        )

        glfw.make_context_current(self.win)

        glfw.swap_interval(0)

        glfw.set_key_callback(self.win, self.key_event_callback)

        glfw.set_window_close_callback(self.win, self.window_close_callback)

        self.colour = colour

        self.flip()

        glfw.set_time(0.0)

        self.nests = 0
Exemplo n.º 15
0
    def __CreateWindowFullscreen(self, spec):
        mon = glfw.get_primary_monitor()
        mode = glfw.get_video_mode(mon)

        glfw.window_hint(glfw.RED_BITS, mode.bits.red)
        glfw.window_hint(glfw.GREEN_BITS, mode.bits.green)
        glfw.window_hint(glfw.BLUE_BITS, mode.bits.blue)
        glfw.window_hint(glfw.REFRESH_RATE, mode.refresh_rate)

        return glfw.create_window(spec.width, spec.height, self.baseTitle, mon,
                                  None)
Exemplo n.º 16
0
 def __init__(self, name, width, height, fullscreen=False):
     if not glfw.init():
         raise GlfwError("Could not initialize GLFW")
     monitor = glfw.get_primary_monitor() if fullscreen else None
     self.win = glfw.create_window(width, height, name, monitor, None)
     if not self.win:
         glfw.terminate()
         raise GlfwError("Could not create GLFW window")
     glfw.make_context_current(self.win)
     glfw.set_key_callback(self.win, self.key_cb)
     self.key_callbacks = []
Exemplo n.º 17
0
    def _toggle_fullscreen(self):
        if glfw.get_window_monitor(self._window):  # fullscreen to window
            glfw.set_window_monitor(self._window, None, *self._window_info, 0)
        else:  # window to fullscreen
            info = [0] * 4
            info[0], info[1] = glfw.get_window_pos(self._window)
            info[2], info[3] = glfw.get_window_size(self._window)
            self._window_info = info

            monitor = glfw.get_primary_monitor()
            size = glfw.get_video_mode(monitor)[0]
            glfw.set_window_monitor(self._window, monitor, 0, 0, *size, 0)
Exemplo n.º 18
0
 def set_pos(self, x=None, y=None):
     '设置窗口位置'
     if self.window is None:
         return
     if x is None or x is None:
         ws = glfw.get_window_size(self.window)
         ma = glfw.get_monitor_workarea(glfw.get_primary_monitor())
         if x is None:
             x = (ma[2] - ws[0]) // 2
         if y is None:
             y = (ma[3] - ws[1]) // 2
     glfw.set_window_pos(self.window, x, y)
    def createDefaultConfig(overwrite=True):

        # We retrieve the user's screen resolution using the GLFW library
        width = 576
        height = 384
        import glfw
        glfw.init()
        vm = glfw.get_video_modes(glfw.get_primary_monitor())
        nvm = len(vm) - 1
        monitorRes = [vm[nvm][0][0], vm[nvm][0][1]]

        # We choose the highest resolution that can support the screen
        baseRes = [
            576, 384
        ]  # The minimum game display resolution (18 tiles * 32 pixels and 12 tiles * 32 pixels)
        for factor in range(
                1, 10
        ):  # Test differents zoom factors to find the maximum that can be used
            if (baseRes[0] * factor < monitorRes[0]
                    and baseRes[1] * factor < monitorRes[1]):
                width = baseRes[0] * factor
                height = baseRes[1] * factor

        # We retrieve the user's locale
        import locale
        userLanguage = locale.getdefaultlocale()[0][:2]
        languages = [['en', 'English'], ['fr', 'Français']]
        language = "en"
        # We choose the locale if present in the game, otherwise, we take the default one (English)
        for lang in languages:
            if lang[0] == userLanguage: language = lang[0]

        # We set the values for the configuration
        Config.values = {
            "general": {
                "language": language,
                "debug": False
            },
            "window": {
                "limFrameRate": 0,
                "fullScreen": 0,
                "width": width,
                "height": height
            },
            "audio": {
                "musicVolume": 0.5,
                "soundsVolume": 0.5
            }
        }

        # We overwrite the configuration if needed
        if overwrite: Config.saveConfig()
Exemplo n.º 20
0
    def toggle_fullscreen(self):
        if self.fullscreen:
            glfw.set_window_monitor(self.window, None, *self.saved_size,
                                    util.get_opts().fps)
        else:
            self.saved_size = self.x, self.y, self.win_width, self.win_height
            monitor = glfw.get_primary_monitor()
            mode = glfw.get_video_mode(monitor)
            glfw.set_window_monitor(self.window, monitor, 0, 0,
                                    mode.size.width, mode.size.height,
                                    mode.refresh_rate)

        self.fullscreen = not self.fullscreen
Exemplo n.º 21
0
    def toggle_fullscreen(self):
        if self.fullscreen:
            glfw.set_window_monitor(self.window, None, *self.saved_size,
                                    util.get_opts().fps)
        else:
            self.saved_size = self.x, self.y, self.win_width, self.win_height
            monitor = glfw.get_primary_monitor()
            mode = glfw.get_video_mode(monitor)
            glfw.set_window_monitor(self.window, monitor, 0, 0,
                                    mode.size.width, mode.size.height,
                                    mode.refresh_rate)

        self.fullscreen = not self.fullscreen
Exemplo n.º 22
0
    def __init__(self, window):
        super(Client, self).__init__()
        self.window = window

        self._is_drag = False
        self._pre_cursor = ivec2(0, 0)

        monitor = glfw.get_primary_monitor()
        x, y, w, h = glfw.get_monitor_workarea(monitor)
        ww, wh = glfw.get_window_size(window)
        glfw.set_window_pos(window, (w >> 1) - (ww >> 1), (h >> 1) - (wh >> 1))

        glfw.set_mouse_button_callback(window, self.on_mouse_button)
        glfw.set_cursor_pos_callback(window, self.on_cursor_pos)
Exemplo n.º 23
0
 def create_window(self, name='Berry Engine Viewport', x=640, y=480, fullscreen=False):
     self.name=name
     if not glfw.init():
         self.alive=False
         return
     if fullscreen == True:
         self.win=glfw.create_window(x, y, name, glfw.get_primary_monitor(), None)
     else:
         self.win=glfw.create_window(x, y, name, None, None)
     glfw.make_context_current(self.win)
     self.ctx=gl.create_context(require=self.req)
     if not self.win:
         glfw.terminate()
         self.alive=False
         return
Exemplo n.º 24
0
def main():
    glfw.init()
    glfw.window_hint(glfw.FLOATING, glfw.TRUE)
    glfw.window_hint(glfw.DECORATED, glfw.FALSE)
    window = glfw.create_window(WIDTH, HEIGHT, TITLE, None, None)
    m = glfw.get_primary_monitor()
    x, y, w, h = glfw.get_monitor_workarea(m)
    glfw.set_window_pos(window, w // 2 - WIDTH // 2, h // 2 - HEIGHT // 2)
    glfw.make_context_current(window)
    client = RenderClient(window)

    while not glfw.window_should_close(window):
        glfw.poll_events()
        glfw.swap_buffers(window)
        client.update()
Exemplo n.º 25
0
    def __init__(self, window):
        super(Client, self).__init__()

        self.window = window

        m = glfw.get_primary_monitor()
        _, _, w, h = glfw.get_monitor_workarea(m)
        ww, hh = glfw.get_window_size(window)
        glfw.set_window_pos(window, w // 2 - ww // 2, h // 2 - hh // 2)

        self._isdrag = False
        self._prevpos = ivec2(0, 0)

        glfw.set_mouse_button_callback(window, self.on_mouse_button)
        glfw.set_cursor_pos_callback(window, self.on_cursor_pos)
Exemplo n.º 26
0
def main():
    WIDTH, HEIGHT = 400, 400
    glfw.init()
    glfw.window_hint(glfw.DECORATED, glfw.FALSE)
    glfw.window_hint(glfw.FLOATING, glfw.TRUE)
    window = glfw.create_window(WIDTH, HEIGHT, "", None, None)
    monitor = glfw.get_primary_monitor()
    x, y, w, h = glfw.get_monitor_workarea(monitor)
    glfw.set_window_pos(window, (w >> 1) - (WIDTH >> 1),
                        (h >> 1) - (HEIGHT >> 1))
    glfw.make_context_current(window)
    client = Client(window)
    while not glfw.window_should_close(window):
        glfw.swap_buffers(window)
        glfw.poll_events()
        client.update()
Exemplo n.º 27
0
    def open_output_window(self):
        self._pause_event_loop()

        # Select monitor
        self._select_monitor()

        # Open window
        if self.monitor:
            # Fullscreen
            self._select_video_mode()
            x, y = glfw.get_monitor_pos(self.monitor)
            logger.info("Output selected : {} on {} at {},{}".format(
                str(self.video_mode), glfw.get_monitor_name(self.monitor), x,
                y))
            w, h = self.video_mode[0]
            self.pano_renderer.setViewport(w, h)
            self.pano_renderer.setRefreshRate(
                self._convert_rate(30), self._convert_rate(self.video_mode[2]))
            if self.output_window:
                glfw.set_window_monitor(self.output_window, self.monitor, x, y,
                                        w, h, self.video_mode[2])
                glfw.show_window(self.output_window)
                self.pano_renderer.enableOutput(True)
            else:
                self._open_output_window(w, h, self.monitor, self.video_mode)
        else:
            # No monitor available or windowed
            w = self.width / 4
            h = self.height / 4
            self.pano_renderer.setViewport(w, h)

            monitor = glfw.get_primary_monitor()
            if monitor:
                rate = glfw.get_video_mode(monitor)[2]
                self.pano_renderer.setRefreshRate(self._convert_rate(30),
                                                  self._convert_rate(rate))

            if self.output_window:
                self.pano_renderer.enableOutput(True)
                glfw.show_window(self.output_window)
            else:
                self._open_output_window(w, h)
                if not SETTINGS.display in ["window", "windowed"]:
                    # No monitor available
                    glfw.hide_window(self.output_window)

        self._unpause_event_loop()
Exemplo n.º 28
0
def main():
    width, height = 800, 800

    glfw.init()
    glfw.window_hint(glfw.FLOATING, glfw.TRUE)
    glfw.window_hint(glfw.DECORATED, glfw.FALSE)
    window = glfw.create_window(width, height, "", None, None)
    glfw.make_context_current(window)
    monitor = glfw.get_primary_monitor()
    _, _, w, h = glfw.get_monitor_workarea(monitor)
    glfw.set_window_pos(window, w - width, h - height)

    client = Client(window)
    while not glfw.window_should_close(window):
        client.update()
        glfw.poll_events()
        glfw.swap_buffers(window)
Exemplo n.º 29
0
    def run(self, width, height, resizable, title, background_color):
        self.init_glfw()
        glfw.window_hint(glfw.RESIZABLE, resizable)
        window = glfw.create_window(width, height, title, None, None)
        self.window = window
        self.refresh_rate = glfw.get_video_mode(
            glfw.get_primary_monitor()).refresh_rate
        glfw.make_context_current(window)
        glfw.swap_interval(1)  # vsync

        glfw.set_key_callback(window, self.key_callback)
        glfw.set_mouse_button_callback(window, self.mouse_button_callback)
        glfw.set_framebuffer_size_callback(window,
                                           self.framebuffer_size_callback)
        glfw.set_monitor_callback(self.monitor_callback)

        self.reset_canvas_size(*glfw.get_framebuffer_size(window))
        self.monitor_callback()
        self.change_background_color(background_color)

        context = self.drawy_module
        context.FRAME = 0
        self.sync_context_with_main()
        self.reload_module(self.main_module)

        try:
            self.call_from_main("init", [], reraise=True)
        except:
            return

        while not glfw.window_should_close(window):
            self.reload_main_if_modified()
            canvas = context._canvas
            context.MOUSE_POSITION = context.Point(
                *glfw.get_cursor_pos(window))
            canvas.clear(self.background_color)
            self.sync_context_with_main()
            self.draw_frame()

            canvas.flush()
            glfw.swap_buffers(window)
            glfw.poll_events()
            context.FRAME += 1

        self.gpu_context.abandonContext()
        glfw.terminate()
Exemplo n.º 30
0
def init():
    if not glfw.init():
        return
    # Create window
    m = glfw.get_primary_monitor()
    mode = glfw.get_video_mode(m)
    width = mode.size.width
    height = mode.size.height

    window = glfw.create_window(width, height, "Fractals", None, None)
    if not window:
        glfw.terminate()
        exit(0)
    glfw.make_context_current(window)
    impl = GlfwRenderer(window)
    #compile shaders
    try:
        mandelbrot_shader = from_files_names("fractal_v.glsl",
                                             "mandelbrot_f.glsl")
        julia_shader = from_files_names("fractal_v.glsl", "julia_f.glsl")
        newton_shader = from_files_names("fractal_v.glsl", "newton_f.glsl")
    except ShaderCompilationError as e:
        print(e.logs)
        exit()
    #setup data used for window and shaders
    window_dict = {
        'width': width,
        'height': height,
        'n_iter': 100,
        'b': 2,
        'scalar': 4.5,
        'x_off': 0,
        'y_off': 0
    }
    window_dict = struct(window_dict)
    #setep callback so they can change local variables
    glfw.set_key_callback(window,
                          lambda *args: key_callback(window_dict, *args))
    glfw.set_window_size_callback(
        window, lambda *args: window_size_callback(window_dict, *args))
    #quad we are drawing to
    quad = pyglet.graphics.vertex_list(
        4, ('v2f', (-1.0, -1.0, -1.0, 1.0, 1.0, -1.0, 1.0, 1.0)))
    return window, window_dict, impl, quad, mandelbrot_shader, julia_shader, newton_shader
Exemplo n.º 31
0
    def create_window(self, name, width, height,
                      hints=DEFAULT_WINDOW_HINTS, units='framebuffer'):

        assert units in ['framebuffer', 'window']

        create_window_size = numpy.array([width, height])
        
        if units == 'framebuffer':

            try:
                monitor = glfw.get_primary_monitor()
                monitor_scale = glfw.get_monitor_content_scale(monitor)
                print('detected monitor_scale', monitor_scale)
            except:
                monitor_scale = (1.0, 1.0)

                create_window_size = numpy.round(
                    create_window_size / monitor_scale).astype(numpy.int32)
        
        for hint, value in hints:
            glfw.window_hint(hint, value)
        
        self.window = glfw.create_window(
            create_window_size[0], create_window_size[1],
            name, None, None)

        if not self.window:
            print("create_window failed")
            glfw.terminate()
            sys.exit(1)
            
        self.window_size[:] = glfw.get_window_size(self.window)

        glfw.make_context_current(self.window)

        self._framebuffer_size_updated()

        glfw.set_key_callback(self.window, self._key_callback)
        glfw.set_window_size_callback(self.window, self._window_size_callback)
        glfw.set_cursor_pos_callback(self.window, self._cursor_pos_callback)
        glfw.set_mouse_button_callback(self.window, self._mouse_button_callback)

        check_opengl_errors('setup window')
Exemplo n.º 32
0
    def __init__(self, model, data):
        self._gui_lock = Lock()
        self._button_left_pressed = False
        self._button_right_pressed = False
        self._last_mouse_x = 0
        self._last_mouse_y = 0
        self._paused = False
        self._transparent = False
        self._contacts = False
        self._render_every_frame = True
        self._image_idx = 0
        self._image_path = "/tmp/frame_%07d.png"
        self._time_per_render = 1 / 60.0
        self._run_speed = 1.0
        self._loop_count = 0
        self._advance_by_one_step = False
        self._hide_menu = False

        # glfw init
        glfw.init()
        width, height = glfw.get_video_mode(glfw.get_primary_monitor()).size
        self.window = glfw.create_window(width // 2, height // 2, "mujoco",
                                         None, None)
        glfw.make_context_current(self.window)
        glfw.swap_interval(1)

        framebuffer_width, framebuffer_height = glfw.get_framebuffer_size(
            self.window)
        window_width, _ = glfw.get_window_size(self.window)
        self._scale = framebuffer_width * 1.0 / window_width

        # set callbacks
        glfw.set_cursor_pos_callback(self.window, self._cursor_pos_callback)
        glfw.set_mouse_button_callback(self.window,
                                       self._mouse_button_callback)
        glfw.set_scroll_callback(self.window, self._scroll_callback)
        glfw.set_key_callback(self.window, self._key_callback)

        # get viewport
        self.viewport = mujoco.MjrRect(0, 0, framebuffer_width,
                                       framebuffer_height)

        super().__init__(model, data, offscreen=False)
Exemplo n.º 33
0
        def open(self, title, width=1024, height=768, fullscreen=False):
            'glfw环境创建应用窗口'
            if self.window is not None:
                return self.window

            # 使用glfw创建窗口句柄
            self.window = glfw.create_window(
                int(width), int(height), title,
                glfw.get_primary_monitor() if fullscreen else None, None)

            if not self.window:
                # 创建失败直接退出
                glfw.terminate()
                print("glfw Could not initialize Window")
                exit(1)

            # 绑定窗口对象为当前绘图环境
            glfw.make_context_current(self.window)
            return self.window
Exemplo n.º 34
0
def init_window():
    def 超融合():
        glfw.window_hint(glfw.DECORATED, False)
        glfw.window_hint(glfw.TRANSPARENT_FRAMEBUFFER, True)
        glfw.window_hint(glfw.FLOATING, True)
    glfw.init()
    超融合()
    glfw.window_hint(glfw.SAMPLES, 4)
    # glfw.window_hint(glfw.RESIZABLE, False)
    window = glfw.create_window(*Vtuber尺寸, 'Vtuber', None, None)
    glfw.make_context_current(window)
    monitor_size = glfw.get_video_mode(glfw.get_primary_monitor()).size
    glfw.set_window_pos(window, monitor_size.width - Vtuber尺寸[0], monitor_size.height - Vtuber尺寸[1])
    glViewport(0, 0, *Vtuber尺寸)
    glEnable(GL_TEXTURE_2D)
    glEnable(GL_BLEND)
    glEnable(GL_MULTISAMPLE)
    glEnable(GL_CULL_FACE)
    glCullFace(GL_FRONT)
    glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA)
    return window
Exemplo n.º 35
0
    def _set_fullscreen(self, value: bool) -> None:
        monitor = glfw.get_primary_monitor()
        mode = glfw.get_video_mode(monitor)
        refresh_rate = mode.refresh_rate if self.vsync else glfw.DONT_CARE
        self.resizable = not value
        glfw.window_hint(glfw.RESIZABLE, self.resizable)

        if value:
            # enable fullscreen
            self._non_fullscreen_size = self.width, self.height
            self._non_fullscreen_position = self.position
            glfw.set_window_monitor(
                self._window,
                monitor,
                0,
                0,
                mode.size.width,
                mode.size.height,
                refresh_rate,
            )

            glfw.window_hint(glfw.RED_BITS, mode.bits.red)
            glfw.window_hint(glfw.GREEN_BITS, mode.bits.green)
            glfw.window_hint(glfw.BLUE_BITS, mode.bits.blue)
            glfw.window_hint(glfw.REFRESH_RATE, mode.refresh_rate)

        else:
            # disable fullscreen
            glfw.set_window_monitor(
                self._window,
                None,
                *self._non_fullscreen_position,
                *self._non_fullscreen_size,
                refresh_rate
            )

        if self.vsync:
            glfw.swap_interval(1)
        else:
            glfw.swap_interval(0)
Exemplo n.º 36
0
    def start(self):
        logger.info('initializing glfw@%s', glfw.get_version())

        glfw.set_error_callback(_glfw_error_callback)

        if not glfw.init():
            raise Exception('glfw failed to initialize')

        window = None
        if self.visible:
            glfw.window_hint(glfw.SAMPLES, 4)
        else:
            glfw.window_hint(glfw.VISIBLE, 0);

        # try stereo if refresh rate is at least 100Hz
        stereo_available = False

        _, _, refresh_rate = glfw.get_video_mode(glfw.get_primary_monitor())
        if refresh_rate >= 100:
            glfw.window_hint(glfw.STEREO, 1)
            window = glfw.create_window(
                self.init_width, self.init_height, "Simulate", None, None)
            if window:
                stereo_available = True

        # no stereo: try mono
        if not window:
            glfw.window_hint(glfw.STEREO, 0)
            window = glfw.create_window(
                self.init_width, self.init_height, "Simulate", None, None)

        if not window:
            glfw.terminate()
            return

        self.running = True

        # Make the window's context current
        glfw.make_context_current(window)

        self._init_framebuffer_object()

        width, height = glfw.get_framebuffer_size(window)
        width1, height = glfw.get_window_size(window)
        self._scale = width * 1.0 / width1

        self.window = window

        mjlib.mjv_makeObjects(byref(self.objects), 1000)

        mjlib.mjv_defaultCamera(byref(self.cam))
        mjlib.mjv_defaultOption(byref(self.vopt))
        mjlib.mjr_defaultOption(byref(self.ropt))

        mjlib.mjr_defaultContext(byref(self.con))

        if self.model:
            mjlib.mjr_makeContext(self.model.ptr, byref(self.con), 150)
            self.autoscale()
        else:
            mjlib.mjr_makeContext(None, byref(self.con), 150)

        glfw.set_cursor_pos_callback(window, self.handle_mouse_move)
        glfw.set_mouse_button_callback(window, self.handle_mouse_button)
        glfw.set_scroll_callback(window, self.handle_scroll)
Exemplo n.º 37
0
def on_close():
    log("Close (press escape to exit)")
    
    return False
    
    
def on_refresh():
    log("Refresh")
    
    glClear(GL_COLOR_BUFFER_BIT)
    glfw.SwapBuffers()


glfw.init()
pm = glfw.get_primary_monitor()
vms = glfw.get_video_modes( pm )
print("Available video modes:\n%s\n" % "\n".join(map(str, vms)))
vm = glfw.get_video_mode( pm )
print( "Desktop video mode:\n%s\n" % str(vm) )
print( "GLFW Version: %d.%d.%d" % glfw.get_version() )

w = glfw.create_window(800, 600, 'test', None, None)

#print("OpenGL version: %d.%d.%d\n" % glfw.get_gl_version())

#glfw.ext.set_icons([(icon_data, icon_width, icon_height)])
glfw.set_window_title(w, "pyglfw test")
#glfw.disable(w, glfw.AUTO_POLL_EVENTS)
#glfw.enable(w, glfw.KEY_REPEAT)

config_file = open('config.txt', 'r')
ip, port, = open('config.txt', 'r').readline().split()
player_id = registerMe('OpenGL')

t1 = threading.Thread(target=asking, daemon=True).start()
t2 = threading.Thread(target=sending, daemon=True).start()

if not glfw.init():
    exit(0)

glfw.window_hint(glfw.RESIZABLE, GL_FALSE)
glfw.window_hint(glfw.SAMPLES, 8)
window = glfw.create_window(WINDOW_WIDTH, WINDOW_HEIGHT, 'agar.io', None, None)
w, h = glfw.get_video_mode(glfw.get_primary_monitor())[0]
glfw.set_window_pos(window, (w - WINDOW_WIDTH) // 2, (h - WINDOW_HEIGHT) // 2)
glfw.set_cursor_pos_callback(window, on_motion)

if not window:
    glfw.terminate()
    exit(0)

glfw.make_context_current(window)
glfw.swap_interval(1)

glClearColor(1., 1., 1., 1.)
glViewport(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT)
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
gluOrtho2D(0, WINDOW_WIDTH, WINDOW_HEIGHT, 0)