def solve(num): actions = globals()['actions'] if len(actions) > 0: cube.doAction(actions[0], True, drawGLScene) globals()['actions'] = actions[1:] glut.glutTimerFunc(500, solve, 0) drawGLScene()
def start(self): ''' Starts main loop. ''' # Start timers for i in range(len(self._timer_stack)): def func(index): handler, fps = self._timer_stack[index] t = glut.glutGet(glut.GLUT_ELAPSED_TIME) dt = (t - self._timer_date[index])/1000.0 self._timer_date[index] = t handler(dt) glut.glutTimerFunc(int(1000./fps), func, index) self._timer_date[index] = glut.glutGet(glut.GLUT_ELAPSED_TIME) fps = self._timer_stack[i][1] glut.glutTimerFunc(int(1000./fps), func, i) # Start idle only if necessary for item in self._event_stack: if 'on_idle' in item.keys(): glut.glutIdleFunc(self._idle) # Dispatch init event self.dispatch_event('on_init') if not self._interactive: 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 timer(fps): global clock global data global phi, theta clock += 0.005 * 1000.0/fps # for scaling #loc = gl.glGetUniformLocation(program, "scale") #gl.glUniform1f(loc, (1+np.cos(clock))/2.0) loc = gl.glGetUniformLocation(program, "transform") # transform['transform'] = [ # (np.cos(clock),np.sin(clock),0,0), # (-np.sin(clock),np.cos(clock),0,0), # (0,0,1,0), (0,0,0,1) ] # gl.glUniformMatrix4fv(loc, 1, False, transform['transform']) # Rotate cube theta += 0.5 # degrees phi += 0.5 # degrees model = np.eye(4, dtype=np.float32) rotate(model, theta, 0, 0, 1) rotate(model, phi, 0, 1, 0) gl.glUniformMatrix4fv(loc, 1, False, model) glut.glutTimerFunc(1000/fps, timer, fps) glut.glutPostRedisplay()
def run(self): self.interval_ms = 0 if self.limit_fps <= 0 else 1000 / self.limit_fps if self.show_fps: self.previous_update_time = utils.current_time_ms() self.previous_fps_print = -1 glut.glutTimerFunc(self.interval_ms, self.update, 0) glut.glutMainLoop()
def world_timer(self,value): if self.timer2on: self.time2now+=self.timer2Dt self.plot.update_time(self.time2now) glut.glutTimerFunc( self.timer2Dt, self.world_timer, 1)
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 timer(fps): global clock clock += 0.005 * 1000.0/fps program['scale'] = (1+np.cos(clock))/2.0 program['m_transform'] = [ (np.cos(clock),np.sin(clock),0,0), (-np.sin(clock),np.cos(clock),0,0), (0,0,1,0), (0,0,0,1) ] print program['m_transform'] glut.glutTimerFunc(1000/fps, timer, fps) glut.glutPostRedisplay()
def func(index): handler, fps = self._timer_stack[index] t = glut.glutGet(glut.GLUT_ELAPSED_TIME) dt = (t - self._timer_date[index])/1000.0 self._timer_date[index] = t handler(dt) glut.glutTimerFunc(int(1000./fps), func, index) self._timer_date[index] = glut.glutGet(glut.GLUT_ELAPSED_TIME)
def update(_): with use_program(gl_program): loc = gl.glGetUniformLocation(gl_program, 'time') gl.glUniform1f(loc, current_time_ms() - start) scale_width, scale_height = min(width, height)*1.0/width, min(width, height)*1.0/height loc = gl.glGetUniformLocation(gl_program, 'scale_to_square') gl.glUniform2f(loc, scale_width, scale_height) glut.glutPostRedisplay() glut.glutTimerFunc(0, update, 0)
def updateScene(value): # rotate geometry ang_rad = math.radians(1) for object in sceneObjects.values(): if object.getDim() == 3: # 3d rotation rotateInLocalBasis(object, ang_rad, ang_rad, ang_rad, e1, e2, e3) else: rotateInLocalBasis4D(object) GLUT.glutTimerFunc(20, updateScene, 1);
def update_transforms(self, event): self.theta += .5 self.phi += .5 self.model = np.eye(4, dtype=np.float32) rotate(self.model, self.theta, 0,0,1) rotate(self.model, self.phi, 0,1,0) # Redraw and invoke new timer glut.glutTimerFunc(1000/fps, self.update_transforms, fps) glut.glutPostRedisplay()
def timer(fps): global theta, phi theta += 0.5 phi += 0.5 model = np.eye(4, dtype=np.float32) rotate(model, theta, 0, 0, 1) rotate(model, phi, 0, 1, 0) program["model"] = model glut.glutTimerFunc(1000 / fps, timer, fps) glut.glutPostRedisplay()
def timer(fps): global theta, phi theta += .5 phi += .5 model = np.eye(4, dtype=np.float32) rotate(model, theta, 0, 0, 1) rotate(model, phi, 0, 1, 0) loc = gl.glGetUniformLocation(cube, "u_model") gl.glUniformMatrix4fv(loc, 1, False, model) glut.glutTimerFunc(1000 / fps, timer, fps) glut.glutPostRedisplay()
def mainloop(self, interactive=False, namespace=globals()): '''Starts main loop ''' # Start timers for i in range(len(self._timer_stack)): def func(index): handler, fps = self._timer_stack[index] t = glut.glutGet(glut.GLUT_ELAPSED_TIME) dt = (t - self._timer_date[index])/1000.0 self._timer_date[index] = t handler(dt) glut.glutTimerFunc(int(1000./fps), func, index) self._timer_date[index] = glut.glutGet(glut.GLUT_ELAPSED_TIME) fps = self._timer_stack[i][1] glut.glutTimerFunc(int(1000./fps), func, i) # Start idle only if necessary for item in self._event_stack: if 'on_idle' in item.keys(): glut.glutIdleFunc(self._idle) self.dispatch_event('on_init') # Starts non-interactive mode if not interactive: glut.glutMainLoop() sys.exit() # Starts interactive mode # Save tty mode on linux/darwin if sys.platform in ['linux2', 'darwin']: self.term_state = termios.tcgetattr(sys.stdin) namespace = namespace.copy() for key in namespace.keys(): f = namespace[key] if key[:2] == 'gl' and isinstance(namespace[key], _ctypes.CFuncPtr): namespace[key] = proxy.Proxy(f,self) def session_start(): self.shell = IPython.ipapi.make_session(namespace) self.shell.IP.interact() #mainloop() sys.exit() self.session = threading.Thread(target=session_start) self.session.start() @atexit.register def goodbye(): self.shell.IP.ask_exit() # Restore tty state on linux/darwin if sys.platform in ['linux2', 'darwin']: termios.tcsetattr(sys.stdin, termios.TCSADRAIN, self.term_state) sys.stdout.write('\n') glut.glutTimerFunc(100, self._pop, 0) glut.glutMainLoop()
def update(self, _): current_time = utils.current_time_ms() passed_time = current_time - self.previous_update_time if self.show_fps: fps = 1000 // passed_time if current_time > self.previous_fps_print + 100: print fps, 'FPS\r', self.previous_fps_print = current_time self.previous_update_time = current_time glut.glutPostRedisplay() glut.glutTimerFunc(self.interval_ms, self.update, int(passed_time))
def handleTime(self, value): try: currentTime = GLUT.glutGet(GLUT.GLUT_ELAPSED_TIME) self.world.update(currentTime=currentTime) self.render() GLUT.glutTimerFunc(self.time_interval, self.handleTime, None) except: traceback.print_exc() sys.exit()
def update_right_checkerboard(trash_value): global CB_right global t_list_right global render_right CB_right = CB_cycle_right.next() render_right = True glut.glutPostRedisplay() t_list_right.append(time.time()) glut.glutTimerFunc(dtRight, update_right_checkerboard, None)
def animation_timer(self,value): #print value if self.timer1on: if self.recordingon: self.save(filename=self.video_dir+'{0:010d}'.format(self.frameno)+'.png') self.frameno+=1 glut.glutPostRedisplay() glut.glutTimerFunc( self.timer1Dt, self.animation_timer, 1)
def initGLWindow(width, height): # init GL window GLUT.glutInit(sys.argv) GLUT.glutInitDisplayMode(GLUT.GLUT_RGBA | GLUT.GLUT_DOUBLE | GLUT.GLUT_ALPHA | GLUT.GLUT_DEPTH) GLUT.glutInitWindowSize(width, height) GLUT.glutInitWindowPosition(0, 0) GLUT.glutCreateWindow("Hyper Dimensions v1.0 (beta)") # set callback functions GLUT.glutDisplayFunc(drawGLScene) # rendering function GLUT.glutIdleFunc(drawGLScene) # idle function GLUT.glutTimerFunc(10, updateScene, 1); GLUT.glutPassiveMotionFunc(mousePassiveMotion)
def timer(fps): global theta, phi theta += .5 phi += .5 model = np.eye(4, dtype=np.float32) rotate(model, theta, 0, 0, 1) rotate(model, phi, 0, 1, 0) normal = np.array(np.matrix(np.dot(view, model)).I.T) program['u_model'] = model program['u_normal'] = normal glut.glutTimerFunc(1000 / fps, timer, fps) glut.glutPostRedisplay()
def timer(fps): global elapsed_time elapsed_time += 1.0 / fps if elapsed_time > 1.5: new_explosion() elapsed_time = 0.0 loc = gl.glGetUniformLocation(program, "time") gl.glUniform1f(loc, elapsed_time) glut.glutTimerFunc(1000 / fps, timer, fps) glut.glutPostRedisplay()
def run(self): # Create window: self.win = GLUT.glutCreateWindow(self.name) # Setup stuff for testing this time: self.mySetup() # Create update mechanism: GLUT.glutTimerFunc(30, self.update, 30) # Create redraw mechanism: GLUT.glutDisplayFunc(self.draw) GLUT.glutMainLoop()
def timer (dummy): timer.angle += 2 * math.pi / framesPerSecond # So 1 rotation per second if timer.angle > 2 * math.pi * timer.maxGear: timer.angle = 0 zoom = gl.glGetUniformLocation (program, 'zoom') gl.glProgramUniform1f (program, zoom, 0.75 + 0.25 * math.cos (timer.angle)) angle = gl.glGetUniformLocation (program, 'angle') gl.glProgramUniform1f (program, angle, timer.angle / timer.maxGear) glut.glutTimerFunc (milliSecondsPerFrame, timer, None) glut.glutPostRedisplay ()
def timer(self, value): """The timer callback function.""" if value != 0: caption = '{}: {} frames per secound @ {} x {}'.format( self.window_title.decode(), self.frame_count * 4, GLUT.glutGet(GLUT.GLUT_WINDOW_WIDTH), GLUT.glutGet(GLUT.GLUT_WINDOW_HEIGHT)) GLUT.glutSetWindowTitle(caption) self.frame_count = 0 GLUT.glutTimerFunc(250, self.timer, 1) # a quarter of a second
def _glut_callback(id): # Get weakref wrapper for timer timer = TimerBackend._timers.get(id, None) if timer is None: return # Get timer object timer = timer() if timer is None: return # Kick it! if timer._vispy_timer._running: timer._vispy_timer._timeout() ms = int(timer._vispy_timer._interval * 1000) glut.glutTimerFunc(ms, _glut_callback, timer._id)
def __init__(self): GLUT.glutInit(sys.argv) GLUT.glutInitDisplayMode(GLUT.GLUT_RGBA | GLUT.GLUT_DOUBLE | GLUT.GLUT_DEPTH) GLUT.glutInitWindowSize(640, 480) self.win = GLUT.glutCreateWindow("PyOpenGL!!") # "glutTimerFunc" takes in three arguments GLUT.glutTimerFunc( 20, # how long to wait self.update, # when initial wait, run this function 20) # pass this value as argument to function # Called every frame: GLUT.glutDisplayFunc(self.draw) # application main loop: GLUT.glutMainLoop()
def getNextRecord(value): global activity try: activity = g_rs.next_record() except: print "end of file detected" sys.exit() if len(activity) > 0: print "time==", g_rs.time, "num_records==", len(activity) glut.glutPostRedisplay() glut.glutTimerFunc(g_msecs, getNextRecord, 1) else: print "time==", g_rs.time, "num_records==", len(activity) glut.glutTimerFunc(g_msecs, getNextRecord, 1)
def timer(fps): global theta,clock theta += .5 clock += 0.01 program["u_clock"] = clock model = np.eye(4, dtype=np.float32) rotate(model, theta, 0,0,1) rotate(model, -45, 1,0,0) normal = np.array(np.matrix(np.dot(view,model)).I.T) program['u_model'] = model program['u_normal'] = normal glut.glutTimerFunc(1000/fps, timer, fps) glut.glutPostRedisplay()
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 timer(i): GLUT.glutPostRedisplay() GLUT.glutTimerFunc(10, timer, 1)
def timer(fps): glut.glutTimerFunc(1000 // fps, timer, fps) glut.glutPostRedisplay()
def timer(fps): glut.glutTimerFunc(1000 / fps, timer, fps) data['a_fg_color'][..., 3] -= 0.01 data['a_size'] += 1.0 vdata.set_data(data) glut.glutPostRedisplay()
def timer(v): glut.glutPostRedisplay() glut.glutTimerFunc(16, timer, 0)
def timer(self, v): glut.glutPostRedisplay() glut.glutTimerFunc(16, self.timer, 0)
def renderTimer(self, timer): GLUT.glutPostRedisplay() GLUT.glutTimerFunc(20, self.renderTimer, 1)
def _watchdog(self, value): # Used only to handle Ctrl-C glut.glutTimerFunc(100, self._watchdog, 0)
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.'
def timer(fps): global clock clock += 0.005 * 1000.0 / fps program['scale'] = (1 + np.cos(clock)) / 2.0 glut.glutTimerFunc(1000 / fps, timer, fps) glut.glutPostRedisplay()
def on_timer(fps): glut.glutTimerFunc(1000/fps, on_timer, fps) glut.glutPostRedisplay() if __name__ == '__main__': fps = 60 glut.glutInit(sys.argv) glut.glutInitDisplayMode(glut.GLUT_DOUBLE | glut.GLUT_RGBA | glut.GLUT_DEPTH) glut.glutCreateWindow('glut-cube') glut.glutReshapeWindow(512,512) glut.glutDisplayFunc(display) glut.glutReshapeFunc(reshape) glut.glutKeyboardFunc(keyboard ) glut.glutTimerFunc(1000/fps, on_timer, fps) gl.glPolygonOffset( 1, 1 ) gl.glClearColor( .3, .3, .35, 1 ) gl.glBlendFunc( gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA ) gl.glEnable( gl.GL_LINE_SMOOTH ) projection = np.eye(4,dtype=np.float32) view = np.eye(4,dtype=np.float32) theta, phi = 0,0 vtype = [('position', np.float32, 3), ('normal' , np.float32, 3), ('color', np.float32, 4)]
def update_transforms(self, event): self.theta += .5 self.phi += .5 self.model = np.eye(4, dtype=np.float32) rotate(self.model, self.theta, 0, 0, 1) rotate(self.model, self.phi, 0, 1, 0) # Redraw and invoke new timer glut.glutTimerFunc(1000 / fps, self.update_transforms, fps) glut.glutPostRedisplay() if __name__ == '__main__': c = Canvas() fps = 60 use_buffers = False glut.glutInit([]) glut.glutInitDisplayMode(glut.GLUT_DOUBLE | glut.GLUT_RGBA | glut.GLUT_DEPTH) glut.glutCreateWindow('glut-cube') glut.glutReshapeWindow(400, 400) glut.glutDisplayFunc(c.on_paint) glut.glutReshapeFunc(c.on_resize) glut.glutTimerFunc(1000 // fps, c.update_transforms, fps) # Go! c.on_initialize() glut.glutMainLoop()
def on_timer(fps): glut.glutTimerFunc(1000/fps, on_timer, fps) glut.glutPostRedisplay()
def timer(dummy): setTransform() glut.glutTimerFunc(self.milliSecondsPerFrame, timer, None) glut.glutPostRedisplay()
T = np.array([[1.0, 0.0, 0.0, x], [0.0, 1.0, 0.0, y], [0.0, 0.0, 1.0, z], [0.0, 0.0, 0.0, 1.0]], dtype=M.dtype).T M[...] = np.dot(M, T) return M # GLUT init # -------------------------------------- glut.glutInit() glut.glutInitDisplayMode(glut.GLUT_DOUBLE | glut.GLUT_RGBA | glut.GLUT_DEPTH) glut.glutCreateWindow('Hello world!') glut.glutReshapeWindow(512,512) glut.glutReshapeFunc(reshape) glut.glutKeyboardFunc(keyboard) glut.glutDisplayFunc(display) glut.glutTimerFunc(1000/60, timer, 60) # Build data # -------------------------------------- Vertices = np.zeros(8, [("position", np.float32, 3)] ) Vertices["position"] = [( 1, 1, 1), (-1, 1, 1), (-1,-1, 1), ( 1,-1, 1), ( 1,-1,-1), ( 1, 1,-1), (-1, 1,-1), (-1,-1,-1)] Color = np.zeros(32, [("color", np.float32,4)] ) for i in range(8): Color['color'][i*3] = [1, 0, 1, 1] Color['color'][i*3+1] = [1, 0, 1, 1] Color['color'][i*3+2] = [1, 0, 1, 1] Indices = np.array([0,1,2, 0,2,3, 0,3,4, 0,4,5, 0,5,6, 0,6,1,
def __init__(self): self.aspectRatio = 1 self.angle = 0 self.startTime = dt.datetime.now() # Initialize GLUT def display(): gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT) gl.glDrawArrays(gl.GL_TRIANGLES, 0, self.getSubjectVertices().shape[0]) glut.glutSwapBuffers() def reshape(width, height): self.aspectRatio = float(width) / height gl.glViewport(0, 0, width, height) def keyboard(key, x, y): sys.exit() def setTransform(): self.program.setUniform( 'transformation', trf.getPerspMat(self.fieldOfViewY, self.aspectRatio, self.zNearFarVec) * self.getPositionMat()) def timer(dummy): setTransform() glut.glutTimerFunc(self.milliSecondsPerFrame, timer, None) glut.glutPostRedisplay() glut.glutInit() glut.glutInitDisplayMode(glut.GLUT_DOUBLE | glut.GLUT_RGBA | glut.GLUT_DEPTH | glut.GLUT_MULTISAMPLE) glut.glutCreateWindow('Vertex and fragment shaders') glut.glutReshapeWindow(self.windowSize, self.windowSize) glut.glutReshapeFunc(reshape) glut.glutDisplayFunc(display) glut.glutKeyboardFunc(keyboard) glut.glutTimerFunc(0, timer, None) #gl.glEnable (gl.GL_LINE_SMOOTH) #gl.glEnable (gl.GL_BLEND); #gl.glEnable (gl.GL_MULTISAMPLE) # gl.glDepthFunc (gl.GL_LESS) gl.glClearColor(0.2, 0.2, 0.2, 1) gl.glEnable(gl.GL_DEPTH_TEST) #gl.glShadeModel (gl.GL_SMOOTH) #gl.glHint (gl.GL_LINE_SMOOTH_HINT, gl.GL_DONT_CARE) #gl.glBlendFunc (gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA) # Initialize shaders self.program = prg.Program( prg.Shader( 'vertex', ''' uniform mat4 transformation; attribute vec3 position; attribute vec4 color; varying vec4 varyingColor; void main () { gl_Position = vec4 (transformation * vec4 (position, 1)); varyingColor = color; } '''), prg.Shader( 'fragment', ''' varying vec4 varyingColor; void main () { gl_FragColor = varyingColor; } '''), ) # Set subject to be displayed self.program.setAttributes(self.getSubjectVertices()) # Enter GLUT main loop glut.glutMainLoop()
def timerEvent(self, arg): # Do stuff glut.glutPostRedisplay() glut.glutTimerFunc(10,self.timerEvent,1)
def timer(fps): galaxy.update(100000) # in years ! program['a_size'] = galaxy['size'] glut.glutTimerFunc(1000 / fps, timer, fps) glut.glutPostRedisplay()
def on_timer(fps): lines.dash_phase += 0.1 glut.glutTimerFunc(1000/fps, on_timer, fps) glut.glutPostRedisplay()
def timer(self, val): if GrContext.print_fps: sys.stderr.write("{} display fps: {}\n".format( self._title, self.framecount / 2.)) self.framecount = 0 GLUT.glutTimerFunc(2000, lambda val: self.timer(val), 0)