Example #1
0
    def run(self):
        self._callFn("appStarted", self)

        def sizeChanged(window, width, height):
            self.width = width
            self.height = height
            print(f'new size: {width} {height}')
            self.canvas.resize(width, height)
            self._callFn('sizeChanged', self)

        def charEvent(*args):
            self.dispatchCharEvent(*args)

        def keyEvent(*args):
            self.dispatchKeyEvent(*args)

        def mouseMoved(*args):
            self.dispatchMouseMoved(*args)

        def mouseChanged(*args):
            self.dispatchMouseChanged(*args)

        glfw.set_framebuffer_size_callback(self.window, sizeChanged)
        glfw.set_key_callback(self.window, keyEvent)
        glfw.set_char_callback(self.window, charEvent)
        glfw.set_cursor_pos_callback(self.window, mouseMoved)
        glfw.set_mouse_button_callback(self.window, mouseChanged)

        i = 0

        times = [0.0] * 20

        while not glfw.window_should_close(self.window):
            times.pop(0)

            glClearColor(0.2, 0.3, 0.3, 1.0)
            glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)  #type:ignore

            self._callFn('redrawAll', self, self.window, self.canvas)

            self.canvas.redraw()

            if time.time() - self.lastTimer > (self.timerDelay / 1000.0):
                self.lastTimer = time.time()
                self._callFn('timerFired', self)

            glfw.swap_buffers(self.window)
            glfw.poll_events()

            times.append(time.time())

            i += 1

            if i % 50 == 0:
                timeDiff = (times[-1] - times[0]) / (len(times) - 1)
                print(timeDiff)

        self._callFn('appStopped', self)

        glfw.terminate()
def createObj(filePath):
    print filePath
    global gVertexArraySeparate
    if not glfw.init():  #实例化对象
        return
    window = glfw.create_window(640, 640, '3D Obj File Viewer', None,
                                None)  #创建窗口
    if not window:
        glfw.terminate()
        return
    glfw.make_context_current(window)
    glfw.set_key_callback(window, key_callback)
    glfw.set_framebuffer_size_callback(window, framebuffer_size_callback)
    # glfw.set_drop_callback(window, dropCallback)
    dropCallback(window, filePath)
    glfw.swap_interval(1)
    count = 0
    while not glfw.window_should_close(window):
        glfw.poll_events()
        count += 1
        ang = count % 360
        render(ang)
        count += 1
        glfw.swap_buffers(window)
    glfw.terminate()
    def start(self):
        if not glfw.init():
            return

        glfw.window_hint(glfw.FLOATING, glfw.TRUE)
        glfw.window_hint(glfw.RESIZABLE, glfw.TRUE)

        self.u_width, self.u_height = 400, 400
        self.u_volume_size = (64, 64, 64)
        self.window = glfw.create_window(self.u_width, self.u_height,
                                         "pyGLFW window", None, None)
        if not self.window:
            glfw.terminate()
            return

        glfw.make_context_current(self.window)

        self.init()
        self.should_rebuild = False

        glfw.set_framebuffer_size_callback(self.window, self.on_resize_fb)
        glfw.set_key_callback(self.window, self.on_key)

        handler = FileSystemEventHandler()
        handler.on_modified = lambda e: self.set_rebuild(True)
        observer = Observer()
        observer.schedule(handler, "./gl")
        observer.start()
Example #4
0
def main():
    #initialize the library
    if not glfw.init():
        return
    #Create a windowed mode window and its OpenGL context
    window = glfw.create_window(480, 480, "2012004021", None, None)
    if not window:
        glfw.terminate()
        return

    #Make the window's context current
    glfw.make_context_current(window)
    glfw.set_framebuffer_size_callback(window, window_callback)
    glfw.set_key_callback(window, key_callback)
    glfw.swap_interval(1)
    count = 0

    #Loop until the user closes the window
    while not glfw.window_should_close(window):
        #Poll events
        glfw.poll_events()
        render()
        #Swap front and back buffers
        glfw.swap_buffers(window)

    glfw.terminate()
Example #5
0
    def __init__(self, gui=False, width=800, height=600, window_name='opengl'):
        self.width = width
        self.height = height

        if not glfw.init():
            raise RuntimeError('could not init glfw')

        hints = ((glfw.CONTEXT_VERSION_MAJOR, 4),
                 (glfw.CONTEXT_VERSION_MINOR, 5), (glfw.OPENGL_PROFILE,
                                                   glfw.OPENGL_CORE_PROFILE))
        for hint in hints:
            glfw.window_hint(*hint)

        self.window = glfw.create_window(int(self.width), int(self.height),
                                         window_name, None, None)
        glfw.make_context_current(self.window)

        def viewport_func(window, width, height):
            self.width = width
            self.height = height
            self.update_camera(update_proj=True)
            self.ctx.viewport = (0, 0, self.width, self.height)

        glfw.set_framebuffer_size_callback(self.window, viewport_func)

        if not self.window:
            glfw.terminate()
            raise RuntimeError('could not create glfw window')

        self.gui_impl = None
        if gui:
            self.gui_impl = GlfwRenderer(self.window)

        self.ctx = moderngl.create_context()
        self.ctx.viewport = (0, 0, self.width, self.height)
    def __init__(self, *, size=None, title=None):
        super().__init__()

        # Handle inputs
        if not size:
            size = 640, 480
        title = str(title or "")

        # Set window hints
        glfw.window_hint(glfw.CLIENT_API, glfw.NO_API)
        glfw.window_hint(glfw.RESIZABLE, True)
        # see https://github.com/FlorianRhiem/pyGLFW/issues/42
        # Alternatively, from pyGLFW 1.10 one can set glfw.ERROR_REPORTING='warn'
        if sys.platform.startswith("linux"):
            if "wayland" in os.getenv("XDG_SESSION_TYPE", "").lower():
                glfw.window_hint(glfw.FOCUSED, False)  # prevent Wayland focus error

        # Create the window (the initial size may not be in logical pixels)
        self._window = glfw.create_window(int(size[0]), int(size[1]), title, None, None)

        # Register ourselves
        self._need_draw = True
        all_glfw_canvases.add(self)

        # Register callbacks. We may get notified too often, but that's
        # ok, they'll result in a single draw.
        glfw.set_window_content_scale_callback(self._window, self._on_pixelratio_change)
        glfw.set_framebuffer_size_callback(self._window, self._on_size_change)
        glfw.set_window_close_callback(self._window, self._on_close)
        glfw.set_window_refresh_callback(self._window, self._on_window_dirty)
        glfw.set_window_focus_callback(self._window, self._on_window_dirty)
        glfw.set_window_maximize_callback(self._window, self._on_window_dirty)
        # Initialize the size
        self.set_logical_size(*size)
Example #7
0
def main():
    if not glfw.init():
        return

    window = glfw.create_window(640, 640, "2014005014", None, None)

    if not window:
        glfw.terminate()
        return

    glfw.set_key_callback(window, key_callback)
    glfw.make_context_current(window)
    glfw.set_framebuffer_size_callback(window, framebuffer_size)

    glfw.swap_interval(1)

    count = 0

    while not glfw.window_should_close(window):
        glfw.poll_events()

        render()

        glfw.swap_buffers(window)

        count += 1

    glfw.terminate()
Example #8
0
    def createWindow(self):
        self.videomode = glfw.get_video_mode(self.monitor)
        #self.window = glfw.create_window(100, 100, "Pyree Worker (´・ω・ `)", self.monitor, None)    # Fullscreen
        self.window = glfw.create_window(500, 500, "Pyree Worker (´・ω・ `)",
                                         None, None)  # windowed

        self.width, self.height = glfw.get_window_size(self.window)

        #glfw.set_window_size(self.window, self.videomode[0][0], self.videomode[0][1])

        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.make_context_current(self.window)

        glfw.set_framebuffer_size_callback(self.window,
                                           self.framebufferSizeCallback)

        self.fbo = glGenFramebuffers(1)
        glBindFramebuffer(GL_FRAMEBUFFER, self.fbo)
        self.fbotexture = glGenTextures(1)
        glBindTexture(GL_TEXTURE_2D, self.fbotexture)
        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, self.width, self.height, 0,
                     GL_RGBA, GL_UNSIGNED_BYTE, None)

        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)

        glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
                             self.fbotexture, 0)
def main():
    glfw.init()

    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)

    window = glfw.create_window(1280, 720, "LearnOpenGL", None, None)

    if not window:
        print("init window fails")
        glfw.terminate()
        return

    glfw.make_context_current(window)
    glfw.set_framebuffer_size_callback(window, framebuffer_size_callback)

    while not glfw.window_should_close(window):
        process_input(window)

        glClearColor(0.2, 0.3, 0.3, 1.0)
        glClear(GL_COLOR_BUFFER_BIT)

        glfw.swap_buffers(window)
        glfw.poll_events()

    glfw.terminate()
    return
Example #10
0
def main():
    # initialize glfw
    if not glfw.init():
        return

    window = glfw.create_window(800, 600, "LearnOpenGL", None, None)

    if not window:
        glfw.terminate()
        return

    glfw.make_context_current(window)

    glfw.set_framebuffer_size_callback(window, framebuffer_size_callback)

    # render loop
    while not glfw.window_should_close(window):
        # input
        process_input(window)

        # rendering commands here
        glClearColor(0.2, 0.3, 0.3, 1.0)  # state-setting function
        glClear(GL_COLOR_BUFFER_BIT)  # state-using function

        # check and call events and swap the buffers
        glfw.swap_buffers(window)
        glfw.poll_events()
    glfw.terminate()
def main():
    global vertices, window_height, window_width, to_redraw

    if not glfw.init():
        return

    window = glfw.create_window(400, 400, "Lab4", None, None)
    if not window:
        glfw.terminate()
        return

    glfw.make_context_current(window)
    glfw.set_key_callback(window, key_callback)
    glfw.set_framebuffer_size_callback(window, resize_callback)

    glfw.set_mouse_button_callback(window, mouse_button_callback)
    glEnable(GL_DEPTH_TEST)
    glDepthFunc(GL_LESS)
    glClearColor(0, 0, 0, 0)

    while not glfw.window_should_close(window):
        # print(vertices)
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)

        draw()

        glfw.swap_buffers(window)
        glfw.poll_events()

    glfw.destroy_window(window)
    glfw.terminate()
def create_flutter_window(initial_width, initial_height, main_path,
                          assets_path, packages_path, icu_data_path):
    """window"""
    window = glfw.create_window(initial_width, initial_height, "Flutter", None,
                                None)
    if not window:
        return None
    """engine"""
    engine = run_flutter_engine(window, main_path, assets_path, packages_path,
                                icu_data_path)
    if not engine:
        return None
    """state"""
    state = ffi.new('FlutterEmbedderState*')
    """防止state被gc掉"""
    flutter_global.prevent_gc(state)
    flutter_global.get_text_model().notifyState = lambda: update_editing_state(
        window)
    state.engine = engine
    glfw.set_window_user_pointer(window, state)
    state.monitor_screen_coordinates_per_inch = get_screen_coordinates_per_inch(
    )
    width_px = ffi.new('int*')
    height_px = ffi.new('int*')
    glfw.get_framebuffer_size(window, width_px, height_px)
    glfw.set_framebuffer_size_callback(window, glfw_framebuffer_size_callback)
    glfw_framebuffer_size_callback(window, width_px[0], height_px[0])

    glfw_assign_event_callbacks(window)
    return window
Example #13
0
def main():
    global angles, angley, anglez, scale, carcass, sphere
    if not glfw.init():
        return
    window = glfw.create_window(640, 640, "Lab2", None, None)
    if not window:
        glfw.terminate()
        return
    glfw.make_context_current(window)
    glfw.set_key_callback(window, key_callback)
    glfw.set_framebuffer_size_callback(window, resize_callback)
    glfw.set_window_pos_callback(window, drag_callback)
    l_cube = Cube(0, 0, 0, 1)
    # r_cube = Cube(0, 0, 0, 1)
    sphere.recount(parts)
    while not glfw.window_should_close(window):
        glEnable(GL_DEPTH_TEST)
        glDepthFunc(GL_LESS)
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
        set_projection()
        glLoadIdentity()
        sphere.draw(scale, angles, [0.3, 0.0, 0.4], carcass)
        # r_cube.draw(scale, angles, [0.3, 0.2, 0.4], carcass)
        l_cube.draw(0.5, [0, 0, 0], [-0.5, 0.0, -0.25], False)
        glfw.swap_buffers(window)
        glfw.poll_events()
    glfw.destroy_window(window)
    glfw.terminate()
Example #14
0
def main():
    global gVertexArrayIndexed, gIndexArray

    if not glfw.init():
        return
    window = glfw.create_window(480, 480, '2016025969', None, None)
    if not window:
        glfw.terminate()
        return
    glfw.make_context_current(window)

    glfw.set_mouse_button_callback(window, mouse_button_callback)
    glfw.set_cursor_pos_callback(window, cursor_position_callback)
    glfw.set_scroll_callback(window, scroll_callback)
    glfw.set_key_callback(window, key_callback)
    glfw.set_framebuffer_size_callback(window, size_callback)
    glfw.set_drop_callback(window, drop_callback)

    glfw.swap_interval(1)
    tarr = createVertexArraySeparate()

    while not glfw.window_should_close(window):
        glfw.poll_events()
        render()
        glfw.swap_buffers(window)

    glfw.terminate()
Example #15
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)
Example #16
0
    def main(self):
        glfw.init()
        self.window = glfw.create_window(1024, 768, "Car racer", None, None)
        glfw.make_context_current(self.window)
        glfw.swap_interval(1)
        glfw.set_key_callback(self.window, self.onkey)
        glfw.set_framebuffer_size_callback(self.window, self.onresize)

        self.car = model('models/Chevrolet_Camaro_SS_Low.obj')
        self.car.scale = vec3(car_size)

        # self.car = model('cube')
        # self.car.scale = vec3(0.08,0.01,0.18)

        self.envbox = envbox()
        self.road = road(car_speed, lanes, arc_len, lane_width, max_y)

        self.gen_car_states()

        self.cam = camera()
        self.cam.position = vec3(0, 3, 0)
        self.cam.target = vec3(0, 0, -5)

        glEnable(GL_DEPTH_TEST)
        glDepthFunc(GL_LEQUAL)

        while not glfw.window_should_close(self.window) and not self.done:
            glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
            self.__draw_frame()
            glfw.poll_events()
Example #17
0
    def init(self):
        if not glfw.init():
            raise Exception('glfw failed to initialize')

        glfw.window_hint(glfw.CONTEXT_VERSION_MAJOR, 3)
        glfw.window_hint(glfw.CONTEXT_VERSION_MINOR, 2)
        glfw.window_hint(glfw.OPENGL_FORWARD_COMPAT, GL.GL_TRUE)
        glfw.window_hint(glfw.OPENGL_PROFILE, glfw.OPENGL_CORE_PROFILE)

        self.window = glfw.create_window(
            self.initial_width, self.initial_height,
            self.title, None, None
        )
        if not self.window:
            glfw.terminate()
            raise Exception('glfw failed to create a window')

        glfw.make_context_current(self.window)
        glfw.set_framebuffer_size_callback(self.window, self._reshape_callback)
        glfw.set_key_callback(self.window, self._key_callback)
        glfw.set_mouse_button_callback(self.window, self._mouse_button_callback)

        GL.glEnable(GL.GL_CULL_FACE)
        GL.glCullFace(GL.GL_BACK)
        GL.glFrontFace(GL.GL_CW)

        GL.glEnable(GL.GL_DEPTH_TEST)
        GL.glDepthMask(GL.GL_TRUE)
        GL.glDepthFunc(GL.GL_LEQUAL)
        GL.glDepthRange(0.0, 1.0)
        GL.glEnable(depth_clamp.GL_DEPTH_CLAMP)
Example #18
0
    def __init__(self, parent, monitor):
        self.parent = parent
        self.monitor = monitor

        self.running = True
        self.modman = ModuleManager()

        self.currentSheet = None
        self.sheetObjects = {}
        self.subsheets = {}

        self.miscdata = {}  # Special cases are ~fun~! (The f stands for "FUUUCK why did I do this?!")

        self.videomode = glfw.get_video_mode(monitor)
        self.window = glfw.create_window(100, 100, "Hello World", monitor, None)
        #self.window = glfw.create_window(100, 100, "Hello World", None, None)
        if not self.window:
            raise Exception("Creating window failed")
        glfw.set_window_size(self.window, self.videomode[0][0], self.videomode[0][1])

        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.set_framebuffer_size_callback(self.window, self.framebufferSizeCallback)

        self.deltatime = 0
        self.time = glfw.get_time()


        self.beatlow = False
        self.beatmid = False
        self.beathigh = False
        self.bpm = 0
Example #19
0
def main():
    global angles, angley, anglez, scale, carcass, sphere
    if not glfw.init():
        return
    window = glfw.create_window(640, 640, "Lab2", None, None)
    if not window:
        glfw.terminate()
        return
    glfw.make_context_current(window)
    glfw.set_key_callback(window, key_callback)
    glfw.set_framebuffer_size_callback(window, resize_callback)
    glfw.set_window_pos_callback(window, drag_callback)
    l_cube = Cube(0, 0, 0, 1)
    # r_cube = Cube(0, 0, 0, 1)
    sphere.recount(parts)
    while not glfw.window_should_close(window):
        glEnable(GL_DEPTH_TEST)
        glDepthFunc(GL_LESS)
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
        set_projection()
        glLoadIdentity()
        sphere.draw(scale, angles, [0.3, 0.0, 0.4], carcass)
        # r_cube.draw(scale, angles, [0.3, 0.2, 0.4], carcass)
        l_cube.draw(0.5, [0, 0, 0], [-0.5, 0.0, -0.25], False)
        glfw.swap_buffers(window)
        glfw.poll_events()
    glfw.destroy_window(window)
    glfw.terminate()
def main():
    # glfw: initialize and configure
    glfw.init()
    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)

    # for Apple devices uncomment the following line
    # glfw.window_hint(glfw.OPENGL_FORWARD_COMPAT, gl.GL_TRUE)

    # glfw: window creation
    window = glfw.create_window(SCR_WIDTH, SCR_HEIGHT, "Learn OpenGL", None,
                                None)

    if window is None:
        glfw.terminate()
        raise Exception("Failed to create GLFW window")

    glfw.make_context_current(window)
    glfw.set_framebuffer_size_callback(window, framebuffer_size_callback)

    # INFO: GLAD is not used here

    # main event loop
    while not glfw.window_should_close(window):
        # glfw: swap buffers and poll IO events (keys pressed/released, mouse moved etc.)
        glfw.swap_buffers(window)
        glfw.poll_events()

    # glfw: terminate, clearing all previously allocated GLFW resources.
    glfw.terminate()
    return 0
Example #21
0
def main():
    glfw.init()
    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)

    window = glfw.create_window(WIN_WIDTH, WIN_HEIGHT, "Hello OpenGL", None,
                                None)
    if window == 0:
        print("failed to create window")
        glfw.glfwTerminate()

    glfw.make_context_current(window)
    glfw.set_framebuffer_size_callback(window, framebuffer_size_callback)

    vertexShader = gl.glCreateShader(gl.GL_VERTEX_SHADER)
    gl.glShaderSource(vertexShader, vertexShaderSource)
    gl.glCompileShader(vertexShader)

    fragmentShader = gl.glCreateShader(gl.GL_FRAGMENT_SHADER)
    gl.glShaderSource(fragmentShader, fragmentShaderSource)
    gl.glCompileShader(fragmentShader)

    shaderProgram = gl.glCreateProgram()
    gl.glAttachShader(shaderProgram, vertexShader)
    gl.glAttachShader(shaderProgram, fragmentShader)
    gl.glLinkProgram(shaderProgram)

    gl.glDeleteShader(vertexShader)
    gl.glDeleteShader(fragmentShader)

    VAO = gl.glGenVertexArrays(1)
    VBO = gl.glGenBuffers(1)

    gl.glBindVertexArray(VAO)
    gl.glBindBuffer(gl.GL_ARRAY_BUFFER, VBO)
    gl.glBufferData(gl.GL_ARRAY_BUFFER, sys.getsizeof(vertices), vertices,
                    gl.GL_STATIC_DRAW)

    gl.glVertexAttribPointer(gl.glGetAttribLocation(shaderProgram, 'aPos'), 3,
                             gl.GL_FLOAT, gl.GL_FALSE, 12, None)
    gl.glEnableVertexAttribArray(0)
    gl.glBindBuffer(gl.GL_ARRAY_BUFFER, 0)
    gl.glBindVertexArray(0)

    while not glfw.window_should_close(window):
        processInput(window)
        gl.glClearColor(0.2, 0.3, 0.3, 1.0)
        gl.glClear(gl.GL_COLOR_BUFFER_BIT)

        gl.glUseProgram(shaderProgram)
        gl.glBindVertexArray(VAO)
        gl.glDrawArrays(gl.GL_TRIANGLES, 0, 3)
        gl.glBindVertexArray(0)

        glfw.swap_buffers(window)
        glfw.poll_events()

    glfw.terminate()
Example #22
0
 def _register_callbacks(self, window):
     glfw.set_window_size_callback(window, self._on_set_window_size)
     glfw.set_window_pos_callback(window, self._on_set_window_pos)
     glfw.set_framebuffer_size_callback(window,
                                        self._on_set_frame_buffer_size)
     glfw.set_mouse_button_callback(window, self._on_set_mouse_button)
     glfw.set_cursor_pos_callback(window, self._on_set_cursor_pos)
     glfw.set_scroll_callback(window, self._on_set_scroll)
     glfw.set_window_close_callback(window, self._on_set_window_close)
Example #23
0
    def __init__(self):

        self.initglfw()

        self.monitors: Dict[str, Monitor] = {}
        self.monitors = self.getmonitors()

        with open("config.json", "r") as f:
            config = json.load(f)

        client_name = os.environ["PYREE_CLIENT"]
        client_info = config[client_name]

        print(client_info)
        print(self.monitors)

        resolution = (client_info["res"][0], client_info["res"][1])

        #self.window = glfw.create_window(1920, 1080
        #                                 , "PyreeEngine", None, None)
        self.window = glfw.create_window(resolution[0], resolution[1], "PyreeEngine", self.monitors[client_info["monitor"].encode()].monitorptr, None)
        glfw.set_framebuffer_size_callback(self.window, self.framebufferResizeCallback)

        glfw.make_context_current(self.window)

        glEnable(GL_MULTISAMPLE)
        glEnable(GL_DEPTH_TEST)

        self.init()

        ## Program Config
        with open("programconfig.json", "r") as f:
            self.programconfig = ProgramConfig(**json.load(f))

        # OSC setup
        self.oscdispatcher = pythonosc.dispatcher.Dispatcher()
        self.oscclient = pythonosc.udp_client.SimpleUDPClient(self.programconfig.oscclientaddress, self.programconfig.oscclientport)

        def defaultosc(*args):
            print(f"*Unmapped OSC message: {args}")

        self.oscdispatcher.set_default_handler(defaultosc)

        ## Layer Context and Manager
        self.layercontext: LayerContext = LayerContext()
        self.layercontext.setresolution(resolution[0], resolution[1])
        self.layercontext.time = glfw.get_time()

        self.layercontext.oscdispatcher = self.oscdispatcher
        self.layercontext.oscclient = self.oscclient
Example #24
0
    def open_window(self):
        if not self.window:
            self.input = {"button": None, "mouse": (0, 0)}

            # get glfw started
            if self.run_independently:
                glfw.init()
                glfw.window_hint(glfw.SCALE_TO_MONITOR, glfw.TRUE)
                self.window = glfw.create_window(self.window_size[0],
                                                 self.window_size[1],
                                                 self.name, None, None)
            else:
                self.window = glfw.create_window(
                    self.window_size[0],
                    self.window_size[1],
                    self.name,
                    None,
                    glfw.get_current_context(),
                )

            self.other_window = glfw.get_current_context()

            glfw.make_context_current(self.window)
            glfw.swap_interval(0)
            glfw.set_window_pos(self.window, window_position_default[0],
                                window_position_default[1])
            # Register callbacks window
            glfw.set_framebuffer_size_callback(self.window, self.on_resize)
            glfw.set_window_iconify_callback(self.window, self.on_iconify)
            glfw.set_key_callback(self.window, self.on_window_key)
            glfw.set_char_callback(self.window, self.on_window_char)
            glfw.set_mouse_button_callback(self.window,
                                           self.on_window_mouse_button)
            glfw.set_cursor_pos_callback(self.window, self.on_pos)
            glfw.set_scroll_callback(self.window, self.on_scroll)

            # get glfw started
            if self.run_independently:
                glutils.init()
            self.basic_gl_setup()

            self.sphere = glutils.Sphere(20)

            self.glfont = fs.Context()
            self.glfont.add_font("opensans", get_opensans_font_path())
            self.glfont.set_size(18)
            self.glfont.set_color_float((0.2, 0.5, 0.9, 1.0))
            self.on_resize(self.window,
                           *glfw.get_framebuffer_size(self.window))
            glfw.make_context_current(self.other_window)
Example #25
0
    def open_window(self):
        if not self._window:

            monitor = None
            # open with same aspect ratio as surface
            surface_aspect_ratio = (self.surface.real_world_size["x"] /
                                    self.surface.real_world_size["y"])
            win_h = 640
            win_w = int(win_h / surface_aspect_ratio)

            self._window = glfw.create_window(
                win_h,
                win_w,
                "Reference Surface: " + self.surface.name,
                monitor,
                glfw.get_current_context(),
            )

            glfw.set_window_pos(
                self._window,
                self.window_position_default[0],
                self.window_position_default[1],
            )

            self.trackball = gl_utils.trackball.Trackball()
            self.input = {"down": False, "mouse": (0, 0)}

            # Register callbacks
            glfw.set_framebuffer_size_callback(self._window, self.on_resize)
            glfw.set_key_callback(self._window, self.on_window_key)
            glfw.set_window_close_callback(self._window, self.on_close)
            glfw.set_mouse_button_callback(self._window,
                                           self.on_window_mouse_button)
            glfw.set_cursor_pos_callback(self._window, self.on_pos)
            glfw.set_scroll_callback(self._window, self.on_scroll)

            self.on_resize(self._window,
                           *glfw.get_framebuffer_size(self._window))

            # gl_state settings
            active_window = glfw.get_current_context()
            glfw.make_context_current(self._window)
            gl_utils.basic_gl_setup()
            gl_utils.make_coord_system_norm_based()

            # refresh speed settings
            glfw.swap_interval(0)

            glfw.make_context_current(active_window)
Example #26
0
def prepare_window():
    window = glfw.create_window(SCR_WIDTH, SCR_HEIGHT, "LearnOpenGL", None,
                                None)
    glfw.make_context_current(window)
    glfw.set_framebuffer_size_callback(window, framebuffer_size_callback)
    glfw.set_cursor_pos_callback(window, mouse_callback)
    glfw.set_scroll_callback(window, scroll_callback)

    # tell GLFW to capture our mouse
    glfw.set_input_mode(window, glfw.CURSOR, glfw.CURSOR_DISABLED)

    width, height = glfw.get_framebuffer_size(window)
    glClearColor(0.2, 0.3, 0.3, 1.)
    glEnable(GL_DEPTH_TEST)
    return window
Example #27
0
    def createWindow(self):
        self.window = glfw.create_window(500, 500, "Pyree Worker (´・ω・ `)", None, None)

        self.runtime.width, self.runtime.height = glfw.get_window_size(self.window)

        # glfw.set_window_size(self.window, self.videomode[0][0], self.videomode[0][1])

        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.make_context_current(self.window)

        glfw.set_framebuffer_size_callback(self.window, self.framebufferSizeCallback)

        self.genFramebuffer()
Example #28
0
    def create(self):
        self.window = glfw.create_window(self.width, self.height, self.title,
                                         None, None)

        if self.window is None:
            print(MSG_FAILED_CREATE_WINDOW)
            glfw.terminate()
            return False

        glfw.make_context_current(self.window)
        glfw.swap_interval(0)
        glfw.set_framebuffer_size_callback(self.window,
                                           self._framebuffer_size_callback)
        glfw.set_cursor_pos_callback(self.window,
                                     self._get_cursor_position_callback)
        return True
Example #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()
Example #30
0
def main():
    glfw_init()

    window = glfw_create_window()
    set_gl_options()
    print("GL version: %s" % glGetString(GL_VERSION))

    # A bit hacky?
    global INPUT
    INPUT = Input(window)

    glfw.set_framebuffer_size_callback(window, framebuffer_size_callback)
    glfw.set_cursor_pos_callback(window, INPUT.mouse_callback)
    glfw.set_scroll_callback(window, INPUT.scroll_callback)
    glfw.set_key_callback(window, INPUT.key_callback)

    game_manager = GameManager()
    fps = FPSCounter()

    last_time = time.time()
    fov = 45.0
    while not glfw.window_should_close(window):
        fps.frame()

        now = time.time()
        dt = now - last_time
        last_time = now
        t = now

        glfw.poll_events()

        game_manager.update(dt)

        glClearColor(0.0, 0.0, 0.0, 1.0)
        glClear(GL_COLOR_BUFFER_BIT)
        game_manager.render()

        glfw.swap_buffers(window)

        if INPUT.key_down(glfw.KEY_Q):
            glfw.set_window_should_close(window, True)

        INPUT.update_end()

    glfw.terminate()
    return
Example #31
0
def main():
    if not glfw.init():
        return
    window = glfw.create_window(640, 640, '2016024975', None, None)
    if not window:
        glfw.terminate()
        return
    glfw.make_context_current(window)
    glfw.set_key_callback(window, key_callback)
    glfw.set_framebuffer_size_callback(window, framebuffer_size_callback)

    while not glfw.window_should_close(window):
        glfw.poll_events()
        render()
        glfw.swap_buffers(window)

    glfw.terminate()
Example #32
0
def main():
   if not glfw.init():
      return
   window = glfw.create_window(640,640,'2015004584', None,None)
   if not window:
      glfw.terminate()
      return
   glfw.make_context_current(window)
   glfw.set_key_callback(window, key_callback)
   glfw.set_framebuffer_size_callback(window, windows_callback)

   while not glfw.window_should_close(window):
      glfw.poll_events()
      render()
      glfw.swap_buffers(window)
   
   glfw.terminate()
Example #33
0
def main():
    if not glfw.init():
        print("GLFW not initialized")
        return

    window = glfw.create_window(640, 640, "Clipping", None, None)
    if not window:
        print("Window not created")
        glfw.terminate()
        return

    glfw.make_context_current(window)

    glfw.set_key_callback(window, key_callback)
    glfw.set_framebuffer_size_callback(window, resize_callback)
    glfw.set_mouse_button_callback(window, mouse_button_callback)

    while not glfw.window_should_close(window):
        GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT)
        width, height = glfw.get_window_size(window)
        prepare_projection(width, height)

        # создание отсекающего многоугольника
        if Globals.mode == 1:
            draw_points(Globals.clip_polygon_vertexes, Globals.default_color)
            draw_lines(Globals.clip_polygon_vertexes, Globals.default_color,
                       Globals.complete)
        # рисование отрезков
        elif Globals.mode == 2:
            draw_lines(Globals.clip_polygon_vertexes, Globals.default_color,
                       Globals.complete)
            draw_segments(Globals.segments_vertexes, Globals.default_color)
        # закрашивание отсечённых отрезков
        elif Globals.mode == 3:
            draw_lines(Globals.clip_polygon_vertexes, Globals.default_color,
                       Globals.complete)
            draw_segments(Globals.segments_vertexes, Globals.default_color)
            for s in Globals.clipped_segments:
                draw_segment(s[0], s[1], Globals.clipped_color)

        glfw.swap_buffers(window)
        glfw.poll_events()

    print("Terminate...")
    glfw.terminate()
    def open_window(self):
        if not self._window:
            if self.fullscreen:
                try:
                    monitor = glfw.get_monitors()[self.monitor_idx]
                except Exception:
                    logger.warning(
                        "Monitor at index %s no longer availalbe using default"
                        % idx)
                    self.monitor_idx = 0
                    monitor = glfw.get_monitors()[self.monitor_idx]
                mode = glfw.get_video_mode(monitor)
                height, width = mode.size.height, mode.size.width
            else:
                monitor = None
                height, width = 640, 480

            self._window = glfw.create_window(
                height,
                width,
                "Calibration",
                monitor,
                glfw.get_current_context(),
            )
            if not self.fullscreen:
                # move to y = 31 for windows os
                glfw.set_window_pos(self._window, 200, 31)

            # Register callbacks
            glfw.set_framebuffer_size_callback(self._window, on_resize)
            glfw.set_key_callback(self._window, self.on_window_key)
            glfw.set_window_close_callback(self._window, self.on_close)
            glfw.set_mouse_button_callback(self._window,
                                           self.on_window_mouse_button)

            on_resize(self._window, *glfw.get_framebuffer_size(self._window))

            # gl_state settings
            active_window = glfw.get_current_context()
            glfw.make_context_current(self._window)
            basic_gl_setup()
            glfw.make_context_current(active_window)

            self.clicks_to_close = 5
Example #35
0
def init():
    if not glfw.init():
        print("GLFW not initialized")
        return

    window = glfw.create_window(640, 640, "Cubes", None, None)
    if not window:
        print("Window not created")
        glfw.terminate()
        return

    glfw.make_context_current(window)

    GL.glEnable(GL.GL_DEPTH_TEST)
    GL.glDepthFunc(GL.GL_LESS)

    glfw.set_key_callback(window, key_callback)
    glfw.set_framebuffer_size_callback(window, resize_callback)

    # подключение шейдеров
    program = load_shaders()

    return window, program
Example #36
0
def main():
    global fill
    global rotate_x
    global rotate_y
    global rotate_z
    global scale
    global shift
    global segmentsCount
    global draw_cube
    global isometric
    fill = True
    rotate_x = 0
    rotate_y = 0
    rotate_z = 0
    scale = 1.0
    shift = [0.0, 0.0]
    segmentsCount = 40
    draw_cube = True
    isometric = False

    if not glfw.init():
        print("GLFW not initialized")
        return

    window = glfw.create_window(640, 640, "Cubes", None, None)
    if not window:
        print("Window not created")
        glfw.terminate()
        return

    glfw.make_context_current(window)

    glEnable(GL_DEPTH_TEST)
    glDepthFunc(GL_LESS)

    glfw.set_key_callback(window, key_callback)
    glfw.set_framebuffer_size_callback(window, resize_callback)

    big_cube = Cube([0.0, 0.0, 0.0], 0.6)
    small_cube = Cube([0.8, 0.8, 0.0], 0.1)

    line = (
        (0.0, 0.65, 0.0),
        (0.2, 0.4, 0.0),
        (0.05, 0.4, 0.0),
        (0.35, 0.0, 0.0),
        (0.08, 0.0, 0.0),
        (0.08, -0.15, 0.0),
        (0.0, -0.15, 0.0)
    )
    color = (0.0, 0.6, 0.1)
    surface = SurfaceOfRevolution(line, [0.0, 0.0, 0.0])

    while not glfw.window_should_close(window):
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)

        make_projection(isometric)

        if draw_cube:
            big_cube.draw(shift, fill, paint_material, scale, rotate_x, rotate_y, rotate_z)
            small_cube.draw([0.0, 0.0], fill, paint_material)
        else:
            paint_material(color)
            surface.change_segments_count(segmentsCount)
            surface.draw(shift, fill, scale, rotate_x, rotate_y, rotate_z)

        # после каждой итерации сдвиг снова становится нулевым до тех пор,
        # пока пользователь не нажмёт кнопку
        shift = [0.0, 0.0]

        glfw.swap_buffers(window)
        glfw.poll_events()

    print("Terminate...")
    glfw.terminate()
Example #37
0
def main():
    global clear_all, clear_buffers, x, y, clicked, mode, complete, window_height
    mode = 1
    clicked, complete = False, False
    clear_all, clear_buffers = True, True
    window_height = 640

    if not glfw.init():
        print("GLFW not initialized")
        return

    window = glfw.create_window(640, window_height, "Rasterization", None, None)
    if not window:
        print("Window not created")
        glfw.terminate()
        return

    glfw.make_context_current(window)

    glEnable(GL_DEPTH_TEST)
    glDepthFunc(GL_LESS)

    glfw.set_key_callback(window, key_callback)
    glfw.set_framebuffer_size_callback(window, resize_callback)
    glfw.set_mouse_button_callback(window, mouse_button_callback)

    figure = []
    color = (1.0, 1.0, 1.0)

    while not glfw.window_should_close(window):
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
        width, height = glfw.get_window_size(window)
        prepare_projection(width, height)

        if clear_buffers:
            matrix = None
            clear_buffers = False

        if clear_all:
            figure = []
            matrix = None
            clear_all, complete = False, False

        if mode == 1:
            if clicked:
                figure.append((int(x), int(height - y)))
            draw_points(figure, color)
            draw_lines(figure, color, complete)
            clicked = False
        elif mode == 2:
            if matrix is None:
                matrix = create_figure_view(width, height, figure, color)
            glDrawPixels(width, height, GL_RGB, GL_FLOAT, matrix)
        elif mode == 3:
            # фильтрация работает только при задании вершин против часовой стрелки!
            # отрисовка сглаженных границ
            if matrix is None:
                matrix = create_figure_view(width, height, figure, color)
                matrix = add_lines_to_matrix(figure, color, matrix)
            glDrawPixels(width, height, GL_RGB, GL_FLOAT, matrix)

        glfw.swap_buffers(window)
        glfw.poll_events()

    print("Terminate...")
    glfw.terminate()
Example #38
0
    def run(self):
        # Initialize the library
        if not glfw.init():
            return

        # Set some window hints
        glfw.window_hint(glfw.CONTEXT_VERSION_MAJOR, 3);
        glfw.window_hint(glfw.CONTEXT_VERSION_MINOR, 3);
        glfw.window_hint(glfw.OPENGL_FORWARD_COMPAT, GL.GL_TRUE);
        glfw.window_hint(glfw.OPENGL_PROFILE, glfw.OPENGL_CORE_PROFILE);
        glfw.window_hint(glfw.SAMPLES, 16)

        # This works as expected
        # glfw.window_hint(glfw.RESIZABLE, 0)

        # These should work, but don't :(
        # could control focus w/ http://crunchbang.org/forums/viewtopic.php?id=22226
        # ended up using xdotool, see run.py
        glfw.window_hint(glfw.FOCUSED, 0)

        # I've set 'shader-*' to raise in openbox-rc as workaround
        # Looking at the code and confirming version 3.1.2 and it should work
        glfw.window_hint(glfw.FLOATING, 1)

        # Create a windowed mode window and its OpenGL context
        self.w = glfw.create_window(500, 500, "shader-test", None, None)
        if not self.w:
            glfw.terminate()
            return

        # Move Window
        glfw.set_window_pos(self.w, 1400, 50)

        # Callbacks
        glfw.set_key_callback(self.w, self.on_key)
        glfw.set_framebuffer_size_callback(self.w, self.on_resize);


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

        # vsync
        glfw.swap_interval(1)

        # Setup GL shaders, data, etc.
        self.initialize()

        # Loop until the user closes the window
        while not glfw.window_should_close(self.w):
            # print difference in time since start
            # this should always be 16.6-16.7 @ 60fps
            # print('%0.1fms' % (1000 * (time.time()-self.lastframe)))

            # start of the frame
            self.lastframe = time.time()

            # Render here, e.g. using pyOpenGL
            self.render()

            # Swap front and back buffers
            glfw.swap_buffers(self.w)

            # Poll for and process events
            glfw.poll_events()

        glfw.terminate()