def open_window(title, share, posX, posY): fw.Window.hint(visible=False) window = fw.Window(WIDTH, HEIGHT, title, None, share) window.swap_interval(1) window.pos = posX, posY window.show() return window.make_current()
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)
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()
# 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()
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() for i, t in enumerate(threads): if t.window.should_close: running = False for i, t in enumerate(threads): t.id.join()
print("client api: %s" % client_api_map[window.client_api]) print("context version: %s.%s.%s" % window.context_version) print("forward compat: %s" % window.forward_compat) print("debug context: %s" % window.debug_context) print("opengl profile: %s" % opengl_profile_map[window.opengl_profile]) print("context robustness: %s" % context_robustness_map[window.context_robustness]) print("cursor mode: %s" % cursor_mode_map[window.cursor_mode]) print("sticky keys: %s" % window.sticky_keys) print("sticky mice: %s" % window.sticky_mice) print("") if __name__ == '__main__': glfw.init() w = glfw.Window(800, 600, "") w.make_current() while not w.should_close: w.swap_buffers() glfw.poll_events() if w.keys.escape: w.should_close = True if w.keys.space: dump_window_info(w) glfw.terminate()
def on_key(window, key, scancode, action, mods): if action == glfw.Window.PRESS and key == glfw.Keys.ESCAPE: window.should_close = True if __name__ == '__main__': glfw.init() pm = glfw.get_primary_monitor() vm = pm.video_modes[-1] win = glfw.Window(vm.width, vm.height, "nayadra", pm) win.swap_interval(0) win.set_key_callback(on_key) if not win.monitor == pm: raise Exception("Wrong monitor set!") jst = glfw.Joystick(0) with win: render = Render(win.framebuffer_size) dom = Domain() def calc_movement(jst, n_axis, keyneg, keypos): jst_move = jst and round(jst.axes[n_axis], 1) and jst.axes[n_axis]
titles = "Foo", "Bar", "Baz", "Quux" colors = ((0.0, 0.0, 1.0, 0.0), (1.0, 0.0, 0.0, 0.0), (0.0, 1.0, 0.0, 0.0), (1.0, 1.0, 0.0, 0.0)) if __name__ == '__main__': running = True windows = [None, None, None, None] if not fw.init(): sys.exit(1) fw.Window.hint(visible=False) for i in range(4): windows[i] = fw.Window(200, 200, titles[i]) if not windows[i]: fw.terminate() sys.exit(1) windows[i].make_current() glClearColor(*colors[i]) windows[i].pos = 100 + (i & 1) * 300, 100 + (i >> 1) * 300 windows[i].show() while running: for i in range(4): windows[i].make_current() glClear(GL_COLOR_BUFFER_BIT)
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"))