def main(): if not glfw.init(): return window = glfw.create_window(640, 480, "ラララ", None, None) if not window: glfw.terminate() return #init glfw.make_context_current(window) gluOrtho2D(0.0, 640, 0.0, 480) #where is this in glfw? # loop while not glfw.window_should_close(window): glClear(GL_COLOR_BUFFER_BIT) randomWidth() drawLine(100.0, 400.0, 200.0, 400.0) drawLine(440.0, 400.0, 540.0, 400.0) drawLine(320.0, 350.0, 320.0, 330.0) drawLine(100.0, 400.0, 200.0, 400.0) drawLine(300.0, 200.0, 340.0, 200.0) glfw.swap_buffers(window) glfw.poll_events() glfw.swap_interval(2) glfw.terminate()
def __init__(self, actors=[], title="GlfwApp"): """Creates an OpenGL context and a window, and acquires OpenGL resources""" renderer = gl_renderer.OpenVrGlRenderer(actor=actors, multisample=2) self.renderer = renderer self.title = title self._is_initialized = False # keep track of whether self.init_gl() has been called if not glfw.init(): raise Exception("GLFW Initialization error") # Use modern OpenGL version 4.5 core glfw.window_hint(glfw.CONTEXT_VERSION_MAJOR, 4) glfw.window_hint(glfw.CONTEXT_VERSION_MINOR, 5) glfw.window_hint(glfw.OPENGL_PROFILE, glfw.OPENGL_CORE_PROFILE) # Double buffered screen mirror stalls VR headset rendering, # So use single-buffering glfw.window_hint(glfw.DOUBLEBUFFER, False) self.window = glfw.create_window(self.renderer.window_size[0], self.renderer.window_size[1], self.title, None, None) if self.window is None: glfw.terminate() raise Exception("GLFW window creation error") glfw.set_key_callback(self.window, self.key_callback) glfw.make_context_current(self.window) glfw.swap_interval(0)
def main(): if not glfw.init(): return window = glfw.create_window(480,480,"2018008177",None,None) if not window: glfw.terminate() return glfw.make_context_current(window) glfw.swap_interval(1) while not glfw.window_should_close(window): glfw.poll_events() t = glfw.get_time() th = t*np.radians(60) R = np.array([[np.cos(th), -np.sin(th), 0.], [np.sin(th), np.cos(th), 0.], [0., 0., 1.]]) T = np.array([[1., 0., .4], [0., 1., .1], [0., 0., 1.]]) render(R @ T) glfw.swap_buffers(window) glfw.terminate()
def main(): global gComposedM if not glfw.init(): return window = glfw.create_window(480,480,"2016024975", None,None) if not window: glfw.terminate() return glfw.set_key_callback(window, key_callback) glfw.make_context_current(window) glfw.swap_interval(1) count = 0 while not glfw.window_should_close(window): glfw.poll_events() #sx = (count % 10) * .1 #sy = sx * 2 #th = np.radians(count % 360) #T = np.array([[np.cos(th), -np.sin(th)], # [np.sin(th), np.cos(th)]]) #T = np.array([[sx, 0.], # [0., sy]]) #a = (count % 10) * .2 #T = np.array([[-1.,a], # [0.,1.]]) #render(T) #count += 1 render(gComposedM) glfw.swap_buffers(window) glfw.terminate()
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, "2016026080-assignment2-1", None, None) if not window: glfw.terminate() return # Make the window's context current glfw.make_context_current(window) glfw.swap_interval(1) # Loop until the user closes the window while not glfw.window_should_close(window): # Poll events glfw.poll_events() t=glfw.get_time() T=np.array([ [np.cos(t), -np.sin(t), np.cos(t)*.5], [np.sin(t), np.cos(t), np.sin(t)*.5], [0., 0., 1.] ]) render(T) # Swap front and back buffers glfw.swap_buffers(window) glfw.terminate()
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()
def __init__(self, width, height, title): self.width = width self.height = height self.dragging = None self.modifiers = 0 if not glfw.init(): sys.exit('GLFW initialization failed') self.window_hints() with Timer('Create Window') as t: self.window = glfw.create_window(self.width, self.height, title, None, None) if not self.window: glfw.terminate() sys.exit('GLFW create window failed') self.set_callbacks() glfw.make_context_current(self.window) glfw.swap_interval(0) self.last_cursor_position = self.get_cursor()
def _gl_state_settings(window): active_window = glfw.get_current_context() glfw.make_context_current(window) gl_utils.basic_gl_setup() gl_utils.make_coord_system_norm_based() glfw.swap_interval(0) glfw.make_context_current(active_window)
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)
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()
def main(): global gVertexArraySeparate if not glfw.init(): return window = glfw.create_window(480,480,'2018008395-10-1', None,None) if not window: glfw.terminate() return glfw.make_context_current(window) glfw.set_key_callback(window, key_callback) glfw.swap_interval(1) # ... gVertexArraySeparate = createVertexArraySeparate() count = 0 while not glfw.window_should_close(window): glfw.poll_events() ang = count % 360 render(ang) count += 1 glfw.swap_buffers(window) glfw.terminate()
def __init__(self): cwd = os.getcwd() # save current working directory glfw.init() # initialize glfw - this changes cwd os.chdir(cwd) # restore cwd glfw.window_hint(glfw.CONTEXT_VERSION_MAJOR, 3) glfw.window_hint(glfw.CONTEXT_VERSION_MINOR, 3) glfw.window_hint(glfw.OPENGL_FORWARD_COMPAT, GL_TRUE) glfw.window_hint(glfw.OPENGL_PROFILE, glfw.OPENGL_CORE_PROFILE) self.width, self.height = 512,512 self.aspect = self.width/float(self.height) self.win = glfw.create_window(self.width, self.height, 'raycaster(2nd order fcc Voronoi Spline)', None, None) glfw.make_context_current(self.win) glfw.swap_interval(0) # for retina display... self.fb_width, self.fb_height = glfw.get_framebuffer_size(self.win) glEnable(GL_DEPTH_TEST) glClearColor(0.0, 0.0, 0.0,0.0) glfw.set_key_callback(self.win, self.onKeyboard) glfw.set_window_size_callback(self.win, self.onSize) self.scene = Scene(self.fb_width, self.fb_height) self.exitNow = False
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.swap_interval(1) count = 0 while not glfw.window_should_close(window): glfw.poll_events() render(gcamAng, count) glfw.swap_buffers(window) count += 1 glfw.terminate()
def main(): if not glfw.init(): return window = glfw.create_window(800, 800, '2015004466', None, None) if not window: glfw.terminate() return glfw.make_context_current(window) glfw.set_key_callback(window, key_callback) glfw.set_drop_callback(window, drop_callback) glfw.set_mouse_button_callback(window, button_callback) glfw.set_cursor_pos_callback(window, cursor_callback) glfw.set_scroll_callback(window, scroll_callback) glfw.swap_interval(1) count = 0 while not glfw.window_should_close(window): glfw.poll_events() ang = count % 360 render(ang) count += 1 glfw.swap_buffers(window) glfw.terminate()
def main(): global gToggle, count # Initialize the library if not glfw.init(): return # Create a windowed mode window and its OpenGL context window = glfw.create_window(800, 800, "2016025105", None, None) if not window: glfw.terminate() return # Make the window's context current glfw.make_context_current(window) glfw.set_key_callback(window, key_callback) glfw.set_cursor_pos_callback(window, cursor_callback) glfw.set_mouse_button_callback(window, button_callback) glfw.set_scroll_callback(window, scroll_callback) glfw.set_drop_callback(window, drop_callback) glfw.swap_interval(1) # Loop until the user closes the window count = 0 while not glfw.window_should_close(window): # Poll for and process events glfw.poll_events() # Render here, e.g. using pyOpenGL render(count) # Swap front and back buffers glfw.swap_buffers(window) if gToggle == True: count += 1 glfw.terminate()
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()
def main(): global gVertexArraySeparate if not glfw.init(): return global gVertexArrayIndexed, gIndexArray window = glfw.create_window(480, 480, '2018008177', None, None) if not window: glfw.terminate() return glfw.make_context_current(window) glfw.set_key_callback(window, key_callback) glfw.swap_interval(1) gVertexArrayIndexed, gIndexArray = createVertexAndIndexArrayIndexed() while not glfw.window_should_close(window): glfw.poll_events() render() glfw.swap_buffers(window) glfw.terminate()
def main(): if not glfw.init(): return window = glfw.create_window(480,480, 'rotating point&vector', None,None) if not window: glfw.terminate() return glfw.make_context_current(window) glfw.swap_interval(1) while not glfw.window_should_close(window): glfw.poll_events() t = glfw.get_time() #rotate t in ccw / 시간 t의 rad만큼 반시계 회전 R = np.array([[np.cos(t), -np.sin(t), 0.], [np.sin(t), np.cos(t), 0.], [0., 0., 1.]]) #translate 0.5 in x / x축 방향 0.5 이동 T = np.array([[1.,0.,.5], [0.,1.,0.], [0.,0.,1.]]) #first traslate and second rotate / 이동 후 회전 (l to r in local) 백터곱 render(R@T) glfw.swap_buffers(window) glfw.terminate()
def impl_glfw_init(): width, height = 1280, 960 window_name = "minimal ImGui/GLFW3 example" if not glfw.init(): print("Could not initialize OpenGL context") exit(1) # OS X supports only forward-compatible core profiles from 3.2 # 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 not window: glfw.terminate() print("Could not initialize Window") exit(1) glMatrixMode(GL_PROJECTION) glLoadIdentity() glfw.swap_interval(1) glMatrixMode(GL_MODELVIEW) glLoadIdentity() 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.OPENGL_FORWARD_COMPAT, gl.GL_TRUE) return window
def main(): global gVertexArraySeparate # Initialize the library if not glfw.init(): return # Create a windowed mode window and its OpenGL context window = glfw.create_window(640, 640, "2016025887", None, None) if not window: glfw.terminate() return # Make the window's context current glfw.make_context_current(window) glfw.set_key_callback(window, key_callback) glfw.set_cursor_pos_callback(window, cursor_callback) glfw.set_mouse_button_callback(window, button_callback) glfw.set_scroll_callback(window, scroll_callback) glfw.swap_interval(1) obj_drop() # Loop until the user closes the window while not glfw.window_should_close(window): # Poll for and process events glfw.poll_events() # Render here, e.g. using pyOpenGL render() # Swap front and back buffers glfw.swap_buffers(window) glfw.terminate()
def main(): global KEY_SPACE global frame_now, frame_num if not glfw.init(): return window = glfw.create_window(800, 800, '2014000082-class-3', None, None) if not window: glfw.terminate() return glfw.set_drop_callback(window, drop_callback) glfw.set_key_callback(window, key_callback) glfw.make_context_current(window) glfw.set_cursor_pos_callback(window, cursor_callback) glfw.set_mouse_button_callback(window, button_callback) glfw.set_scroll_callback(window, scroll_callback) glfw.swap_interval(1) while not glfw.window_should_close(window): glfw.poll_events() render() glfw.swap_buffers(window) if KEY_SPACE: frame_now += 1 frame_now %= frame_num glfw.terminate()
def main(): global gVertexArraySeparate, gVertexArrayIndexed, gIndexArray if not glfw.init(): return window = glfw.create_window(640, 640, 'OBJViewer', None, None) if not window: glfw.terminate() return glfw.set_drop_callback(window, drop_callback) glfw.make_context_current(window) glfw.set_key_callback(window, key_callback) glfw.swap_interval(1) count = 300 while not glfw.window_should_close(window): glfw.poll_events() ang = count % 360 render(ang) count += 1 glfw.swap_buffers(window) glfw.terminate()
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,"2017029752-3-1", None,None) if not window: glfw.terminate() return glfw.set_key_callback(window, key_callback) # Make the window's context current glfw.make_context_current(window) # set the number of screen refresh to wait before calling glfw.swap_buffer(). # if your monitor refresh rate is 60Hz, the while loop is repeated every 1/60 sec glfw.swap_interval(1) while not glfw.window_should_close(window): glfw.poll_events() render(T) glfw.swap_buffers(window) glfw.terminate()
def main(): global gVertexArraySeparate #initialize the library if not glfw.init(): return #Create a windowed mode window and its OpenGL context window = glfw.create_window(640, 640, "2012004021", None, None) if not window: glfw.terminate() return #Make the window's context current glfw.make_context_current(window) glfw.set_key_callback(window, key_callback) glfw.swap_interval(1) gVertexArraySeparate = createVertexArraySeparate() count = 0 #Loop until the user closes the window while not glfw.window_should_close(window): #Poll events glfw.poll_events() ang = count % 360 render(ang) count += 1 #Swap front and back buffers glfw.swap_buffers(window) glfw.terminate()
def mainLoop(self) -> None: glfw.make_context_current(self.window) glfw.poll_events() newtime = glfw.get_time() self.layercontext.dt = min(0.2, newtime - self.layercontext.time) # Limit delta time to 0.2 to prevent fuckery self.layercontext.time = newtime # Run async loop once #self.asyncloop.stop() #self.asyncloop.run_forever() glClearColor(0.0, 0.0, 0.0, 1.) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glViewport(0, 0, self.layercontext.resolution[0], self.layercontext.resolution[1]) self.loop() glfw.swap_buffers(self.window) glfw.swap_interval(1) self.layercontext.frame = self.layercontext.frame + 1
def main(): if not glfw.init(): print ('GLFW initialization failed') sys.exit(-1) width = 800; height = 600; window = glfw.create_window(width, height, 'modern opengl example', None, None) if not window: glfw.terminate() sys.exit(-1) glfw.make_context_current(window) glfw.set_key_callback(window, onKeyPress) glfw.set_mouse_button_callback(window, onMouseButton) glfw.set_cursor_pos_callback(window, onMouseDrag) glfw.swap_interval(1) initialize(window); while not glfw.window_should_close(window): glfw.poll_events() display() glfw.swap_buffers(window) glfw.terminate()
def main(): global R, T if not glfw.init(): return window = glfw.create_window(480, 480, "2015004584", None, None) if not window: glfw.terminate() return glfw.set_key_callback(window, key_callback) glfw.make_context_current(window) glfw.swap_interval(0) while not glfw.window_should_close(window): glfw.poll_events() clear() axis() glMultMatrixf(R.T) glMultMatrixf(T.T) render() glfw.swap_buffers(window) glfw.terminate()
def main(): # Initialize the library if not glfw.init(): return # Create a windowed mode window and its OpenGL context window = glfw.create_window(720, 720, "2015005141", None, None) if not window: glfw.terminate() return # Make the window's context current glfw.make_context_current(window) glfw.set_mouse_button_callback(window, button_callback) glfw.set_scroll_callback(window, scroll_callback) glfw.set_drop_callback(window, drop_callback) glfw.set_key_callback(window, key_callback) # Loop until the user closes the window while not glfw.window_should_close(window): # Poll for and process events glfw.poll_events() render(gCamAng) glfw.swap_interval(1) # Swap front and back buffers glfw.swap_buffers(window) glfw.terminate()
def main(): # Initialize the library if not glfw.init(): return window = glfw.create_window(640, 640, "OHT", None, None) if not window: glfw.terminate() return glfw.make_context_current(window) glfw.swap_interval(10) count = 0 while not glfw.window_should_close(window): glfw.poll_events() M = np.array([1, 1]) u = np.array([.1, .1]) render(M, u) glfw.swap_buffers(window) glfw.terminate()
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.swap_interval(30) #Loop until the user closes the window while not glfw.window_should_close(window): #Poll events glfw.poll_events() th = np.radians(60) R = np.array([[np.cos(th), -np.sin(th), 0.], [np.sin(th), np.cos(th), 0.], [0., 0., 1.]]) T = np.array([[1., 0., .4], [0., 1., .0], [0., 0., .1]]) render(T @ R) #Render here, e.g. using pyOpenGL #Swap front and back buffers glfw.swap_buffers(window) glfw.terminate()
def main(): if not glfw.init(): return window = glfw.create_window(480, 480, "2016025423", None, None) if not window: glfw.terminate() return glfw.make_context_current(window) glfw.swap_interval(1) while not glfw.window_should_close(window): glfw.poll_events() t = glfw.get_time() #rotate th = t R = np.array([[np.cos(th), -np.sin(th), 0.], [np.sin(th), np.cos(th), 0.], [0., 0., 1.]]) #translate T = np.array([[1., 0., .3], [0., 1., .3], [0., 0., 1.]]) render(R @ T) glfw.swap_buffers(window) glfw.terminate()
def main(): global gVertexArraySeparate if not glfw.init(): return window = glfw.create_window(800, 800, "2016025687", None, None) if not window: glfw.terminate() return glfw.set_drop_callback(window, drop_callback) glfw.make_context_current(window) glfw.set_cursor_pos_callback(window, cursor_callback) glfw.set_scroll_callback(window, scroll_callback) glfw.set_mouse_button_callback(window, button_callback) glfw.set_key_callback(window, key_callback) glfw.swap_interval(1) gVertexArraySeparate = createVertexArraySeparate() while not glfw.window_should_close(window): glfw.poll_events() render() glfw.swap_buffers(window) glfw.terminate()
def init(this): if not glfw.init(): return this.windowID = glfw.create_window(640, 480, "Test", None, None) glfw.show_window(this.windowID) glfw.make_context_current(this.windowID) glfw.swap_interval(1) glClearColor(0, 0, 0, 1);
def initGL(self): if not glfw.init(): sys.exit(1) self.window = glfw.create_window(640, 480, "Hello", None, None) print self.window glfw.make_context_current(self.window) glfw.swap_interval(1) glfw.set_key_callback(self.window, self.key_callback) glClearColor(0.5, 0.5, 0.5, 1)
def show(molecule, width=500, height=500, show_bonds=True, bonds_method='radii', bonds_param=None, camera=None, title='mogli'): """ Interactively show the given molecule with OpenGL. By default, bonds are drawn, if this is undesired the show_bonds parameter can be set to False. For information on the bond calculation, see Molecule.calculate_bonds. If you pass a tuple of camera position, center of view and an up vector to the camera parameter, the camera will be set accordingly. Otherwise the molecule will be viewed in the direction of the z axis, with the y axis pointing upward. """ global _camera molecule.positions -= np.mean(molecule.positions, axis=0) max_atom_distance = np.max(la.norm(molecule.positions, axis=1)) if show_bonds: molecule.calculate_bonds(bonds_method, bonds_param) # If GR3 was initialized earlier, it would use a different context, so # it will be terminated first. gr3.terminate() # Initialize GLFW and create an OpenGL context glfw.init() glfw.window_hint(glfw.SAMPLES, 16) window = glfw.create_window(width, height, title, None, None) glfw.make_context_current(window) glEnable(GL_MULTISAMPLE) # Set up the camera (it will be changed during mouse rotation) if camera is None: camera_distance = -max_atom_distance*2.5 camera = ((0, 0, camera_distance), (0, 0, 0), (0, 1, 0)) camera = np.array(camera) _camera = camera # Create the GR3 scene gr3.setbackgroundcolor(255, 255, 255, 0) _create_gr3_scene(molecule, show_bonds) # Configure GLFW glfw.set_cursor_pos_callback(window, _mouse_move_callback) glfw.set_mouse_button_callback(window, _mouse_click_callback) glfw.swap_interval(1) # Start the GLFW main loop while not glfw.window_should_close(window): glfw.poll_events() width, height = glfw.get_window_size(window) glViewport(0, 0, width, height) _set_gr3_camera() glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) gr3.drawimage(0, width, 0, height, width, height, gr3.GR3_Drawable.GR3_DRAWABLE_OPENGL) glfw.swap_buffers(window) glfw.terminate() gr3.terminate()
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()
def main(): # 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 window = glfw.create_window(300, 300, "shader-test", None, None) if not window: glfw.terminate() return # Move Window glfw.set_window_pos(window, 1600, 50) # Make the window's context current glfw.make_context_current(window) # vsync glfw.swap_interval(1) # Setup GL shaders, data, etc. initialize() # Loop until the user closes the window while not glfw.window_should_close(window): # Render here, e.g. using pyOpenGL render() # Swap front and back buffers glfw.swap_buffers(window) # Poll for and process events glfw.poll_events() glfw.terminate()
def __init__(self, width=800, height=600, title="aiv"): 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.OPENGL_PROFILE, glfw.OPENGL_CORE_PROFILE) self.window = glfw.create_window(width, height, title, None, None) glfw.make_context_current(self.window) glfw.swap_interval(1) self.time = glfw.get_time() self.delta_time = 0 self.aspect_ratio = float(width) / float(height)
def init(self): ''' initialization that must be done in rendering thread ''' # creating the opengl context self.handle = glfw.create_window(self.width, self.height, self.title, None, None); if self.handle == None: glfw.terminate() msg = "GLFW cannot create the window: width={width}, height={height}, title={title}".format( width=self.width, height=self.height, title=self.title) raise RuntimeError(msg) glfw.set_window_pos(self.handle, *self.DF_POSITION) glfw.make_context_current(self.handle) glfw.set_input_mode(self.handle, glfw.STICKY_KEYS, 1) glfw.swap_interval(self.DF_INTERVAL) glClearColor(*self.background_color)
def main(): glfw.init() window = glfw.create_window( 640, 480, "glfw triangle", None, None ) glfw.make_context_current( window ) glfw.swap_interval( 1 ) glfw.set_key_callback( window, on_key ) while not glfw.window_should_close( window ): # set up model view width, height = glfw.get_framebuffer_size( window ) ratio = width / float(height) gl.glViewport( 0, 0, width, height ) gl.glClear( gl.GL_COLOR_BUFFER_BIT ) gl.glMatrixMode( gl.GL_PROJECTION ) gl.glLoadIdentity() gl.glOrtho( -ratio, ratio, -1.0, 1.0, 1.0, -1.0 ) gl.glMatrixMode( gl.GL_MODELVIEW ) gl.glLoadIdentity() gl.glRotatef( float(glfw.get_time()) * 50.0, 0.0, 0.0, 1.0 ) # draw triangle gl.glBegin(gl.GL_TRIANGLES); gl.glColor3f( 1.0, 0.0, 0.0 ) gl.glVertex3f( -0.6, -0.4, 0.0 ) gl.glColor3f( 0.0, 1.0, 0.0 ) gl.glVertex3f( 0.6, -0.4, 0.0 ) gl.glColor3f( 0.0, 0.0, 1.0 ) gl.glVertex3f( 0.0, 0.6, 0.0 ) gl.glEnd() # swap buffers glfw.swap_buffers(window) # poll for events glfw.poll_events() glfw.destroy_window(window) glfw.terminate()
def main(): if not glfw.init(): return window = HOS(640, 640, '2015004584') if not window.context: glfw.terminate() return glfw.make_context_current(window.context) glfw.set_key_callback(window.context, window._callback_key) glfw.set_drop_callback(window.context, window._callback_drop) glfw.swap_interval(1) while not glfw.window_should_close(window.context): glfw.poll_events() window.render() glfw.swap_buffers(window.context) glfw.terminate()
def main(): global T if not glfw.init(): return window = glfw.create_window(480, 480, "Hello World", None, None) if not window: glfw.terminate() return glfw.set_key_callback(window, key_callback) glfw.make_context_current(window) glfw.swap_interval(0) while not glfw.window_should_close(window): glfw.poll_events() render(T) glfw.swap_buffers(window) glfw.terminate()
def init_gl(self): if self._is_initialized: return # only initialize once if not glfw.init(): raise Exception("GLFW Initialization error") # Get OpenGL 4.1 context glfw.window_hint(glfw.CONTEXT_VERSION_MAJOR, 4) glfw.window_hint(glfw.CONTEXT_VERSION_MINOR, 1) glfw.window_hint(glfw.OPENGL_PROFILE, glfw.OPENGL_CORE_PROFILE) # Double buffered screen mirror stalls VR headset rendering, # So use single-buffering glfw.window_hint(glfw.DOUBLEBUFFER, False) glfw.swap_interval(0) self.window = glfw.create_window(self.renderer.window_size[0], self.renderer.window_size[1], self.title, None, None) if self.window is None: glfw.terminate() raise Exception("GLFW window creation error") glfw.set_key_callback(self.window, self.key_callback) glfw.make_context_current(self.window) if self.renderer is not None: self.renderer.init_gl() self._is_initialized = True
def __init__(self, renderer, title="GLFW test"): "Creates an OpenGL context and a window, and acquires OpenGL resources" self.renderer = renderer self.title = title self._is_initialized = False # keep track of whether self.init_gl() has been called if not glfw.init(): raise Exception("GLFW Initialization error") # Get OpenGL 4.1 context glfw.window_hint(glfw.CONTEXT_VERSION_MAJOR, 4) glfw.window_hint(glfw.CONTEXT_VERSION_MINOR, 1) glfw.window_hint(glfw.OPENGL_PROFILE, glfw.OPENGL_CORE_PROFILE) # Double buffered screen mirror stalls VR headset rendering, # So use single-buffering glfw.window_hint(glfw.DOUBLEBUFFER, False) self.window = glfw.create_window(self.renderer.window_size[0], self.renderer.window_size[1], self.title, None, None) if self.window is None: glfw.terminate() raise Exception("GLFW window creation error") glfw.set_key_callback(self.window, self.key_callback) glfw.make_context_current(self.window) glfw.swap_interval(0)
def initMuJoCo(filename, width2, height): ''' load model, init simulation and rendering ''' global window, sim, ctx assert glfw.init(), 'Could not initialize GLFW' glfw.window_hint(glfw.SAMPLES, 0) glfw.window_hint(glfw.DOUBLEBUFFER, True) glfw.window_hint(glfw.RESIZABLE, 0) window = glfw.create_window(width2 // 4, height // 2, "mjvive.py", None, None) assert window, "Could not create GLFW window" glfw.make_context_current(window) glfw.swap_interval(0) # GLEW init required in C++, not in Python sim = MjSim(load_model_from_xml(open(filename).read())) sim.forward() sim.model.vis.global_.offwidth = width2 sim.model.vis.global_.offheight = height sim.model.vis.quality.offsamples = 8 ctx = MjRenderContext(sim) ctx.scn.enabletransform = 1 ctx.scn.translate[1:3] = -0.5 ctx.scn.rotate[0:2] = math.cos(-0.25 * math.pi), math.sin(-0.25 * math.pi) ctx.scn.scale = 1 ctx.scn.stereo = STEREO_SIDEBYSIDE
def main(): global gVertexArraySeparate global gVertexArrayIndexed, gIndexArray 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.swap_interval(1) gVertexArraySeparate = createVertexArraySeparate() gVertexArrayIndexed, gIndexArray = createVertexAndIndexArrayIndexed() count = 0 while not glfw.window_should_close(window): glfw.poll_events() ang = count % 360 render(ang) count += 1 glfw.swap_buffers(window) glfw.terminate()
def main(): import os import sys os.chdir(os.path.dirname(__file__)) import glfw import time from engine import Engine # Initialize the library if not glfw.init(): sys.exit() glfw.window_hint(glfw.CONTEXT_VERSION_MAJOR, 4) glfw.window_hint(glfw.CONTEXT_VERSION_MINOR, 3) glfw.window_hint(glfw.SAMPLES, 16) # Create a windowed mode window and its OpenGL context window = glfw.create_window(640, 480, "Window Name", None, None) if not window: print "Couldn't initialize OpenGL. Check that your OpenGL version >4.3." glfw.terminate() sys.exit() # Make the window's context current glfw.make_context_current(window) # Get window size width, height = glfw.get_framebuffer_size(window) # Create engine engine = Engine(window) engine.setWindowHeight(height) engine.setWindowWidth(width) def on_resize(window, width, height): engine.setWindowWidth(width) engine.setWindowHeight(height) # Install a window size handler glfw.set_window_size_callback(window, on_resize) def on_key(window, key, scancode, action, mods): if key == glfw.KEY_ESCAPE and action == glfw.PRESS: glfw.set_window_should_close(window, 1) # Install a key handler glfw.set_key_callback(window, on_key) def on_mouse(window, button, action, mods): if button == glfw.MOUSE_BUTTON_1 and action == glfw.PRESS: engine.shoot_on() if button == glfw.MOUSE_BUTTON_1 and action == glfw.RELEASE: engine.shoot_off() if button == glfw.MOUSE_BUTTON_2 and action == glfw.PRESS: engine.camera_switch() glfw.set_mouse_button_callback(window, on_mouse) def on_scroll(window, x, y): engine.camera_scroll(y) glfw.set_scroll_callback(window, on_scroll) old_time = time.time() elapsed_time = 0.0 # Loop until the user closes the window while not glfw.window_should_close(window): # Calculate elapsed time elapsed_time = time.time() - old_time old_time = time.time() # Process engine.step(elapsed_time) # Swap front and back buffers glfw.swap_interval(1) glfw.swap_buffers(window) # Poll for and process events glfw.poll_events() # Don't be egoist :) time.sleep(0.01) glfw.terminate()
def __init__(self, win, *args, **kwargs): """Set up the backend window according the params of the PsychoPy win Before PsychoPy 1.90.0 this code was executed in Window._setupPygame() Parameters ---------- win : psychopy.visual.Window instance PsychoPy Window (usually not fully created yet). share : psychopy.visual.Window instance PsychoPy Window to share a context with bpc : array_like Bits per color (R, G, B). refreshHz : int Refresh rate in Hertz. depthBits : int, Framebuffer (back buffer) depth bits. stencilBits : int Framebuffer (back buffer) stencil bits. swapInterval : int Screen updates before swapping buffers. winTitle : str Optional window title string. *args Additional position arguments. **kwargs Additional keyword arguments. """ BaseBackend.__init__(self, win) # window to share a context with shareWin = kwargs.get('share', None) if shareWin is not None: if shareWin.winType == 'glfw': shareContext = shareWin.winHandle else: logging.warning( 'Cannot share a context with a non-GLFW window. Disabling.') shareContext = None else: shareContext = None if sys.platform=='darwin' and not win.useRetina and pyglet.version >= "1.3": raise ValueError("As of PsychoPy 1.85.3 OSX windows should all be " "set to useRetina=True (or remove the argument). " "Pyglet 1.3 appears to be forcing " "us to use retina on any retina-capable screen " "so setting to False has no effect.") # window framebuffer configuration win.bpc = kwargs.get('bpc', (8, 8, 8)) # nearly all displays use 8 bpc win.refreshHz = int(kwargs.get('refreshHz', 60)) win.depthBits = int(kwargs.get('depthBits', 8)) win.stencilBits = int(kwargs.get('stencilBits', 8)) # TODO - make waitBlanking set this too, independent right now win.swapInterval = int(kwargs.get('swapInterval', 1)) # vsync ON if 1 # get monitors, with GLFW the primary display is ALWAYS at index 0 allScrs = glfw.get_monitors() if len(allScrs) < int(win.screen) + 1: logging.warn("Requested an unavailable screen number - " "using first available.") win.screen = 0 thisScreen = allScrs[win.screen] if win.autoLog: logging.info('configured GLFW screen %i' % win.screen) # find a matching video mode (can we even support this configuration?) isVidmodeSupported = False for vidmode in glfw.get_video_modes(thisScreen): size, bpc, hz = vidmode if win._isFullScr: # size and refresh rate are ignored if windowed hasSize = size == tuple(win.size) hasHz = hz == win.refreshHz else: hasSize = hasHz = True hasBpc = bpc == tuple(win.bpc) if hasSize and hasBpc and hasHz: isVidmodeSupported = True break nativeVidmode = glfw.get_video_mode(thisScreen) if not isVidmodeSupported: # the requested video mode is not supported, use current logging.warning( ("The specified video mode is not supported by this display, " "using native mode ...")) logging.warning( ("Overriding user video settings: size {} -> {}, bpc {} -> " "{}, refreshHz {} -> {}".format( tuple(win.size), nativeVidmode[0], tuple(win.bpc), nativeVidmode[1], win.refreshHz, nativeVidmode[2]))) # change the window settings win.size, win.bpc, win.refreshHz = nativeVidmode if win._isFullScr: useDisplay = thisScreen else: useDisplay = None # configure stereo useStereo = 0 if win.stereo: # provide warning if stereo buffers are requested but unavailable if not glfw.extension_supported('GL_STEREO'): logging.warning( 'A stereo window was requested but the graphics ' 'card does not appear to support GL_STEREO') win.stereo = False else: useStereo = 1 # setup multisampling # This enables multisampling on the window backbuffer, not on other # framebuffers. msaaSamples = 0 if win.multiSample: maxSamples = (GL.GLint)() GL.glGetIntegerv(GL.GL_MAX_SAMPLES, maxSamples) if (win.numSamples & (win.numSamples - 1)) != 0: # power of two? logging.warning( 'Invalid number of MSAA samples provided, must be ' 'power of two. Disabling.') elif 0 > win.numSamples > maxSamples.value: # check if within range logging.warning( 'Invalid number of MSAA samples provided, outside of valid ' 'range. Disabling.') else: msaaSamples = win.numSamples win.multiSample = msaaSamples > 0 # disable stencil buffer if not win.allowStencil: win.stencilBits = 0 # set buffer configuration hints glfw.window_hint(glfw.RED_BITS, win.bpc[0]) glfw.window_hint(glfw.GREEN_BITS, win.bpc[1]) glfw.window_hint(glfw.BLUE_BITS, win.bpc[2]) glfw.window_hint(glfw.REFRESH_RATE, win.refreshHz) glfw.window_hint(glfw.STEREO, useStereo) glfw.window_hint(glfw.SAMPLES, msaaSamples) glfw.window_hint(glfw.STENCIL_BITS, win.stencilBits) glfw.window_hint(glfw.DEPTH_BITS, win.depthBits) glfw.window_hint(glfw.AUTO_ICONIFY, 0) # window appearance and behaviour hints if not win.allowGUI: glfw.window_hint(glfw.DECORATED, 0) # create the window self.winHandle = glfw.create_window( width=win.size[0], height=win.size[1], title=str(kwargs.get('winTitle', "PsychoPy (GLFW)")), monitor=useDisplay, share=shareContext) # The window's user pointer maps the Python Window object to its GLFW # representation. glfw.set_window_user_pointer(self.winHandle, win) glfw.make_context_current(self.winHandle) # ready to use # set the position of the window if not fullscreen if not win._isFullScr: # if no window position is specified, centre it on-screen if win.pos is None: size, bpc, hz = nativeVidmode win.pos = [(size[0] - win.size[0]) / 2.0, (size[1] - win.size[1]) / 2.0] # get the virtual position of the monitor, apply offset to the # window position px, py = glfw.get_monitor_pos(thisScreen) glfw.set_window_pos(self.winHandle, int(win.pos[0] + px), int(win.pos[1] + py)) elif win._isFullScr and win.pos is not None: logging.warn("Ignoring window 'pos' in fullscreen mode.") # set the window icon glfw.set_window_icon(self.winHandle, 1, _WINDOW_ICON_) # set the window size to the framebuffer size win.size = np.array(glfw.get_framebuffer_size(self.winHandle)) if win.useFBO: # check for necessary extensions if not glfw.extension_supported('GL_EXT_framebuffer_object'): msg = ("Trying to use a framebuffer object but " "GL_EXT_framebuffer_object is not supported. Disabled") logging.warn(msg) win.useFBO = False if not glfw.extension_supported('GL_ARB_texture_float'): msg = ("Trying to use a framebuffer object but " "GL_ARB_texture_float is not supported. Disabling") logging.warn(msg) win.useFBO = False # Assign event callbacks, these are dispatched when 'poll_events' is # called. glfw.set_mouse_button_callback(self.winHandle, event._onGLFWMouseButton) glfw.set_scroll_callback(self.winHandle, event._onGLFWMouseScroll) glfw.set_key_callback(self.winHandle, event._onGLFWKey) glfw.set_char_mods_callback(self.winHandle, event._onGLFWText) # Enable vsync, GLFW has additional setting for this that might be # useful. glfw.swap_interval(win.swapInterval) # give the window class GLFW specific methods win.setMouseType = self.setMouseType if not win.allowGUI: self.setMouseVisibility(False)
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()
def setSwapInterval(self, interval): """Set the swap interval for the current GLFW context.""" glfw.swap_interval(interval)
quad.draw() gui.modelMatrix = translate(array([-0.3, -0.2, 0.2], "f")) gui.sendMatrices() gui.setColor(array([0, 1, 0, 0.5], "f")) quad.draw() gui.modelMatrix = translate(array([0.3, -0.2, 0.1], "f")) gui.sendMatrices() gui.setColor(array([0, 0, 1, 0.5], "f")) quad.draw() # Loop until the user closes the window while not glfw.window_should_close(window): # Calculate elapsed time elapsed_time = time.time() - old_time old_time = time.time() # Render scene render() # Swap front and back buffers glfw.swap_interval(1) glfw.swap_buffers(window) # Poll for and process events glfw.poll_events() # Don't be egoist :) time.sleep(0.01) glfw.terminate()
def disable_vsyc(): import glfw glfw.swap_interval(0)
def enable_vsyc(): import glfw glfw.swap_interval(1)