def show_event(self, ps): if not self.exitgl: if not self.is_initialized: self.initialize() self.set_particle_system(ps) glut.glutMainLoopEvent() glut.glutSetWindow(self.window_handle) glut.glutPostRedisplay()
def quit(self): print('close window') # glut displayfunc seems to mess up stdout in pytest # GLUT.glutDisplayFunc(None) GLUT.glutIdleFunc(None) # Hide the window, glut destroy does not instantly remove the window # it adds the window to a list to be removed later # GLUT.glutHideWindow(self.window) GLUT.glutDestroyWindow(self.window) # handle remaining events so the window is closed correctly GLUT.glutMainLoopEvent() # self.window = None # time.sleep(0.1) super(context, self).quit()
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 start(self): plt.ion() plt.show() while True: glut.glutMainLoopEvent() self.simulation.scale = self.scale_slider.val self.simulation.offset_horizontal = self.h_offset_slider.val self.simulation.offset_vertical = self.v_offset_slider.val self.simulation.color_range = self.color_range_slider.val self.simulation.width = int(self.width_slider.val) self.simulation.height = int(self.height_slider.val) self.simulation.z = self.z_slider.val self.simulation.plane = self.plane_radio.value_selected self.simulation.upload_all() self.fig.canvas.draw() plt.pause(0.0001)
def timestep(self, dt): self.__current_time += dt.v now = time.time() if now < self.__current_time: self.__am_slow = False glut.glutPostRedisplay() # print('waiting', self.__current_time - now, 'out of', dt) time.sleep(self.__current_time - now) # print('one frame took', time.time() - self.__last_time) self.__last_time = time.time() elif now > self.__last_time + 0.1: self.__am_slow = True glut.glutPostRedisplay() self.__last_time = time.time() else: pass glut.glutMainLoopEvent()
def process(dt): # Poll for and process events glut.glutMainLoopEvent() for window in __windows__: window.activate() # Dispatch the main draw event window.dispatch_event('on_draw', dt) # Dispatch the idle event window.dispatch_event('on_idle', dt) # Swap buffers window.swap() return len(__windows__)
def save(self, filename): self.update() GLUT.glutMainLoopEvent() return super(context, self).save(filename=filename)
def runSingleStep(self): GLUT.glutPostRedisplay() GLUT.glutMainLoopEvent()
def close(self): GLUT.glutDestroyWindow(self.window) GLUT.glutMainLoopEvent()
def sleep_forever(): self.__am_slow = False if not self._window_closed: print('program complete, but still running visualization...') while True: glut.glutMainLoopEvent()