def __init__(self, *args, **kwargs): BaseCanvasBackend.__init__(self) title, size, show, position = self._process_backend_kwargs(kwargs) glut.glutInitWindowSize(size[0], size[1]) self._id = glut.glutCreateWindow(title.encode('ASCII')) if not self._id: raise RuntimeError('could not create window') glut.glutSetWindow(self._id) _VP_GLUT_ALL_WINDOWS.append(self) # Cache of modifiers so we can send modifiers along with mouse motion self._modifiers_cache = () self._closed = False # Keep track whether the widget is closed # Register callbacks glut.glutDisplayFunc(self.on_draw) glut.glutReshapeFunc(self.on_resize) # glut.glutVisibilityFunc(self.on_show) glut.glutKeyboardFunc(self.on_key_press) glut.glutSpecialFunc(self.on_key_press) glut.glutKeyboardUpFunc(self.on_key_release) glut.glutMouseFunc(self.on_mouse_action) glut.glutMotionFunc(self.on_mouse_motion) glut.glutPassiveMotionFunc(self.on_mouse_motion) _set_close_fun(self._id, self.on_close) self._vispy_canvas_ = None if position is not None: self._vispy_set_position(*position) if not show: glut.glutHideWindow()
def run(self): glut.glutInit(sys.argv) glut.glutInitWindowSize(500, 500) glut.glutInitDisplayMode(glut.GLUT_RGBA | glut.GLUT_DOUBLE | glut.GLUT_DEPTH) self.win = glut.glutCreateWindow(b'Molecular visualizer') glut.glutDisplayFunc(self.display) glut.glutReshapeFunc(self.reshape) glut.glutKeyboardFunc(self.keyboard) glut.glutMotionFunc(self.rotate) glut.glutMouseFunc(self.mouse) gl.glClearColor(0, 0, 0, 1) gl.glEnable(gl.GL_DEPTH_TEST) gl.glEnable(gl.GL_LIGHTING) gl.glEnable(gl.GL_LIGHT0) gl.glColorMaterial(gl.GL_FRONT, gl.GL_DIFFUSE) gl.glEnable(gl.GL_COLOR_MATERIAL) # very diffuse and dark specular highlights, to make black visible gl.glMaterial(gl.GL_FRONT, gl.GL_SPECULAR, (.1, .1, .1, 1)) gl.glMaterial(gl.GL_FRONT, gl.GL_SHININESS, 5) self.displist = gl.glGenLists(1) gl.glNewList(self.displist, gl.GL_COMPILE) self.draw_atoms(self.molecule) gl.glEndList() glut.glutMainLoop()
def init(self): if not self.__is_initialized: self.__is_initialized = True sys.argv = glut.glutInit(sys.argv) glut.glutInitDisplayMode(glut.GLUT_DOUBLE | glut.GLUT_RGBA | glut.GLUT_DEPTH) self.__windowsize = (400,400) glut.glutInitWindowSize(self.__windowsize[0],self.__windowsize[1]) glut.glutCreateWindow(self.__name) gl.glShadeModel(gl.GL_SMOOTH) gl.glEnable(gl.GL_CULL_FACE) gl.glEnable(gl.GL_DEPTH_TEST) gl.glEnable(gl.GL_LIGHTING) glut.glutDisplayFunc(self.__display) glut.glutMouseFunc(self.__onMouse) glut.glutMotionFunc(self.__onMouseMotion) glut.glutMouseWheelFunc(self.__onWheel) glut.glutReshapeFunc(self.__onReshape) self.__onReshape(400,400) def sleep_forever(): self.__am_slow = False if not self._window_closed: print('program complete, but still running visualization...') while True: glut.glutMainLoopEvent() atexit.register(sleep_forever)
def run(self, ): print("\n") print("space bar: simulation on/off") print("' ': run/stop simulation") print("'a': run/stop animation") print("'[' and ']': play one frame backward and forward") # Init glut GLUT.glutInit(()) GLUT.glutInitDisplayMode(GLUT.GLUT_RGBA | GLUT.GLUT_DOUBLE | GLUT.GLUT_MULTISAMPLE | GLUT.GLUT_ALPHA | GLUT.GLUT_DEPTH) GLUT.glutInitWindowSize(*self.window_size) GLUT.glutInitWindowPosition(0, 0) self.window = GLUT.glutCreateWindow(self.title) # Init functions # glutFullScreen() GLUT.glutDisplayFunc(self.drawGL) GLUT.glutIdleFunc(self.idle) GLUT.glutReshapeFunc(self.resizeGL) GLUT.glutKeyboardFunc(self.keyPressed) GLUT.glutMouseFunc(self.mouseFunc) GLUT.glutMotionFunc(self.motionFunc) GLUT.glutTimerFunc(25, self.renderTimer, 1) self.initGL(*self.window_size) # Run GLUT.glutMainLoop()
def main(self): self.location = np.array([0.0,0.0,1500.0]) self.focus = np.array([0.0,0.0,0.0]) self.up = np.array([1.0,0.0,0.0]) self.mousex = 0 self.mousey = 0 self.mouse_drag = gl.GL_FALSE # Wire up GL glut.glutInit(sys.argv) glut.glutInitDisplayMode(glut.GLUT_RGB | glut.GLUT_DOUBLE | glut.GLUT_DEPTH) glut.glutInitWindowSize(500,500) glut.glutInitWindowPosition(10,10) glut.glutCreateWindow("Laspy+OpenGL Pointcloud") glut.glutDisplayFunc(self.display) glut.glutReshapeFunc(self.reshape) glut.glutMouseFunc(self.mouse) glut.glutMotionFunc(self.mouse_motion) glut.glutKeyboardFunc(self.keyboard) gl.glClearColor(0.0,0.0,0.0,1.0) glut.glutTimerFunc(10,self.timerEvent,1) glut.glutMainLoop() return 0
def Visualization(title, drawScene=DrawGLScene, width=320, height=200, handleKey=None): global window, _DrawCurrentSceneFunc, _KeyHandlerFunc GLUT.glutInit(sys.argv) _DrawCurrentSceneFunc = drawScene if handleKey: _KeyHandlerFunc = handleKey # Select type of Display mode: # Double buffer # RGBA color # Alpha components supported # Depth buffer GLUT.glutInitDisplayMode(GLUT.GLUT_RGBA | GLUT.GLUT_DOUBLE \ | GLUT.GLUT_DEPTH) # get a 640 x 480 window GLUT.glutInitWindowSize(640, 480) # the window starts at the upper left corner of the screen GLUT.glutInitWindowPosition(0, 0) # Okay, like the C version we retain the window id to use when closing, but # for those of you new to Python (like myself), remember this assignment # would make the variable local and not global if it weren't for the global # declaration at the start of main. window = GLUT.glutCreateWindow(title) # Register the drawing function with glut, BUT in Python land, at least # using PyOpenGL, we need to set the function pointer and invoke a function # to actually register the callback, otherwise it would be very much like # the C version of the code. GLUT.glutDisplayFunc(DrawGLScene) # Uncomment this line to get full screen. # GLUT.glutFullScreen() # When we are doing nothing, redraw the scene. GLUT.glutIdleFunc(DrawGLScene) # Register the function called when our window is resized. GLUT.glutReshapeFunc(ReSizeGLScene) # Register the function called when the keyboard is pressed. GLUT.glutKeyboardFunc(keyPressed) # Register the function called when the mouse is pressed. GLUT.glutMouseFunc(mousePressed) # Register the function called when the mouse is pressed. GLUT.glutMotionFunc(mouseMoved) # Initialize our window. InitGL(640, 480) # Start Event Processing Engine GLUT.glutMainLoop()
def __init__( self, width=256, height=256, title=None, visible=True, aspect=None, decoration=True, fullscreen=False, config=None, context=None, color=(0,0,0,1), vsync=False): if vsync: log.warn('vsync not implemented for osxglut backend') if len(__windows__) > 0: log.critical( """OSXGLUT backend is unstable with more than one window.\n""" """Exiting...""") sys.exit(0) window.Window.__init__(self, width=width, height=height, title=title, visible=visible, aspect=aspect, decoration=decoration, fullscreen=fullscreen, config=config, context=context, color=color) if config is None: config = configuration.Configuration() set_configuration(config) self._native_window = glut.glutCreateWindow( self._title ) if bool(glut.glutSetOption): glut.glutSetOption(glut.GLUT_ACTION_ON_WINDOW_CLOSE, glut.GLUT_ACTION_CONTINUE_EXECUTION) glut.glutSetOption(glut.GLUT_ACTION_GLUTMAINLOOP_RETURNS, glut.GLUT_ACTION_CONTINUE_EXECUTION) glut.glutWMCloseFunc( self._close ) glut.glutDisplayFunc( self._display ) glut.glutReshapeFunc( self._reshape ) glut.glutKeyboardFunc( self._keyboard ) glut.glutKeyboardUpFunc( self._keyboard_up ) glut.glutMouseFunc( self._mouse ) glut.glutMotionFunc( self._motion ) glut.glutPassiveMotionFunc( self._passive_motion ) glut.glutVisibilityFunc( self._visibility ) glut.glutEntryFunc( self._entry ) glut.glutSpecialFunc( self._special ) glut.glutSpecialUpFunc( self._special_up ) glut.glutReshapeWindow( self._width, self._height ) if visible: glut.glutShowWindow() else: glut.glutHideWindow() # This ensures glutCheckLoop never blocks def on_idle(): pass glut.glutIdleFunc(on_idle) __windows__.append(self)
def initAndRunDevice(templateGlutSystem): glut.glutInit() glut.glutInitDisplayMode(glut.GLUT_DOUBLE | glut.GLUT_RGBA) glut.glutCreateWindow(b'raVEngine_py') glut.glutReshapeWindow(512, 512) glut.glutReshapeFunc(reshape) glut.glutDisplayFunc(templateGlutSystem.display) glut.glutKeyboardFunc(keyboard) glut.glutMotionFunc(mouse) glut.glutIdleFunc(templateGlutSystem.combineUpdateAndDisplay) glut.glutMainLoop()
def __init__(self, *args, **kwargs): BaseCanvasBackend.__init__(self, *args) title, size, position, show, vsync, resize, dec, fs, parent, context, \ = self._process_backend_kwargs(kwargs) self._initialized = False # Deal with context if not context.istaken: context.take('glut', self) _set_config(context.config) else: raise RuntimeError('Glut cannot share contexts.') glut.glutInitWindowSize(size[0], size[1]) self._id = glut.glutCreateWindow(title.encode('ASCII')) if not self._id: raise RuntimeError('could not create window') glut.glutSetWindow(self._id) _VP_GLUT_ALL_WINDOWS.append(self) if fs is not False: self._fullscreen = True self._old_size = size if fs is not True: logger.warning('Cannot specify monitor for glut fullscreen, ' 'using default') glut.glutFullScreen() else: self._fullscreen = False # Cache of modifiers so we can send modifiers along with mouse motion self._modifiers_cache = () self._closed = False # Keep track whether the widget is closed # Register callbacks glut.glutDisplayFunc(self.on_draw) glut.glutReshapeFunc(self.on_resize) # glut.glutVisibilityFunc(self.on_show) glut.glutKeyboardFunc(self.on_key_press) glut.glutSpecialFunc(self.on_key_press) glut.glutKeyboardUpFunc(self.on_key_release) glut.glutMouseFunc(self.on_mouse_action) glut.glutMotionFunc(self.on_mouse_motion) glut.glutPassiveMotionFunc(self.on_mouse_motion) _set_close_fun(self._id, self.on_close) if position is not None: self._vispy_set_position(*position) if not show: glut.glutHideWindow() # Init self._initialized = True self._vispy_set_current() self._vispy_canvas.events.initialize()
def attachGLUT(self): glut.glutMouseFunc(self.mouseInputHandler) glut.glutMouseWheelFunc(self.mouseWheelHandler) glut.glutMotionFunc(self.mouseMoveHandler) glut.glutPassiveMotionFunc(self.mouseMoveHandler) glut.glutKeyboardFunc(self.keyboardHandler) glut.glutKeyboardUpFunc(lambda *x:self.keyboardHandler(*x,isEnd=True)) glut.glutSpecialFunc(self.specialKeyHandler) glut.glutSpecialUpFunc(lambda *x:self.specialKeyHandler(*x,isEnd=True))
def __init__(self, width=None, height=None, caption=None, visible=True, fullscreen=False): event.EventDispatcher.__init__(self) self._event_queue = [] if width and width > 0: self._width = width else: self._width = Window._default_width if height and height > 0: self._height = height else: self._height = Window._default_height if caption is None: caption = sys.argv[0] self._caption = caption self._saved_width = self._width self._saved_height = self._height if _window is None: glut.glutInit(sys.argv) glut.glutInitDisplayMode(glut.GLUT_DOUBLE | glut.GLUT_RGBA | glut.GLUT_DEPTH) self._window_id = glut.glutCreateWindow(self._caption) glut.glutDisplayFunc(self._display) glut.glutReshapeFunc(self._reshape) glut.glutKeyboardFunc(self._keyboard) glut.glutKeyboardUpFunc(self._keyboard_up) glut.glutMouseFunc(self._mouse) glut.glutMotionFunc(self._motion) glut.glutPassiveMotionFunc(self._passive_motion) glut.glutVisibilityFunc(self._visibility) glut.glutEntryFunc(self._entry) glut.glutSpecialFunc(self._special) glut.glutSpecialUpFunc(self._special_up) gl.glClearColor(0,0,0,0) self._visible = visible self._time = glut.glutGet(glut.GLUT_ELAPSED_TIME) if not visible: glut.glutHideWindow() else: glut.glutShowWindow() self.set_size(self._width, self._height) screen_width = glut.glutGet(glut.GLUT_SCREEN_WIDTH) screen_height= glut.glutGet(glut.GLUT_SCREEN_HEIGHT) glut.glutPositionWindow((screen_width-self._width)//2, (screen_height-self._height)//2) self.fullscreen = fullscreen
def init_window(self): glut.glutInit(sys.argv) glut.glutInitDisplayMode(glut.GLUT_DOUBLE | glut.GLUT_RGBA | glut.GLUT_ALPHA | glut.GLUT_DEPTH) glut.glutInitWindowPosition( (glut.glutGet(glut.GLUT_SCREEN_WIDTH) - self.window_width) // 2, (glut.glutGet(glut.GLUT_SCREEN_HEIGHT) - self.window_height) // 2, ) glut.glutSetOption(glut.GLUT_ACTION_ON_WINDOW_CLOSE, glut.GLUT_ACTION_CONTINUE_EXECUTION) glut.glutInitWindowSize(self.window_width, self.window_height) self.window_handle = glut.glutCreateWindow(WINDOW_TITLE_PREFIX) glut.glutDisplayFunc(self.render_func) glut.glutReshapeFunc(self.resize_func) glut.glutMouseFunc(self.mouse) glut.glutMotionFunc(self.mouse_motion) glut.glutKeyboardFunc(self.keyboard) glut.glutSpecialFunc(self.keyboard_s)
def __init__(self, name='glut window', *args, **kwargs): BaseCanvasBackend.__init__(self) self._id = glut.glutCreateWindow(name) global ALL_WINDOWS ALL_WINDOWS.append(self) # Cache of modifiers so we can send modifiers along with mouse motion self._modifiers_cache = () # Note: this seems to cause the canvas to ignore calls to show() # about half of the time. # glut.glutHideWindow() # Start hidden, like the other backends # Register callbacks glut.glutDisplayFunc(self.on_draw) glut.glutReshapeFunc(self.on_resize) # glut.glutVisibilityFunc(self.on_show) glut.glutKeyboardFunc(self.on_key_press) glut.glutSpecialFunc(self.on_key_press) glut.glutKeyboardUpFunc(self.on_key_release) glut.glutMouseFunc(self.on_mouse_action) glut.glutMotionFunc(self.on_mouse_motion) glut.glutPassiveMotionFunc(self.on_mouse_motion) # Set close function. See issue #10. For some reason, the function # can still not exist even if we checked its boolean status. closeFuncSet = False if bool(glut.glutWMCloseFunc): # OSX specific test try: glut.glutWMCloseFunc(self.on_close) closeFuncSet = True except OpenGL.error.NullFunctionError: pass if not closeFuncSet: try: glut.glutCloseFunc(self.on_close) closeFuncSet = True except OpenGL.error.NullFunctionError: pass # glut.glutFunc(self.on_) self._initialized = False # LC: I think initializing here makes it more consistent with other # backends glut.glutTimerFunc(0, self._emit_initialize, None)
def glinit(self): self._sock_thread = threading.Thread(target=self._comm_thread,args=(self,)) self._sock_thread.start() GLUT.glutInit() GLUT.glutSetOption(GLUT.GLUT_ACTION_ON_WINDOW_CLOSE, GLUT.GLUT_ACTION_GLUTMAINLOOP_RETURNS) # Some window attributes GLUT.glutInitDisplayMode(GLUT.GLUT_RGBA | GLUT.GLUT_DOUBLE) GLUT.glutInitWindowSize(self._width, self._height) GLUT.glutInitWindowPosition(0, 0) self._win = GLUT.glutCreateWindow(self.title) # OpenGL callbacks GLUT.glutDisplayFunc(self._draw(self._render_func)) GLUT.glutKeyboardFunc(self._on_key) GLUT.glutMouseFunc(self._on_click) GLUT.glutMotionFunc(self._on_mouse_motion) GLUT.glutCloseFunc(self._on_exit) GLUT.glutTimerFunc(self.refresh, self._timer, self.refresh) #set up 2d or 3d viewport in nice orthographic projection GL.glViewport(0, 0, self._width, self._height) GL.glMatrixMode(GL.GL_PROJECTION) GL.glLoadIdentity() if self._dim==3: GL.glOrtho(-1.,1.,-1,1.,-1000.,1000.) GL.glMatrixMode(GL.GL_MODELVIEW) else: GL.glMatrixMode(GL.GL_PROJECTION) GL.glLoadIdentity() GLU.gluOrtho2D(-1.,1.,-1.,1.) #smooth the crap out of everything GL.glEnable(GL.GL_POINT_SMOOTH) GL.glEnable(GL.GL_LINE_SMOOTH) GL.glEnable(GL.GL_POLYGON_SMOOTH) GL.glEnable(GL.GL_BLEND) GL.glBlendFunc(GL.GL_ONE,GL.GL_ONE_MINUS_SRC_ALPHA) GL.glHint(GL.GL_LINE_SMOOTH_HINT,GL.GL_NICEST) GL.glHint(GL.GL_POINT_SMOOTH_HINT,GL.GL_NICEST) GL.glHint(GL.GL_POLYGON_SMOOTH_HINT,GL.GL_NICEST) #Clear Everything and call the main loop GL.glClearColor(*self.background_color) self._window_open =True GLUT.glutMainLoop()
def __init__( self, update_callback = _EmptyOneArgCallback, display_callback = _EmptyZeroArgCallback, init_callback = _EmptyZeroArgCallback, key_callback = _EmptyThreeArgCallback, window_name = 'viewer', window_size = (640, 480), frame_rate = 60, clear_color = (0.0, 0.0, 0.0, 1.0), field_of_view = 45.0, ): self.update_callback = update_callback self.display_callback = display_callback self.key_callback = key_callback self.ms_per_frame = int(1000.0 / frame_rate) self.field_of_view = field_of_view GLUT.glutInit() GLUT.glutInitWindowSize(*window_size) GLUT.glutInitDisplayMode(GLUT.GLUT_DOUBLE | GLUT.GLUT_RGB | GLUT.GLUT_DEPTH) GLUT.glutCreateWindow(window_name) GLUT.glutDisplayFunc(self.Display) GLUT.glutKeyboardFunc(self.Key) GLUT.glutReshapeFunc(self.Reshape) GLUT.glutMouseFunc(self.Mouse) GLUT.glutMotionFunc(self.Motion) GLUT.glutPassiveMotionFunc(self.PassiveMotion) GL.glEnable(GL.GL_DEPTH_TEST) GL.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_FILL) GL.glClearColor(*clear_color) self.Reshape(*window_size) self.camera_theta = 0.0 self.camera_phi = 0.0 self.camera_r = 10.0 self.camera_center = numpy.array((0.0, 0.0, 0.0)) self.UpdateCameraRotationMatrix() self.mouse_drag_mode = None init_callback()
def run(self): glut.glutInit() glut.glutInitDisplayMode(glut.GLUT_RGBA | glut.GLUT_DOUBLE | glut.GLUT_ALPHA | glut.GLUT_DEPTH) glut.glutInitWindowSize(self.window_width, self.window_height) self.window = glut.glutCreateWindow("Point cloud test") glut.glutDisplayFunc(self.display_base) glut.glutIdleFunc(self.display_base) glut.glutReshapeFunc(self.resize_event) glut.glutKeyboardFunc(self.keyboard_press_event) glut.glutKeyboardUpFunc(self.keyboard_up_event) glut.glutMouseFunc(self.mouse_button_event) glut.glutMotionFunc(self.mouse_moved_event) self.init_gl(self.window_width, self.window_height) glut.glutMainLoop()
def show(self): rot = 0 GLUT.glutInit(sys.argv) GLUT.glutInitDisplayMode(GLUT.GLUT_RGBA | GLUT.GLUT_DOUBLE | GLUT.GLUT_ALPHA | GLUT.GLUT_DEPTH) GLUT.glutInitWindowSize(400, 300) GLUT.glutInitWindowPosition(0, 0) GLUT.glutCreateWindow('Asteroid Orbits') self.prepare_displists() GLUT.glutDisplayFunc(self.DrawGLScene) # GLUT.glutDisplayFunc(self.display_orbits) GLUT.glutMouseFunc(self.mouseHandle) GLUT.glutMotionFunc(self.motionFunc) # GLUT.glutIdleFunc(DrawGLScene) GLUT.glutReshapeFunc(self.ReSizeGLScene) GLUT.glutKeyboardFunc(self.KeyPressed) self.InitGL(400, 300) GLUT.glutMainLoop()
def init_glut(self, args): """Initialize the GLUT state.""" # Initialize GLUT. GLUT.glutInit(args) GLUT.glutInitContextVersion( self.context_version[0], self.context_version[1]) GLUT.glutInitContextFlags(GLUT.GLUT_FORWARD_COMPATIBLE) GLUT.glutInitContextProfile(GLUT.GLUT_CORE_PROFILE) GLUT.glutSetOption( GLUT.GLUT_ACTION_ON_WINDOW_CLOSE, GLUT.GLUT_ACTION_GLUTMAINLOOP_RETURNS) # Initialize and create the main window. GLUT.glutInitDisplayMode( GLUT.GLUT_DOUBLE | GLUT.GLUT_RGBA | GLUT.GLUT_DEPTH) GLUT.glutInitWindowSize( self.window_size[0], self.window_size[1]) GLUT.glutInitWindowPosition( self.window_position[0], self.window_position[1]) GLUT.glutCreateWindow(self.window_title) GLUT.glutDisplayFunc(self.render) GLUT.glutIdleFunc(self.idle) GLUT.glutReshapeFunc(self.resize) GLUT.glutKeyboardFunc(self.keyboard) GLUT.glutTimerFunc(0, self.timer, 0) GLUT.glutMouseFunc(self.mouse) GLUT.glutMotionFunc(self.motion) GLUT.glutCloseFunc(self.cleanup) aspects = [('Vendor', GL.GL_VENDOR), ('Renderer', GL.GL_RENDERER), ('Version', GL.GL_VERSION),] if self.context_version[0] > 1: aspects.append(('GLSL', GL.GL_SHADING_LANGUAGE_VERSION)) for i in aspects: print('{}: {}'.format(i[0], GL.glGetString(i[1]).decode()), file=sys.stderr, flush=True)
def main(self, neuronObject, displaysize=(800, 600), radius=5, poly=True, fast=False, multisample=True, graph=True): self.poly = poly self.displaysize = displaysize self.graph = graph title = 'btmorph OpenGL Viewer' GLUT.glutInit(sys.argv) if multisample: GLUT.glutInitDisplayMode(GLUT.GLUT_RGBA | GLUT.GLUT_DOUBLE) else: GLUT.glutInitDisplayMode(GLUT.GLUT_RGBA | GLUT.GLUT_DOUBLE | GLUT.GLUT_MULTISAMPLE) GLUT.glutInitWindowSize(self.displaysize[0], self.displaysize[1]) GLUT.glutInitWindowPosition(50, 50) GLUT.glutCreateWindow(title) GLUT.glutDisplayFunc(self.display) GLUT.glutReshapeFunc(self.reshape) GLUT.glutMouseFunc(self.mouse) GLUT.glutMotionFunc(self.mouseMove) GLUT.glutMouseWheelFunc(self.mouseWheel) GLUT.glutKeyboardFunc(self.keyDown) GLUT.glutKeyboardUpFunc(self.keyUp) mb = modelbuilder() self.root, self.vertices_gl, self.colors_gl, self.Neuron = \ mb.build(neuronObject, self.poly, 100, fast) if graph: self.gb = graphbuilder() self.Graph, mid = \ self.gb.build(neuronObject, scalefactor=100) self.initGL(multisample) self.camera.rad = radius self.camera.focus = mid while self.running: GLUT.glutMainLoopEvent() GLUT.glutDestroyWindow(GLUT.glutGetWindow())
def init(self, w=None, h=None): if w: self.width = w if h: self.height = h try: glut.glutInit() except Exception as e: print(e) sys.exit() if pl.system() == 'Darwin': #Darwin: OSX glut.glutInitDisplayString('double rgba samples=8 core depth') else: #Other: Linux try: glut.glutInitDisplayMode( glut.GLUT_DOUBLE | \ glut.GLUT_RGBA | \ glut.GLUT_MULTISAMPLE | \ glut.GLUT_DEPTH) except Exception as e: print('Issue detected') print(e) sys.exit() glut.glutInitWindowSize (self.width, self.height) glut.glutCreateWindow (self.label) self.handler.init() glut.glutDisplayFunc(self.display) glut.glutKeyboardFunc(self.on_key_press) glut.glutMouseFunc(self.on_mouse_click) glut.glutMotionFunc(self.on_mouse_motion) glut.glutPassiveMotionFunc(self.on_mouse_motion) glut.glutReshapeFunc(self.on_resize) self.last_glut_idle_time = time.time() glut.glutIdleFunc(self.on_glut_idle) if self.streamed: # sakura core defines the main program loop, # so we have to run GLUT's own loop in another # greenlet. self.spawn_greenlet_loop()
def __init__(self, cam_model_files, tracked_cam_parameters, cam_track, point_cloud): point_cloud_ids, point_cloud_points, point_cloud_colors = point_cloud if point_cloud_colors is None: point_cloud_colors = np.ones(point_cloud_points.shape, dtype=np.float32) point_cloud_scale = _detect_point_cloud_scale(point_cloud_points) point_cloud_target_scale = 3 point_cloud_points = _rescale_point_cloud( point_cloud_points, point_cloud_target_scale / point_cloud_scale) cam_track = _rescale_track( cam_track, point_cloud_target_scale / point_cloud_scale) self._tracked_cam_track_len = len(cam_track) self._tracked_cam_track_pos_float = 0.0 self._camera = recordclass('CameraPoseAndParameters', 'yaw pitch pos fov_y')( 0.0, 0.0, np.array([0, 0, 10.0]), self._camera_fov_y_range.default) GLUT.glutInit() GLUT.glutInitWindowSize(600, 400) GLUT.glutInitWindowPosition(0, 0) self._data = recordclass('AnimationData', 'prev_time key_states last_xy')( GLUT.glutGet(GLUT.GLUT_ELAPSED_TIME), np.array([False] * 256), None) GLUT.glutCreateWindow(b'Camera track renderer') GLUT.glutDisplayFunc(self.display) GLUT.glutKeyboardFunc(self.key_pressed) GLUT.glutKeyboardUpFunc(self.key_up) GLUT.glutIdleFunc(self.animate) GLUT.glutMouseFunc(self.mouse_event) GLUT.glutMotionFunc(self.mouse_move) self._renderer_impl = CameraTrackRenderer( cam_model_files, tracked_cam_parameters, cam_track, PointCloud(point_cloud_ids, point_cloud_points, point_cloud_colors))
def main(): GLUT.glutInit(argv) GLUT.glutInitDisplayMode(GLUT.GLUT_DOUBLE | GLUT.GLUT_RGBA | GLUT.GLUT_DEPTH | GLUT.GLUT_MULTISAMPLE) screen_width = GLUT.glutGet(GLUT.GLUT_SCREEN_WIDTH) screen_height = GLUT.glutGet(GLUT.GLUT_SCREEN_HEIGHT) window_width = round(2 * screen_width / 3) window_height = round(2 * screen_height / 3) GLUT.glutInitWindowSize(window_width, window_height) GLUT.glutInitWindowPosition(round((screen_width - window_width) / 2), round((screen_height - window_height) / 2)) GLUT.glutCreateWindow("Textura Esfera - Globo") GLUT.glutDisplayFunc(draw) GLUT.glutKeyboardFunc(key_pressed) GLUT.glutMouseFunc(mouse_click) GLUT.glutMotionFunc(mouse_move) LoadTextures() GL.glEnable(GL.GL_MULTISAMPLE) GL.glEnable(GL.GL_DEPTH_TEST) GL.glEnable(GL.GL_TEXTURE_2D) GL.glClearColor(0.0, 0.0, 0.0, 1) GL.glClearDepth(1.0) GL.glDepthFunc(GL.GL_LESS) GL.glShadeModel(GL.GL_SMOOTH) GL.glMatrixMode(GL.GL_PROJECTION) # POSICAO DA CAMERA GLU.gluPerspective(-45, window_width / window_height, 0.1, 100.0) GL.glTranslatef(0.0, 0.0, -10) GL.glMatrixMode(GL.GL_MODELVIEW) GLUT.glutTimerFunc(10, timer, 1) GLUT.glutMainLoop()
def activate(self, width, height): glut.glutInit(['mesh_viewer']) glut.glutInitDisplayMode(glut.GLUT_RGBA | glut.GLUT_DOUBLE | glut.GLUT_ALPHA | glut.GLUT_DEPTH) glut.glutInitWindowSize(width, height) glut.glutInitWindowPosition(0, 0) self.root_window_id = glut.glutCreateWindow(self.titlebar) glut.glutDisplayFunc(self.on_draw) #glut.glutIdleFunc(self.checkQueue) glut.glutTimerFunc(100, self.checkQueue, 0) glut.glutReshapeFunc(self.on_resize_window) glut.glutKeyboardFunc(self.on_keypress) glut.glutMouseFunc(self.on_click) glut.glutMotionFunc(self.on_drag) # for r, lst in enumerate(self.mesh_viewers): # for c, mv in enumerate(lst): # mv.glut_window_id = glut.glutCreateSubWindow(self.root_window_id, c*width/len(lst), r*height/len(self.mesh_viewers), width/len(lst), height/len(self.mesh_viewers)) glut.glutDisplayFunc(self.on_draw) self.init_opengl() glut.glutMainLoop() # won't return until process is killed
def __init__( self, mesh, width=1024, height=768 ) : # Initialise OpenGL / GLUT glut.glutInit() glut.glutInitDisplayMode( glut.GLUT_DOUBLE | glut.GLUT_RGBA | glut.GLUT_DEPTH | glut.GLUT_MULTISAMPLE ) glut.glutInitWindowSize( width, height ) glut.glutInitWindowPosition( 100, 100 ) glut.glutCreateWindow( mesh.name ) # Mesh viewer self.meshviewer = mtk.MeshViewer() self.meshviewer.InitialiseOpenGL( width, height ) self.meshviewer.LoadMesh( mesh ) self.antialiasing = True # GLUT function binding glut.glutCloseFunc( self.meshviewer.Close ) glut.glutDisplayFunc( self.Display ) glut.glutIdleFunc( self.Idle ) glut.glutKeyboardFunc( self.Keyboard ) glut.glutMouseFunc( self.Mouse ) glut.glutMotionFunc( self.meshviewer.trackball.MouseMove ) glut.glutReshapeFunc( self.meshviewer.Resize )
def main(): glut.glutInit() parse_input() glut.glutInitDisplayMode(glut.GLUT_DOUBLE | glut.GLUT_RGBA | glut.GLUT_DEPTH) glut.glutInitWindowSize(win_width,win_height) glut.glutInitContextVersion(3, 3); glut.glutInitContextProfile(glut.GLUT_CORE_PROFILE); glut.glutCreateWindow('Mesh slices') init() glut.glutReshapeFunc(reshape) glut.glutDisplayFunc(display) glut.glutKeyboardFunc(keyboard) glut.glutMouseFunc(mouse) glut.glutMotionFunc(motion) glut.glutMainLoop()
def main(): GLUT.glutInit(argv) GLUT.glutInitDisplayMode( GLUT.GLUT_DOUBLE | GLUT.GLUT_RGBA | GLUT.GLUT_DEPTH | GLUT.GLUT_MULTISAMPLE ) screen_width = GLUT.glutGet(GLUT.GLUT_SCREEN_WIDTH) screen_height = GLUT.glutGet(GLUT.GLUT_SCREEN_HEIGHT) window_width = round(2 * screen_width / 3) window_height = round(2 * screen_height / 3) GLUT.glutInitWindowSize(window_width, window_height) GLUT.glutInitWindowPosition( round((screen_width - window_width) / 2), round((screen_height - window_height) / 2) ) GLUT.glutCreateWindow(window_name) GLUT.glutDisplayFunc(draw) GLUT.glutSpecialFunc(special_key_pressed) GLUT.glutKeyboardFunc(key_pressed) GLUT.glutMouseFunc(mouse_click) GLUT.glutMotionFunc(mouse_move) GL.glEnable(GL.GL_MULTISAMPLE) GL.glEnable(GL.GL_DEPTH_TEST) GL.glClearColor(*background_color) GLU.gluPerspective(-45, window_width / window_height, 0.1, 100.0) GL.glTranslatef(0.0, 0.0, -10) GLUT.glutTimerFunc(10, timer, 1) GLUT.glutMainLoop()
def run(self, _width=None, _height=None, _show_window=True): # Init glut self._show_window = _show_window GLUT.glutInit(()) GLUT.glutInitDisplayMode(GLUT.GLUT_RGBA | GLUT.GLUT_DOUBLE | GLUT.GLUT_ALPHA | GLUT.GLUT_DEPTH) if _width is not None and _height is not None: GLUT.glutInitWindowSize(_width, _height) #self.resizeGL(_width, _height) # this line crashes my program ?? else: GLUT.glutInitWindowSize(*self.window_size) GLUT.glutInitWindowPosition(0, 0) self.window = GLUT.glutCreateWindow(self.title) if not _show_window: GLUT.glutHideWindow() GLUT.glutDisplayFunc(self.drawGL) GLUT.glutReshapeFunc(self.resizeGL) GLUT.glutKeyboardFunc(self.mykeyboard) GLUT.glutMouseFunc(self.mouseFunc) GLUT.glutMotionFunc(self.motionFunc) self.initGL(*self.window_size)
def main(argv): # Initialize glut for a nice main window glut.glutInit(argv) glut.glutInitDisplayMode(glut.GLUT_DEPTH | glut.GLUT_RGB | glut.GLUT_DOUBLE) glut.glutInitWindowSize(width, height) glut.glutInitWindowPosition(winX, winY) # Create the main window title glut.glutCreateWindow("Rubik's Cube!") # Initialize OpenGL initGL() size = globals()['size'] # Set up the size of the cube if len(argv) == 1: print "No size given, assuming 3" elif len(argv) == 2: size = int(argv[1]) globals()['size'] = size print "Creating a cube of size %d*%d*%d" % (size, size, size) else: print "%s [size]" % argv[0] # Create the cube globals()['cube'] = Cube(size) # Register callback functions glut.glutDisplayFunc(drawGLScene) glut.glutReshapeFunc(resizeGLScene) glut.glutKeyboardFunc(keyboard) glut.glutMouseFunc(mouseClick) glut.glutMotionFunc(mouseMove) print help # Run the main event loop glut.glutMainLoop()
def __init__(self, **kwargs): BaseCanvasBackend.__init__(self, capability, SharedContext) title, size, position, show, vsync, resize, dec, fs, context = \ self._process_backend_kwargs(kwargs) _set_config(context) glut.glutInitWindowSize(size[0], size[1]) self._id = glut.glutCreateWindow(title.encode('ASCII')) if not self._id: raise RuntimeError('could not create window') glut.glutSetWindow(self._id) _VP_GLUT_ALL_WINDOWS.append(self) if fs is not False: if isinstance(fs, int): logger.warn('Cannot specify monitor for glut fullscreen, ' 'using default') glut.glutFullScreen() # Cache of modifiers so we can send modifiers along with mouse motion self._modifiers_cache = () self._closed = False # Keep track whether the widget is closed # Register callbacks glut.glutDisplayFunc(self.on_draw) glut.glutReshapeFunc(self.on_resize) # glut.glutVisibilityFunc(self.on_show) glut.glutKeyboardFunc(self.on_key_press) glut.glutSpecialFunc(self.on_key_press) glut.glutKeyboardUpFunc(self.on_key_release) glut.glutMouseFunc(self.on_mouse_action) glut.glutMotionFunc(self.on_mouse_motion) glut.glutPassiveMotionFunc(self.on_mouse_motion) _set_close_fun(self._id, self.on_close) self._vispy_canvas_ = None if position is not None: self._vispy_set_position(*position) if not show: glut.glutHideWindow()
def run(self): # Create window: win = GLUT.glutCreateWindow(self.name) # Setup some OpenGL settings: GL.glEnable(GL.GL_CULL_FACE) # This isn't enabled by default GL.glFrontFace(GL.GL_CCW) # Standard, right hand rule GL.glCullFace(GL.GL_BACK) # Subclass setup: self.setup() # Create update mechanism: GLUT.glutTimerFunc(30, self.update, 30) # Create redraw mechanism: GLUT.glutDisplayFunc(self.draw) # Create event listeners GLUT.glutKeyboardFunc(self.keyboardEvents) GLUT.glutMouseFunc(self.mouseEvents) GLUT.glutMotionFunc(self.motionEvents) # Start main loop: GLUT.glutMainLoop()
def __init__(self): self.makeMovie = False self.mouse_down = False self.mouse_old = [0., 0.] self.rotate = [0., 0., 0.] self.translate = [0., 0., 0.] self.initrans = [0., 0., -2.] self.dt = np.float32(.001) self.size = 2 print self.size **3 size = self.size self.randarr = np.random.rand(self.size, self.size, self.size) self.randarr = np.require(self.randarr, 'f') arr = [(float(x)/(size-1)-.5,float(y)/(size-1)-.5,float(z)/(size-1)-.5,1.0) for x in xrange(size) for y in xrange(size) for z in xrange(size)] print len(arr) self.arr = np.require(arr, 'f') colarr = [(.5-float(x)/size+.2,float(y)/size-.5+.2,float(z)/size-.5+.2,1.0) for x in xrange(size) for y in xrange(size) for z in xrange(size)] self.colarr = np.require(colarr, 'f') if self.makeMovie: self.curimage = np.zeros((self.height, self.width, 3),dtype=np.uint8) self.curindex = 0 glut.glutInit() glut.glutInitDisplayMode(glut.GLUT_RGBA | glut.GLUT_DOUBLE | glut.GLUT_DEPTH) glut.glutInitWindowSize(self.width, self.height) glut.glutInitWindowPosition(0, 0) self.win = glut.glutCreateWindow("Testing...") glut.glutDisplayFunc(self.draw) glut.glutKeyboardFunc(self.on_key) glut.glutMouseFunc(self.on_click) glut.glutMotionFunc(self.on_mouse_motion) glut.glutTimerFunc(10, self.timer, 10) self.glinit() self.clinit() self.loadProgram("kernel.cl") self.loadclData()
def main() : global tetris tetris = Tetris() _ = glut.glutInit(sys.argv) glut.glutInitDisplayMode(glut.GLUT_DOUBLE | glut.GLUT_RGB | glut.GLUT_DEPTH) glut.glutInitWindowSize(600, 600) glut.glutInitWindowPosition(0, 100) _ = glut.glutCreateWindow('Tetris!!!') init() _ = glut.glutDisplayFunc(display) _ = glut.glutReshapeFunc(reshape) _ = glut.glutKeyboardFunc(keyboard) _ = glut.glutIdleFunc(idle) _ = glut.glutMotionFunc(mouse) _ = glut.glutSpecialFunc(special) glut.glutMainLoop()
global deltaMove if key == glut.GLUT_KEY_UP: deltaMove = 0.5 elif key == glut.GLUT_KEY_DOWN: deltaMove = -0.5 # ------------------------------------------------------- def releaseKey(key, xx, yy): global deltaMove deltaMove = 0 # ------------------------------------------------------- # main program init glut.glutInit() glut.glutInitWindowSize(800, 600) glut.glutInitDisplayMode(glut.GLUT_RGB | glut.GLUT_DOUBLE | glut.GLUT_DEPTH) glut.glutCreateWindow("DynSimTest") glut.glutDisplayFunc(render) glut.glutIdleFunc(simulate) glut.glutMouseFunc(mouseButton) glut.glutMotionFunc(mouseMove) glut.glutSpecialFunc(pressKey) glut.glutSpecialUpFunc(releaseKey) init() glut.glutMainLoop()
def mouse_button_handler(self, button, state, x, y): if button == GLUT.GLUT_RIGHT_BUTTON: GLUT.glutSetWindow(self.window) if state == GLUT.GLUT_UP: # sys.stderr.write("RMB up: forward={}\n up={}\n".format(self._forward, self._up)) # sys.stderr.write(" θ={:.2f}, φ={:.2f}, upθ={:.2f}, upφ={:.2f}\n" # .format(self._theta, self._phi, self._uptheta, self._upphi)) GLUT.glutMotionFunc(None) elif state == GLUT.GLUT_DOWN: # sys.stderr.write("RMB down\n") self._mousex0 = x self._mousey0 = y self._origtheta = math.acos( -self._forward[1] / math.sqrt(self._forward[0]**2 + self._forward[1]**2 + self._forward[2]**2)) self._origphi = math.atan2(-self._forward[0], -self._forward[2]) # sys.stderr.write("origθ = {:.2f}, origφ = {:.2f}\n".format(self._origtheta, self._origphi)) GLUT.glutMotionFunc(lambda x, y: self.rmb_moved(x, y)) if button == GLUT.GLUT_MIDDLE_BUTTON: GLUT.glutSetWindow(self.window) if state == GLUT.GLUT_UP: # sys.stderr.write("MMB up\n") GLUT.glutMotionFunc(None) elif state == GLUT.GLUT_DOWN: # sys.stderr.write("MMB down\n") self._mousex0 = x self._mousey0 = y self._origrange = self._range GLUT.glutMotionFunc(lambda x, y: self.mmb_moved(x, y)) if button == GLUT.GLUT_LEFT_BUTTON: GLUT.glutSetWindow(self.window) if state == GLUT.GLUT_UP: # sys.stderr.write("LMB up: self._center={}\n".format(self._center)) GLUT.glutMotionFunc(None) if state == GLUT.GLUT_DOWN: # sys.stderr.write("LMB down\n") keys = GLUT.glutGetModifiers() if keys & GLUT.GLUT_ACTIVE_SHIFT: self._mouseposx0 = x self._mouseposy0 = y self._origcenter = self._center self._upinscreen = self._up - self._forward * ( numpy.sum(self._up * self._forward) / math.sqrt( self._up[0]**2 + self._up[1]**2 + self._up[2]**2)) self._upinscreen /= math.sqrt(self._upinscreen[0]**2 + self._upinscreen[1]**2 + self._upinscreen[2]**2) self._rightinscreen = numpy.array([ self._forward[1] * self._upinscreen[2] - self._forward[2] * self._upinscreen[1], self._forward[2] * self._upinscreen[0] - self._forward[0] * self._upinscreen[2], self._forward[0] * self._upinscreen[1] - self._forward[1] * self._upinscreen[0] ]) self._rightinscreen /= math.sqrt( self._rightinscreen[0]**2 + self._rightinscreen[1]**2 + self._rightinscreen[2]**2) GLUT.glutMotionFunc(lambda x, y: self.lmb_moved(x, y)) if (state == GLUT.GLUT_UP) and (button == 3 or button == 4): # wheel up/down GLUT.glutSetWindow(self.window) if button == 3: self._range *= 0.9 else: self._range *= 1.1 self.update_cam_posrot_gl()
# Setup window screen_width = glut.glutGet(glut.GLUT_SCREEN_WIDTH) screen_height = glut.glutGet(glut.GLUT_SCREEN_HEIGHT) glut.glutInitWindowSize(screen_width // 2, screen_height // 2) glut.glutInitWindowPosition(0, 0) glut.glutInitDisplayMode(glut.GLUT_SINGLE | glut.GLUT_RGB) glut.glutCreateWindow(b'glGalaxy') # Register event callbacks glut.glutIdleFunc(idle_cb) glut.glutDisplayFunc(display_cb) glut.glutKeyboardFunc(keyboard_cb) glut.glutReshapeFunc(reshape_cb) glut.glutMouseFunc(mouse_cb) glut.glutMotionFunc(mouse_motion_cb) # must create VBOs before initializing openCL context??? # Initialize simulation controller controller = Controller(screen_width, screen_height, 0) camera = Camera(0.05, 10) # Initialize OpenCL cl_platform = cl.get_platforms()[0] cl_context = cl.Context( properties=[(cl.context_properties.PLATFORM, cl_platform)] + get_gl_sharing_context_properties()) cl_queue = cl.CommandQueue(cl_context) cl_program = cl.Program(cl_context, open('gravity.c', 'r').read()).build() kernel_step = cl_program.gravity
def __init__(self, size=None, position=None, title=None, fullscreen=False,enableAlpha=True,pointSize=2): ''' Constructor ''' self._mouse_x = 0 self._mouse_y = 0 self._button = mouse.NONE self._modifiers = None self._motionEventCounter=0 self._time = None self._timer_stack = [] self._timer_date = [] self._title = title or "PyGLer" # FIXME: get default name from a central location self._fullscreen = -1 self.dragSensitivity = 5 # Is there any glut loop already running ? if glut.glutGetWindow( ) == 0: glut.glutInit() glut.glutInitDisplayMode( glut.GLUT_DOUBLE | glut.GLUT_RGBA | glut.GLUT_DEPTH ) self._interactive = False else: self._interactive = True self._id = glut.glutCreateWindow( self._title ) glut.glutShowWindow() glut.glutDisplayFunc( self.redraw ) glut.glutReshapeFunc( self._reshape ) glut.glutKeyboardFunc( self._keyboard ) glut.glutKeyboardUpFunc( self._keyboard_up ) glut.glutMouseFunc( self._mouse ) glut.glutMotionFunc( self._motion ) glut.glutPassiveMotionFunc( self._passive_motion ) glut.glutVisibilityFunc( self._visibility ) glut.glutEntryFunc( self._entry ) glut.glutSpecialFunc( self._special ) glut.glutSpecialUpFunc( self._special_up ) GL.glEnable(GL.GL_DEPTH_TEST) GL.glEnable(GL.GL_BLEND) if enableAlpha: GL.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA); GL.glPolygonOffset(1, 1); GL.glEnable(GL.GL_POLYGON_OFFSET_FILL); GL.glPointSize(pointSize) GL.glEnable(GL.GL_PROGRAM_POINT_SIZE) if size is not None: width, height = size glut.glutReshapeWindow( width, height ) width = glut.glutGet( glut.GLUT_WINDOW_WIDTH ) height= glut.glutGet( glut.GLUT_WINDOW_HEIGHT ) self._width = width self._height = height if position is not None: x,y = position glut.glutPositionWindow( x, y ) x = glut.glutGet( glut.GLUT_WINDOW_X ) y = glut.glutGet( glut.GLUT_WINDOW_X ) self._x, self._y = x, y # These ones will be used when exiting fullscreen self._saved_width = self._width self._saved_height = self._height self._saved_x = self._x self._saved_y = self._y self._time = glut.glutGet( glut.GLUT_ELAPSED_TIME ) self._fullscreen = fullscreen if fullscreen: self.set_fullscreen(True)
(c_float, c_float), ('delta_x', 'delta_y'), ) except: glutScrollFunc = None glut.glutInit(sys.argv) glut.glutInitDisplayMode(glut.GLUT_DOUBLE | glut.GLUT_RGB | glut.GLUT_DEPTH) glut.glutCreateWindow(sys.argv[0]) glut.glutReshapeWindow(512, 512) glut.glutDisplayFunc(on_display) glut.glutReshapeFunc(on_reshape) glut.glutKeyboardFunc(on_keyboard) glut.glutIdleFunc(on_idle) glut.glutMotionFunc(on_motion) glut.glutPassiveMotionFunc(on_passive_motion) if glutScrollFunc: glutScrollFunc(on_scroll) elif glut.glutMouseWheelFunc: glutMouseWheelFunc(on_wheel) t0, t, frames = glut.glutGet(glut.GLUT_ELAPSED_TIME), 0, 0 zoom = 100.0 offset = np.array([256., 256.]) mouse = 0, 0 n = 400 X = np.linspace(-4 * np.pi, 4 * np.pi, n) Y = np.cos(X)
def __init__(self, dim=3, width=800, height=800, title="", refresh=15, background_color = (0.,0.,0.,0.), render_func=lambda window: None, rf_args=(), rf_kwargs = {}, save_file='./', save_file_type=None): pid = os.fork() # Hack to get interpetor back if not pid==0: return None self.mouse_down = False self.mouse_old = [0., 0.] self.rotate = [0., 0., 0.] self.translate = [0., 0., 0.] self.scale = 1.0 self.dim=dim # grab the file extension if its there. split_path_ext = os.path.splitext(save_file) self.save_file = split_path_ext[0] if save_file_type is None: self.save_file_ext = split_path_ext[1] if self.save_file_ext == '': self.save_file_ext = '.png' else: self.save_file_ext = save_file_type self.save_count = 0 self.width = width self.height = height self.lights = False GLUT.glutInit() # Some window attributes GLUT.glutInitDisplayMode(GLUT.GLUT_RGBA | GLUT.GLUT_DOUBLE) GLUT.glutInitWindowSize(self.width, self.height) GLUT.glutInitWindowPosition(0, 0) self.win = GLUT.glutCreateWindow(title) # OpenGL callbacks GLUT.glutDisplayFunc(self.draw(render_func,*rf_args,**rf_kwargs)) GLUT.glutKeyboardFunc(self.on_key) GLUT.glutMouseFunc(self.on_click) GLUT.glutMotionFunc(self.on_mouse_motion) try: GLUT.glutCloseFunc(self.on_exit) # JJB - 6/6/12 -- except GLUT.error.NullFunctionError: GLUT.glutWMCloseFunc(self.on_exit) GLUT.glutTimerFunc(refresh, self.timer, refresh) self.glinit() # Clean the slate GL.glClearColor(*background_color) # and start GLUT.glutMainLoop()
def __init__(self, xyz, color=None): """Initialize a PointCloudApp with the given XYZ data. The xyz parameter should be an N-by-3 numpy array of data to be visualized. If the data type of the array is not float32, then it will be converted automatically. """ # Check shape if ( len(xyz.shape) != 2 or xyz.shape[1] != 3 ): raise Exception('xyz must be an n-by-3 array') # Store points self.npoints = xyz.shape[0] self.xyz = xyz.astype('float32') # Compute mean Z value and range Z = self.xyz[:,2] self.zmean = numpy.average(Z) zmin = Z.min() zmax = Z.max() if zmax > zmin: zrng = zmax-zmin else: zrng = 1 # Compute colors for points self.rgb = gradient((Z - zmin)/zrng) # Set up GLUT glut.glutInit() glut.glutInitWindowSize(640, 480) glut.glutInitDisplayMode( glut.GLUT_DOUBLE | glut.GLUT_RGB | glut.GLUT_DEPTH | glut.GLUT_MULTISAMPLE ) glut.glutCreateWindow('Point cloud viewer') glut.glutDisplayFunc(self.display) glut.glutReshapeFunc(self.reshape) glut.glutKeyboardFunc(self.keyboard) glut.glutMouseFunc(self.mouse) glut.glutMotionFunc(self.motion) # Matrix to create a coordinate system with # X right # Y down # Z forward self.M = numpy.array( [ [ 1.0, 0.0, 0.0, 0.0 ], [ 0.0, -1.0, 0.0, 0.0 ], [ 0.0, 0.0, -1.0, 0.0 ], [ 0.0, 0.0, 0.0, 1.0 ] ] ) # Set up X/Y rotations and mouse state self.rot = numpy.array([0,0]) self.lastMouse = None # Handle Ctrl-C gracefully signal.signal(signal.SIGINT, self._ctrlC) glut.glutTimerFunc(100, self._watchdog, 0) # Set up OpenGL state gl.glClearColor(0.0, 0.0, 0.0, 1.0) gl.glPointSize(2.0) gl.glEnableClientState(gl.GL_VERTEX_ARRAY) gl.glEnableClientState(gl.GL_COLOR_ARRAY) gl.glVertexPointer(3, gl.GL_FLOAT, 0, self.xyz) gl.glColorPointer(3, gl.GL_FLOAT, 0, self.rgb) gl.glEnable(gl.GL_DEPTH_TEST) print 'Press space to reset view, ESC to quit.'
def register_callbacks(self): """Initialise glut callback functions.""" GLUT.glutMouseFunc(self.mouse_button) GLUT.glutMotionFunc(self.mouse_motion)
def Visualization(title, drawScene=DrawGLScene, width=320, height=200, handleKey=None): global window, _DrawCurrentSceneFunc, _KeyHandlerFunc GLUT.glutInit(sys.argv) _DrawCurrentSceneFunc = drawScene if handleKey: _KeyHandlerFunc = handleKey # Select type of Display mode: # Double buffer # RGBA color # Alpha components supported # Depth buffer GLUT.glutInitDisplayMode(GLUT.GLUT_RGBA | GLUT.GLUT_DOUBLE | GLUT.GLUT_DEPTH) # get a 640 x 480 window GLUT.glutInitWindowSize(640, 480) # the window starts at the upper left corner of the screen GLUT.glutInitWindowPosition(0, 0) # Okay, like the C version we retain the window id to use when closing, but # for those of you new to Python (like myself), remember this assignment # would make the variable local and not global if it weren't for the global # declaration at the start of main. window = GLUT.glutCreateWindow(title) # Register the drawing function with glut, BUT in Python land, at least # using PyOpenGL, we need to set the function pointer and invoke a function # to actually register the callback, otherwise it would be very much like # the C version of the code. GLUT.glutDisplayFunc(DrawGLScene) # Uncomment this line to get full screen. # GLUT.glutFullScreen() # When we are doing nothing, redraw the scene. GLUT.glutIdleFunc(DrawGLScene) # Register the function called when our window is resized. GLUT.glutReshapeFunc(ReSizeGLScene) # Register the function called when the keyboard is pressed. GLUT.glutKeyboardFunc(keyPressed) # Register the function called when the mouse is pressed. GLUT.glutMouseFunc(mousePressed) # Register the function called when the mouse is pressed. GLUT.glutMotionFunc(mouseMoved) # Initialize our window. InitGL(640, 480) # Start Event Processing Engine GLUT.glutMainLoop()
def __init__( self, size=None, position=None, title=None, fullscreen=False): ''' Create a window with given sise, position and title. :param (int,int) size: Initial window size as (width,height) in pixels. :param (int,int) position: Initial window position. Depending on the window-manager, the position request may or may not be honored. :param string title: The title of the window. ''' global _window window.Window.__init__( self, size, position, title ) self._mouse_x = 0 self._mouse_y = 0 self._button = mouse.NONE self._modifiers = None self._time = None self._timer_stack = [] self._timer_date = [] self._title = title or sys.argv[0] self._fullscreen = -1 # Is there any glut loop already running ? if glut.glutGetWindow( ) == 0: glut.glutInit( sys.argv ) glut.glutInitDisplayMode( glut.GLUT_DOUBLE | glut.GLUT_RGBA | glut.GLUT_DEPTH ) self._interactive = False else: self._interactive = True self._id = glut.glutCreateWindow( self._title ) glut.glutShowWindow( ) glut.glutDisplayFunc( self._display ) glut.glutReshapeFunc( self._reshape ) glut.glutKeyboardFunc( self._keyboard ) glut.glutKeyboardUpFunc( self._keyboard_up ) glut.glutMouseFunc( self._mouse ) glut.glutMotionFunc( self._motion ) glut.glutPassiveMotionFunc( self._passive_motion ) glut.glutVisibilityFunc( self._visibility ) glut.glutEntryFunc( self._entry ) glut.glutSpecialFunc( self._special ) glut.glutSpecialUpFunc( self._special_up ) if size is not None: width, height = size glut.glutReshapeWindow( width, height ) width = glut.glutGet( glut.GLUT_WINDOW_WIDTH ) height= glut.glutGet( glut.GLUT_WINDOW_HEIGHT ) self._width = width self._height = height if position is not None: x,y = position glut.glutPositionWindow( x, y ) #else: # screen_width = glut.glutGet( glut.GLUT_SCREEN_WIDTH ) # screen_height= glut.glutGet( glut.GLUT_SCREEN_HEIGHT ) # x = (screen_width - self._size[0]) / 2 # y = (screen_width - self._size[0]) / 2 # glut.glutPositionWindow( x, y ) x = glut.glutGet( glut.GLUT_WINDOW_X ) y = glut.glutGet( glut.GLUT_WINDOW_X ) self._x, self._y = x, y # These ones will be used when exiting fullscreen self._saved_width = self._width self._saved_height = self._height self._saved_x = self._x self._saved_y = self._y self._time = glut.glutGet( glut.GLUT_ELAPSED_TIME ) _window = self self._fullscreen = False if fullscreen: self.set_fullscreen(True)
def __init__(self, xyz, color=None): """Initialize a PointCloudApp with the given XYZ data. The xyz parameter should be an N-by-3 numpy array of data to be visualized. If the data type of the array is not float32, then it will be converted automatically. """ # Check shape if (len(xyz.shape) != 2 or xyz.shape[1] != 3): raise Exception('xyz must be an n-by-3 array') # Store points self.npoints = xyz.shape[0] self.xyz = xyz.astype('float32') normalize_data(self.xyz) # Compute mean Z value and range Z = self.xyz[:, 2] self.zmean = numpy.average(Z) zmin = Z.min() zmax = Z.max() if zmax > zmin: zrng = zmax - zmin else: zrng = 1 # Compute color for points if color is None: self.rgb = gradient((Z - zmin) / zrng) else: self.rgb = color.astype(float) / 255.0 # Set up GLUT glut.glutInit() glut.glutInitWindowSize(640, 480) glut.glutInitDisplayMode(glut.GLUT_DOUBLE | glut.GLUT_RGB | glut.GLUT_DEPTH | glut.GLUT_MULTISAMPLE) glut.glutCreateWindow('Point cloud viewer') glut.glutDisplayFunc(self.display) glut.glutReshapeFunc(self.reshape) glut.glutKeyboardFunc(self.keyboard) glut.glutMouseFunc(self.mouse) glut.glutMotionFunc(self.motion) # Matrix to create a coordinate system with # X right # Y down # Z forward self.M = numpy.array([[1.0, 0.0, 0.0, 0.0], [0.0, -1.0, 0.0, 0.0], [0.0, 0.0, -1.0, 0.0], [0.0, 0.0, 0.0, 1.0]]) # Set up X/Y rotations and mouse state self.rot = numpy.array([0, 0], dtype='float32') self.lastMouse = None # Handle Ctrl-C gracefully signal.signal(signal.SIGINT, self._ctrlC) glut.glutTimerFunc(100, self._watchdog, 0) # Set up OpenGL state gl.glClearColor(0.0, 0.0, 0.0, 1.0) gl.glPointSize(2.0) gl.glEnableClientState(gl.GL_VERTEX_ARRAY) gl.glEnableClientState(gl.GL_COLOR_ARRAY) gl.glVertexPointer(3, gl.GL_FLOAT, 0, self.xyz) gl.glColorPointer(3, gl.GL_FLOAT, 0, self.rgb) gl.glEnable(gl.GL_DEPTH_TEST) print 'Press space to reset view, ESC to quit.'
elif button == 4: on_scroll(0, -3) else: return # Glut init # -------------------------------------- glut.glutInit(sys.argv) glut.glutInitDisplayMode(glut.GLUT_DOUBLE | glut.GLUT_RGBA) glut.glutCreateWindow('Infinite hexagonal grid') glut.glutReshapeWindow(512, 512) glut.glutReshapeFunc(reshape) glut.glutKeyboardFunc(keyboard) glut.glutDisplayFunc(display) glut.glutMotionFunc(on_motion) glut.glutMouseFunc(on_mouse) glut.glutPassiveMotionFunc(on_passive_motion) # Build program & data # -------------------------------------- program = Program(vertex, fragment, 4) program['a_position'] = (-1, -1), (-1, +1), (+1, -1), (+1, +1) program['a_texcoord'] = (0, 0), (0, +1), (+1, 0), (+1, +1) program['u_grid_color'] = 0, 0, 0, 1 program['u_grid_thickness'] = 1 program['u_grid_antialias'] = .75 program['u_translate'] = 0, 0 program['u_scale'] = 1.0 program['u_size'] = 512, 512
elif key == 'p': running = not running #the mouse is used to control the camera def mouse(button, state, x, y): if button == GLUT.GLUT_LEFT_BUTTON: if (state == GLUT.GLUT_DOWN): GLUT.glutIdleFunc(forward) elif (state == GLUT.GLUT_UP): GLUT.glutIdleFunc(Calculations) elif button == GLUT.GLUT_RIGHT_BUTTON: if (state == GLUT.GLUT_DOWN): GLUT.glutIdleFunc(backward) elif (state == GLUT.GLUT_UP): GLUT.glutIdleFunc(Calculations) GLUT.glutInit(sys.argv) GLUT.glutInitDisplayMode (GLUT.GLUT_DOUBLE | GLUT.GLUT_RGB | GLUT.GLUT_DEPTH) GLUT.glutInitWindowSize (1024, 576) GLUT.glutInitWindowPosition (100, 100) GLUT.glutCreateWindow('Lorentz Attractor') init() GL.glEnable(GL.GL_TEXTURE_2D) GLUT.glutDisplayFunc(display) GLUT.glutReshapeFunc(reshape) GLUT.glutKeyboardFunc(keyboard) GLUT.glutMouseFunc(mouse) GLUT.glutPassiveMotionFunc(motion) GLUT.glutMotionFunc(motion) GLUT.glutIdleFunc(Calculations) GLUT.glutMainLoop()
def __init__(self, width=256, height=256, title=None, visible=True, aspect=None, decoration=True, fullscreen=False, config=None, context=None, color=(0, 0, 0, 1), vsync=False): if vsync: log.warn('vsync not implemented for freeglut backend') if len(__windows__) > 0: log.critical( """OSXGLUT backend is unstable with more than one window.\n""" """Exiting...""") sys.exit(0) window.Window.__init__(self, width=width, height=height, title=title, visible=visible, aspect=aspect, decoration=decoration, fullscreen=fullscreen, config=config, context=context, color=color) if config is None: config = configuration.Configuration() set_configuration(config) self._native_window = glut.glutCreateWindow(self._title) if bool(glut.glutSetOption): glut.glutSetOption(glut.GLUT_ACTION_ON_WINDOW_CLOSE, glut.GLUT_ACTION_CONTINUE_EXECUTION) glut.glutSetOption(glut.GLUT_ACTION_GLUTMAINLOOP_RETURNS, glut.GLUT_ACTION_CONTINUE_EXECUTION) glut.glutWMCloseFunc(self._close) glut.glutDisplayFunc(self._display) glut.glutReshapeFunc(self._reshape) glut.glutKeyboardFunc(self._keyboard) glut.glutKeyboardUpFunc(self._keyboard_up) glut.glutMouseFunc(self._mouse) glut.glutMotionFunc(self._motion) glut.glutPassiveMotionFunc(self._passive_motion) glut.glutVisibilityFunc(self._visibility) glut.glutEntryFunc(self._entry) glut.glutSpecialFunc(self._special) glut.glutSpecialUpFunc(self._special_up) glut.glutReshapeWindow(self._width, self._height) if visible: glut.glutShowWindow() else: glut.glutHideWindow() # This ensures glutCheckLoop never blocks def on_idle(): pass glut.glutIdleFunc(on_idle) __windows__.append(self)
def registerCallbacks(self): """Initialise glut callback functions.""" glut.glutMouseFunc(self.mouseButton) glut.glutMotionFunc(self.mouseMotion)