예제 #1
0
def main():
  ### Initialize
  fw.init()

  ### Rift
  monitor = get_rift()

  win = CbWindow(640, 480, 'pyglfw')
  win.make_current()

  # XWindows...
  d = Display()
  root = d.screen().root
  pixmap = root.create_pixmap(256, 256, 8)
  # glXCreateWindow(d, cfg, pixmap, 0)


  while not win.should_close:

    render()

    win.swap_buffers()
    fw.poll_events()

    if win.keys.escape:
        win.should_close = True

  fw.terminate()
예제 #2
0
def main():
    ### Initialize
    fw.init()

    ### Monitor Info
    # print_all_monitors()

    ### Rift
    monitor = get_rift()
    curmode = monitor.video_mode
    curmode.refresh_rate  # should be 74

    # Check for Monitor - really should check for Rift attach/detach...
    # this doesn't work like I think it should
    fw.Monitor.set_callback(on_monitor)

    win = CbWindow(curmode.width, curmode.height, 'pyglfw', monitor)
    win.make_current()

    while not win.should_close:

        # blue!
        blue = (0.0, 0.0, 1.0, 0.0)
        glClearColor(*blue)

        glClear(GL_COLOR_BUFFER_BIT)

        win.swap_buffers()
        fw.poll_events()

        if win.keys.escape:
            win.should_close = True

    fw.terminate()
예제 #3
0
def main():
  ### Initialize
  fw.init()

  ### Monitor Info
  # print_all_monitors()

  ### Rift
  monitor = get_rift()
  curmode = monitor.video_mode
  curmode.refresh_rate # should be 74


  # Check for Monitor - really should check for Rift attach/detach...
  # this doesn't work like I think it should
  fw.Monitor.set_callback(on_monitor)

  win = CbWindow(curmode.width, curmode.height, 'pyglfw', monitor)
  win.make_current()

  while not win.should_close:

    # blue!
    blue = (0.0, 0.0, 1.0, 0.0)
    glClearColor(*blue)

    glClear(GL_COLOR_BUFFER_BIT)

    win.swap_buffers()
    fw.poll_events()

    if win.keys.escape:
        win.should_close = True

  fw.terminate()
예제 #4
0
def main():
    # Initialize the library
    if not glfw.init():
        return
    # Create a windowed mode window and its OpenGL context
    window = glfw.window.Window(640, 480, "Hello World", None, None)
    if not window:
        glfw.terminate()
        return

    renderer = RiftGLRendererCompatibility()
    # Paint a triangle in the center of the screen
    renderer.append(TriangleDrawerCompatibility())

    # Make the window's context current
    window.make_current()

    # Initialize Oculus Rift
    renderer.init_gl()
    renderer.rift.recenter_pose()

    # Loop until the user closes the window
    while not window.should_close:
        # Render here, e.g. using pyOpenGL
        renderer.display_rift_gl()

        # Swap front and back buffers
        window.swap_buffers()

        # Poll for and process events
        glfw.poll_events()

    glfw.terminate()
예제 #5
0
def main():
    fw.init()

    fw.Monitor.set_callback(on_monitor)

    win = CbWindow(800, 600, "callback window")
    win.make_current()

    while not win.should_close:

        win.swap_buffers()
        fw.poll_events()

        if win.keys.escape:
            win.should_close = True

    fw.terminate()
예제 #6
0
def main():
    fw.init()

    fw.Monitor.set_callback(on_monitor)

    win = CbWindow(800, 600, "callback window")
    win.make_current()

    while not win.should_close:

        win.swap_buffers()
        fw.poll_events()

        if win.keys.escape:
            win.should_close = True

    fw.terminate()
예제 #7
0
    def __init__(self):

        with open("config.json") as cfg_file:
            game_cfg = load_json(cfg_file)

        if not glfw.init():
            raise RuntimeError("Failed to initialise GLFW")

        GlfwWindow.hint(samples=game_cfg["aaSamples"])
        GlfwWindow.hint(context_ver_major=3)
        GlfwWindow.hint(context_ver_minor=3)
        GlfwWindow.hint(forward_compat=True)
        GlfwWindow.hint(resizable=True)
        GlfwWindow.hint(opengl_profile=GlfwWindow.CORE_PROFILE)

        primary_monitor = None
        if game_cfg["fullscreen"]:
            primary_monitor = glfw.get_primary_monitor()

        self.window = GlfwWindow(game_cfg["screenWidth"],
                                 game_cfg["screenHeight"], "Tutorial",
                                 primary_monitor)
        if not self.window:
            raise RuntimeError("Failed to initialise window.")

        self.window.make_current()

        self.clock = Clock()

        self.dispatchTable = DispatchTable(self.window)

        # setup keyboard and mouse controls
        self.dispatchTable.registerKey(glfw.Keys.ESCAPE, self.escape)
        self.dispatchTable.registerKey(glfw.Keys.W, self.moveForward)
        self.dispatchTable.registerKey(glfw.Keys.S, self.moveBackward)
        self.dispatchTable.registerKey(glfw.Keys.A, self.moveLeft)
        self.dispatchTable.registerKey(glfw.Keys.D, self.moveRight)

        self.dispatchTable.registerMouseButton(glfw.Mice.RIGHT,
                                               self.toggleMouseLook)

        self.renderer = Renderer(self.window)
        self.renderer.fov = pi / 4.

        self.camera = None

        self.gameData = GameData()

        self._mouseLook = False

        self._terminate = False
예제 #8
0
파일: app.py 프로젝트: yoyonel/vrdev
def main():
    fw.init()

    monitor = get_dk2()
    if not monitor:
        sys.exit('Could not find DK2')
    curmode = monitor.video_mode
    print(curmode.refresh_rate)  # should be 74

    win = CbWindow(960, 540, 'pyglfw')
    win.make_current()

    dk2 = DK2(win)

    while not win.should_close:
        dk2.render()

        fw.poll_events()

        if win.keys.escape:
            win.should_close = True

    fw.terminate()
예제 #9
0
파일: app.py 프로젝트: lhl/vrdev
def main():
  fw.init()

  monitor = get_dk2()
  if not monitor:
    sys.exit('Could not find DK2')
  curmode = monitor.video_mode
  print(curmode.refresh_rate) # should be 74

  win = CbWindow(960, 540, 'pyglfw')
  win.make_current()

  dk2 = DK2(win)

  while not win.should_close:
    dk2.render()

    fw.poll_events()

    if win.keys.escape:
        win.should_close = True

  fw.terminate()
예제 #10
0
def main():
  ### Initialize
  fw.init()

  ### Hints
  # ok, that doesn't work... can't get context for that
  # fw.Window.hint(stereo=True)


  ### Monitor Info
  # print_all_monitors()

  ### Rift
  monitor = get_rift()
  curmode = monitor.video_mode
  curmode.refresh_rate # should be 74


  # Check for Monitor - really should check for Rift attach/detach...
  # this doesn't work like I think it should
  fw.Monitor.set_callback(on_monitor)

  win = CbWindow(640, 480, 'pyglfw')
  win.make_current()

  while not win.should_close:

    render()

    win.swap_buffers()
    fw.poll_events()

    if win.keys.escape:
        win.should_close = True

  fw.terminate()
예제 #11
0
파일: eezl.py 프로젝트: philetus/pyeezl
    def __init__( self, width, height, title='eezl' ):

        print( "creating eezl" )
        self._width = width
        self._height = height
        self._title = title
        self._clear_color = [0.0, 0.0, 0.0, 1.0]

        self._stainq = queue.Queue( 1 ) # queue to signal for redraw

        # init glfw
        if not glfw.init():
            raise Exception("couldnt init glfw!")

        # create window
        self._win = glfw.Window(width, height, title)
        if not self._win:
            glfw.terminate()
            raise Exception("couldnt create glfw window!")

        self._win.make_current()
        self._win.swap_interval( 1 ) # 0 -> go fast / 1 -> pause first

        self._nvg = nvg.Context()

        # setup gl context
        gl.glEnable( gl.GL_POINT_SPRITE )
        gl.glEnable( gl.GL_VERTEX_PROGRAM_POINT_SIZE ) # overwrite pointsize
        gl.glBlendFunc( gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA )
        gl.glEnable( gl.GL_BLEND )
        gl.glClearColor( *self._clear_color )

        # register glfw.window callbacks
        self._win.set_window_size_callback( self._on_resize )
        self._win.set_window_close_callback( self._on_close )
        self._win.set_key_callback( self._on_key )
        self._win.set_mouse_button_callback( self._on_button )
        self._win.set_cursor_pos_callback( self._on_pos )

        # init window size
        self._on_resize( self._win, self._width, self._height )
예제 #12
0
    def __init__(self, width, height, title='eezl'):

        print("creating eezl")
        self._width = width
        self._height = height
        self._title = title
        self._clear_color = [0.0, 0.0, 0.0, 1.0]

        self._stainq = queue.Queue(1)  # queue to signal for redraw

        # init glfw
        if not glfw.init():
            raise Exception("couldnt init glfw!")

        # create window
        self._win = glfw.Window(width, height, title)
        if not self._win:
            glfw.terminate()
            raise Exception("couldnt create glfw window!")

        self._win.make_current()
        self._win.swap_interval(1)  # 0 -> go fast / 1 -> pause first

        self._nvg = nvg.Context()

        # setup gl context
        gl.glEnable(gl.GL_POINT_SPRITE)
        gl.glEnable(gl.GL_VERTEX_PROGRAM_POINT_SIZE)  # overwrite pointsize
        gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)
        gl.glEnable(gl.GL_BLEND)
        gl.glClearColor(*self._clear_color)

        # register glfw.window callbacks
        self._win.set_window_size_callback(self._on_resize)
        self._win.set_window_close_callback(self._on_close)
        self._win.set_key_callback(self._on_key)
        self._win.set_mouse_button_callback(self._on_button)
        self._win.set_cursor_pos_callback(self._on_pos)

        # init window size
        self._on_resize(self._win, self._width, self._height)
예제 #13
0
def main():
    # Initialize the library
    if not glfw.init():
        return

    # Set some window hints
    glfw.Window.hint(floating=glfw.Window.floating)

    # Create a windowed mode window and its OpenGL context
    window = glfw.Window(300, 300, "Hello World", None, None)
    if not window:
        glfw.terminate()
        return

    # Move Window
    window.pos = (1600, 50)

    # Make the window's context current
    window.make_current()

    # vsync
    window.swap_interval(1)

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

    # Loop until the user closes the window
    while not window.should_close:
        # Render here, e.g. using pyOpenGL
        render()

        # Swap front and back buffers
        window.swap_buffers()

        # Poll for and process events
        glfw.poll_events()

    glfw.terminate()
예제 #14
0
파일: hello_glfw.py 프로젝트: yuyou/pyovr
def main():
    # Initialize the library
    if not glfw.init():
        return
    # Create a windowed mode window and its OpenGL context
    window = glfw.window.Window(640, 480, "Hello World", None, None)
    if not window:
        glfw.terminate()
        return

    # Make the window's context current
    window.make_current()

    # Loop until the user closes the window
    while not window.should_close:
        # Render here, e.g. using pyOpenGL

        # Swap front and back buffers
        window.swap_buffers()

        # Poll for and process events
        glfw.poll_events()

    glfw.terminate()
예제 #15
0
    thread.window.swap_interval(1)

    with thread.window:
        while running:
            v = math.fabs(math.sin(fw.get_time() * 2.0))
            glClearColor(thread.r * v, thread.g * v, thread.b * v, 0.0)
            glClear(GL_COLOR_BUFFER_BIT)
            thread.window.swap_buffers()


if __name__ == '__main__':
    threads = (Thread('Red', 1.0, 0.0,
                      0.0), Thread('Green', 0.0, 1.0,
                                   0.0), Thread('Blue', 0.0, 0.0, 1.0))

    if not fw.init():
        sys.exit(1)

    fw.Window.hint(visuble=False)

    for i, t in enumerate(threads):
        t.window = fw.Window(200, 200, t.title)
        t.window.pos = 200 + 250 * i, 200
        t.window.show()

        t.id = threading.Thread(None, thread_main, t.title, (t, ))
        t.id.start()

    while running:
        fw.wait_events()
예제 #16
0
    def __init__(self,
                 wavelength_nm,
                 pixel_size_um,
                 focal_mm,
                 beam_radius_mm=None,
                 screenID=None,
                 active_area_coords=None,
                 lut_edges=[0, 255]):
        print("""Thanks for using SLM-3dPointCloud.
Library openly available for non-commercial use at https://github.com/ppozzi/SLM-3dPointCloud.
If used for academic purposes, please consider citing the appropriate literature (https://doi.org/10.3389/fncel.2021.609505, https://doi.org/10.3390/mps2010002))"""
              )

        self.screenID = screenID
        if self.screenID is not None:
            self.screenresolution = (
                screeninfo.get_monitors()[self.screenID].height,
                screeninfo.get_monitors()[self.screenID].width)
            if active_area_coords is None:
                self.res = numpy.amin(
                    numpy.asarray([
                        screeninfo.get_monitors()[self.screenID].height,
                        screeninfo.get_monitors()[self.screenID].width
                    ]))
                self.position = (screeninfo.get_monitors()[self.screenID].x, 0)
                self.aperture_position = (int(
                    (self.screenresolution[0] - self.res) /
                    2), int((self.screenresolution[1] - self.res) / 2))
            else:
                self.res = (active_area_coords[2])
                self.position = (screeninfo.get_monitors()[self.screenID].x, 0)
                self.aperture_position = (active_area_coords[0],
                                          active_area_coords[1])
        else:
            if active_area_coords is None:
                self.res = 512
                self.position = (0, 0)
            else:
                self.res = active_area_coords[2]
                self.position = (active_area_coords[0], active_area_coords[1])
            self.aperture_position = (0, 0)
            self.screenresolution = (self.res, self.res)
        glfw.init()
        glfw.Window.hint()

        if screenID != None:
            self.win = glfw.Window(self.screenresolution[1],
                                   self.screenresolution[0], "SLM",
                                   glfw.get_monitors()[self.screenID])
        else:
            self.win = glfw.Window(
                self.screenresolution[1],
                self.screenresolution[0],
                "SLM",
            )
            self.win.pos = self.position
        self.win.make_current()
        self.win.swap_interval(0)
        self.lut_edges = lut_edges
        glViewport(0, 0, self.screenresolution[1], self.screenresolution[0])
        glMatrixMode(GL_PROJECTION)
        glLoadIdentity()
        glOrtho(0, 1.0, 0, 1.0, -1.0, 1.0)
        glMatrixMode(GL_MODELVIEW)
        glLoadIdentity()
        glEnable(GL_DEPTH_TEST)
        glClearColor(1.0, 1.0, 1.0, 1.5)
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)

        glEnable(GL_TEXTURE_2D)
        self.tex = glGenTextures(1)
        glBindTexture(GL_TEXTURE_2D, self.tex)
        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, self.screenresolution[1],
                     self.screenresolution[0], 0, GL_RGBA, GL_UNSIGNED_BYTE,
                     None)
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)

        import pycuda.gl.autoinit
        self.mod = SourceModule(cuda_code, options=DEFAULT_NVCC_FLAGS)
        self.project_to_slm = self.mod.get_function("project_to_slm")
        self.project_to_spots_setup = self.mod.get_function(
            "project_to_spots_setup")
        self.project_to_spots_end = self.mod.get_function(
            "project_to_spots_end")
        self.project_to_slm_comp = self.mod.get_function("project_to_slm_comp")
        self.project_to_spots_setup_comp = self.mod.get_function(
            "project_to_spots_setup_comp")
        self.project_to_spots_end_comp = self.mod.get_function(
            "project_to_spots_end_comp")
        self.update_weights = self.mod.get_function("update_weights")
        self.fill_screen_output = self.mod.get_function("fill_screen_output")

        self.pbo = glGenBuffers(1)
        glBindBuffer(GL_PIXEL_UNPACK_BUFFER, self.pbo)
        glBufferData(GL_PIXEL_UNPACK_BUFFER,
                     self.screenresolution[1] * self.screenresolution[0] * 4,
                     None, GL_DYNAMIC_COPY)
        self.cuda_pbo = pycuda.gl.RegisteredBuffer(
            int(self.pbo), cuda_gl.graphics_map_flags.WRITE_DISCARD)

        self.lam = wavelength_nm * 0.001
        self.pix_size = pixel_size_um
        self.f = focal_mm * 1000.0
        self.blocksize_forward = 512
        XC, YC = numpy.meshgrid(
            numpy.linspace(-self.pix_size * self.res / 2,
                           self.pix_size * self.res / 2, self.res),
            numpy.linspace(-self.pix_size * self.res / 2,
                           self.pix_size * self.res / 2, self.res))
        RC2 = XC**2 + YC**2
        pupil_coords = numpy.where(
            numpy.sqrt(RC2) <= self.pix_size * self.res / 2)
        indexes = numpy.asarray(range(pupil_coords[0].shape[0]))
        numpy.random.shuffle(indexes)
        self.pupil_coords = (pupil_coords[0][indexes],
                             pupil_coords[1][indexes])
        self.PUP_NP = self.pupil_coords[0].shape[0]

        # XC_unit, YC_unit = numpy.meshgrid(numpy.linspace(-1.0, 1.0, self.res),
        #                         numpy.linspace(-1.0, 1.0, self.res))
        # pupil_int = gauss((XC_unit, YC_unit), 1.0, 0.0, 0.00851336, -0.02336506,  0.48547321,  0.50274484)**2

        if beam_radius_mm == None:
            pupil_int = numpy.ones((self.res, self.res))
        else:
            pupil_int = numpy.exp(-(XC**2 + YC**2) /
                                  (1000.0 * beam_radius_mm)**2)
        pupil_int = pupil_int[self.pupil_coords]
        pupil_int = (pupil_int / numpy.sum(pupil_int)).astype("float32")
        self.PUP_INT_gpu = gpuarray.to_gpu(pupil_int)
        self.holo_real_gpu = gpuarray.to_gpu(
            numpy.zeros(self.PUP_NP, dtype="float32"))
        self.holo_imag_gpu = gpuarray.to_gpu(
            numpy.zeros(self.PUP_NP, dtype="float32"))
        self.XC_gpu = gpuarray.to_gpu(XC[self.pupil_coords].astype("float32"))
        self.YC_gpu = gpuarray.to_gpu(YC[self.pupil_coords].astype("float32"))
        self.float_pars_gpu = gpuarray.to_gpu(
            numpy.asarray([
                2.0 * numpy.pi / (self.lam * self.f),
                numpy.pi / (self.lam * self.f**2) * 10**3
            ]).astype("float32"))
        self.screen_pup_coords_y_gpu = gpuarray.to_gpu(
            (self.pupil_coords[0] + self.aperture_position[0]).astype("int32"))
        self.screen_pup_coords_x_gpu = gpuarray.to_gpu(
            (self.pupil_coords[1] + self.aperture_position[1]).astype("int32"))
        self.screenpars_gpu = gpuarray.to_gpu(
            numpy.asarray([
                self.PUP_NP, self.screenresolution[1], self.lut_edges[0],
                self.lut_edges[1]
            ]).astype("int32"))
예제 #17
0
# coding=utf-8

import pyglfw.pyglfw as glfw
import common2d

if __name__ == '__main__':
    glfw.init()

    w = glfw.Window(640, 480, "Hello world!")

    w.make_current()

    program = common2d.init_shader_program()

    while not w.should_close:
        # Render here
        common2d.display(program)

        w.swap_buffers()
        glfw.poll_events()

        if w.keys.escape:
            w.should_close = True

    glfw.terminate()
예제 #18
0
# coding=utf-8

import pyglfw.pyglfw as glfw
import common2d

if __name__ == '__main__':
	glfw.init()

	w = glfw.Window(640, 480, "Hello world!")

	w.make_current()

	program = common2d.init_shader_program()

	while not w.should_close:
		# Render here
		common2d.display(program)

		w.swap_buffers()
		glfw.poll_events()

		if w.keys.escape:
			w.should_close = True

	glfw.terminate()

예제 #19
0
파일: threads.py 프로젝트: lhl/pyglfw
def thread_main(thread):
    thread.window.swap_interval(1)

    with thread.window:
        while running:
            v = math.fabs(math.sin(fw.get_time() * 2.0))
            glClearColor(thread.r * v, thread.g * v, thread.b * v, 0.0)
            glClear(GL_COLOR_BUFFER_BIT)
            thread.window.swap_buffers()

if __name__ == '__main__':
    threads = (Thread('Red', 1.0, 0.0, 0.0),
               Thread('Green', 0.0, 1.0, 0.0),
               Thread('Blue', 0.0, 0.0, 1.0))

    if not fw.init():
        sys.exit(1)

    fw.Window.hint(visuble=False)

    for i, t in enumerate(threads):
        t.window = fw.Window(200, 200, t.title)
        t.window.pos = 200 + 250 * i, 200
        t.window.show()

        t.id = threading.Thread(None, thread_main, t.title, (t,))
        t.id.start()

    while running:
        fw.wait_events()