def on_initialize(self, event): gl.glClearColor(0,0,0,1) gl.glDisable(gl.GL_DEPTH_TEST) gl.glEnable(gl.GL_BLEND) gl.glBlendFunc (gl.GL_SRC_ALPHA, gl.GL_ONE) #_MINUS_SRC_ALPHA) # Start the timer upon initialization. self.timer.start()
def draw11(event): print(' {0:7}: {1}'.format('1', bgcolors[1])) if bgcolors[1] is not None: gl.glViewport(0, 0, *list(_win_size)) gl.glClearColor(*bgcolors[1]) gl.glClear(gl.GL_COLOR_BUFFER_BIT) gl.glFinish()
def _test_functonality(backend): """ Create app and canvas so we have a context. Then run tests. """ # use the backend gl.use_gl(backend) with Canvas() as canvas: _clear_screen() # Prepare w, h = canvas.size gl.glViewport(0, 0, w, h) gl.glScissor(0, 0, w, h) # touch gl.glClearColor(0.0, 0.0, 0.0, 1.0) # Setup visualization, ensure to do it in a draw event objects = _prepare_vis() _clear_screen() _draw1() _clear_screen() _draw2() _clear_screen() _draw3() # Clean up for delete_func, handle in objects: delete_func(handle) gl.glFinish()
def on_initialize(self, event): gl.glClearColor(1, 1, 1, 1) gl.glEnable(gl.GL_DEPTH_TEST) gl.glEnable(gl.GL_BLEND) gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA) gl.glEnable(GL_VERTEX_PROGRAM_POINT_SIZE) gl.glEnable(GL_POINT_SPRITE)
def _test_functionality(backend): """Create app and canvas so we have a context. Then run tests.""" # use the backend gl.use_gl(backend) with Canvas() as canvas: _clear_screen() # Prepare w, h = canvas.size gl.glViewport(0, 0, w, h) gl.glScissor(0, 0, w, h) # touch gl.glClearColor(0.0, 0.0, 0.0, 1.0) # Setup visualization, ensure to do it in a draw event objects = _prepare_vis() _clear_screen() _draw1() _clear_screen() _draw2() _clear_screen() _draw3() # Clean up for delete_func, handle in objects: delete_func(handle) gl.glFinish()
def draw00(event): print(" {0:7}: {1}".format("0", bgcolors[0])) if bgcolors[0] is not None: gl.glViewport(0, 0, *list(_win_size)) gl.glClearColor(*bgcolors[0]) gl.glClear(gl.GL_COLOR_BUFFER_BIT) gl.glFinish()
def paint0(event): print(' {0:7}: {1}'.format(backend + '_0', bgcolors[0])) if bgcolors[0] is not None: gl.glViewport(0, 0, *list(_win_size)) gl.glClearColor(*bgcolors[0]) gl.glClear(gl.GL_COLOR_BUFFER_BIT) gl.glFinish()
def on_initialize(self, event): gl.glClearColor(0, 0, 0, 1) gl.glDisable(gl.GL_DEPTH_TEST) gl.glEnable(gl.GL_BLEND) gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE) # _MINUS_SRC_ALPHA) # Start the timer upon initialization. self.timer.start()
def draw00(event): print(' {0:7}: {1}'.format('0', bgcolors[0])) if bgcolors[0] is not None: gl.glViewport(0, 0, *list(_win_size)) gl.glClearColor(*bgcolors[0]) gl.glClear(gl.GL_COLOR_BUFFER_BIT) gl.glFinish()
def on_initialize(self, event): gl.glClearColor(1,1,1,1) gl.glEnable(gl.GL_DEPTH_TEST) # Create shader program self._prog_handle = gl.glCreateProgram() # Create vertex shader shader = gl.glCreateShader(gl.GL_VERTEX_SHADER) gl.glShaderSource(shader, VERT_CODE) gl.glCompileShader(shader) status = gl.glGetShaderiv(shader, gl.GL_COMPILE_STATUS) if not status: # We could show more useful info here, but that takes a few lines raise RuntimeError('Vertex shader did not compile.') else: gl.glAttachShader(self._prog_handle, shader) # Create fragment shader shader = gl.glCreateShader(gl.GL_FRAGMENT_SHADER) gl.glShaderSource(shader, FRAG_CODE) gl.glCompileShader(shader) status = gl.glGetShaderiv(shader, gl.GL_COMPILE_STATUS) if not status: # We could show more useful info here, but that takes a few lines raise RuntimeError('Fragment shader did not compile.') else: gl.glAttachShader(self._prog_handle, shader) # Link gl.glLinkProgram(self._prog_handle) status = gl.glGetProgramiv(self._prog_handle, gl.GL_LINK_STATUS) if not status: # We could show more useful info here, but that takes a few lines raise RuntimeError('Program did not link.') # Create texture im = dataio.crate() self._tex_handle = gl.glGenTextures(1) gl.glPixelStorei(gl.GL_UNPACK_ALIGNMENT, 1) gl.glBindTexture(gl.GL_TEXTURE_2D, self._tex_handle) gl.glTexImage2D(gl.GL_TEXTURE_2D, 0, gl.GL_RGB, im.shape[1], im.shape[0], 0, gl.GL_RGB, gl.GL_UNSIGNED_BYTE, im) gl.glTexParameter(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MIN_FILTER, gl.GL_LINEAR) gl.glTexParameter(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MAG_FILTER, gl.GL_LINEAR) if use_buffers: # Create vertex buffer self._positions_handle = gl.glGenBuffers(1) gl.glBindBuffer(gl.GL_ARRAY_BUFFER, self._positions_handle) gl.glBufferData(gl.GL_ARRAY_BUFFER, positions.nbytes, positions, gl.GL_DYNAMIC_DRAW) # self._texcoords_handle = gl.glGenBuffers(1) gl.glBindBuffer(gl.GL_ARRAY_BUFFER, self._texcoords_handle) gl.glBufferData(gl.GL_ARRAY_BUFFER, texcoords.nbytes, texcoords, gl.GL_DYNAMIC_DRAW) # Create buffer for faces self._faces_handle = gl.glGenBuffers(1) gl.glBindBuffer(gl.GL_ELEMENT_ARRAY_BUFFER, self._faces_handle) gl.glBufferData(gl.GL_ELEMENT_ARRAY_BUFFER, faces.nbytes, faces, gl.GL_DYNAMIC_DRAW)
def on_initialize(self, event): self.program = gl.glCreateProgram() vertex = gl.glCreateShader(gl.GL_VERTEX_SHADER) fragment = gl.glCreateShader(gl.GL_FRAGMENT_SHADER) gl.glShaderSource(vertex, vertex_code) gl.glShaderSource(fragment, fragment_code) gl.glCompileShader(vertex) gl.glCompileShader(fragment) gl.glAttachShader(self.program, vertex) gl.glAttachShader(self.program, fragment) gl.glLinkProgram(self.program) gl.glDetachShader(self.program, vertex) gl.glDetachShader(self.program, fragment) gl.glUseProgram(self.program) n = 10000000 self.data = np.zeros((n, 4), dtype=np.float32) self.data[:, :2] = .15 * prng.randn(n, 2) self.data[:, 3] = 1. vbuffer = gl.glCreateBuffer() gl.glBindBuffer(gl.GL_ARRAY_BUFFER, vbuffer) gl.glBufferData(gl.GL_ARRAY_BUFFER, self.data, gl.GL_DYNAMIC_DRAW) stride = self.data.strides[0] offset = 0 loc = gl.glGetAttribLocation(self.program, "a_position") gl.glEnableVertexAttribArray(loc) gl.glVertexAttribPointer(loc, 4, gl.GL_FLOAT, False, stride, offset) gl.glClearColor(0, 0, 0, 1) gl.glEnable(34370) gl.glEnable(34913) # Auto-close after 10 seconds self.timer = app.Timer(10, self.on_timer, start=True)
def on_initialize(self, event): gl.glClearColor(0, 0, 0, 1) # Enable blending gl.glEnable(gl.GL_BLEND) gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE) gl.glEnable(GL_VERTEX_PROGRAM_POINT_SIZE) gl.glEnable(GL_POINT_SPRITE)
def on_initialize(self, event): gl.glClearColor(0, 0, 0, 1) # Enable blending gl.glEnable(gl.GL_BLEND) gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE) # Create shader program self._prog_handle = gl.glCreateProgram() # Create vertex shader shader = gl.glCreateShader(gl.GL_VERTEX_SHADER) gl.glShaderSource_compat(shader, VERT_CODE) gl.glCompileShader(shader) status = gl.glGetShaderiv(shader, gl.GL_COMPILE_STATUS) if not status: # We could show more useful info here, but that takes a few lines raise RuntimeError('Vertex shader did not compile.') else: gl.glAttachShader(self._prog_handle, shader) # Create fragment shader shader = gl.glCreateShader(gl.GL_FRAGMENT_SHADER) need_enabled = gl.glShaderSource_compat(shader, FRAG_CODE) gl.glCompileShader(shader) status = gl.glGetShaderiv(shader, gl.GL_COMPILE_STATUS) if not status: # We could show more useful info here, but that takes a few lines raise RuntimeError('Fragment shader did not compile.') else: gl.glAttachShader(self._prog_handle, shader) # Enable point sprites for enum in need_enabled: gl.glEnable(enum) # Link gl.glLinkProgram(self._prog_handle) status = gl.glGetProgramiv(self._prog_handle, gl.GL_LINK_STATUS) if not status: # We could show more useful info here, but that takes a few lines raise RuntimeError('Program did not link.') # Create texture self._tex_handle = gl.glGenTextures(1) gl.glPixelStorei(gl.GL_UNPACK_ALIGNMENT, 1) gl.glBindTexture(gl.GL_TEXTURE_2D, self._tex_handle) gl.glTexImage2D(gl.GL_TEXTURE_2D, 0, gl.GL_LUMINANCE, im1.shape[1], im1.shape[0], 0, gl.GL_LUMINANCE, gl.GL_FLOAT, im1.astype(np.float32)) gl.glTexParameter(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MIN_FILTER, gl.GL_LINEAR) gl.glTexParameter(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MAG_FILTER, gl.GL_LINEAR) # Create vertex buffer self._vbo_handle = gl.glGenBuffers(1)
def __init__(self, n=50): app.Canvas.__init__(self) self.program = gloo.Program(vertex, fragment, n) gl.glClearColor(1,1,1,1) self.program['x'] = np.linspace(-1.0, +1.0, n) self.program['y'] = np.random.uniform(-0.5, +0.5, n) self._timer = app.Timer(1.0/60) self._timer.connect(self.on_timer) self._timer.start()
def __init__(self, n=50): app.Canvas.__init__(self) self.program = gloo.Program(vertex, fragment, n) gl.glClearColor(1, 1, 1, 1) self.program['x'] = np.linspace(-1.0, +1.0, n) self.program['y'] = np.random.uniform(-0.5, +0.5, n) self._timer = app.Timer(1.0 / 60) self._timer.connect(self.on_timer) self._timer.start()
def on_initialize(self, event): # Build & activate program self.program = gl.glCreateProgram() vertex = gl.glCreateShader(gl.GL_VERTEX_SHADER) fragment = gl.glCreateShader(gl.GL_FRAGMENT_SHADER) gl.glShaderSource(vertex, vertex_code) gl.glShaderSource(fragment, fragment_code) gl.glCompileShader(vertex) gl.glCompileShader(fragment) gl.glAttachShader(self.program, vertex) gl.glAttachShader(self.program, fragment) gl.glLinkProgram(self.program) gl.glDetachShader(self.program, vertex) gl.glDetachShader(self.program, fragment) gl.glUseProgram(self.program) # Build vertex buffer n = 10000 self.data = np.zeros(n, dtype=[('lifetime', np.float32), ('start', np.float32, 3), ('end', np.float32, 3)]) vbuffer = gl.glCreateBuffer() gl.glBindBuffer(gl.GL_ARRAY_BUFFER, vbuffer) gl.glBufferData(gl.GL_ARRAY_BUFFER, self.data, gl.GL_DYNAMIC_DRAW) # Bind buffer attributes stride = self.data.strides[0] offset = 0 loc = gl.glGetAttribLocation(self.program, "lifetime") gl.glEnableVertexAttribArray(loc) gl.glVertexAttribPointer(loc, 1, gl.GL_FLOAT, False, stride, offset) offset = self.data.dtype["lifetime"].itemsize loc = gl.glGetAttribLocation(self.program, "start") gl.glEnableVertexAttribArray(loc) gl.glVertexAttribPointer(loc, 3, gl.GL_FLOAT, False, stride, offset) offset = self.data.dtype["start"].itemsize loc = gl.glGetAttribLocation(self.program, "end") gl.glEnableVertexAttribArray(loc) gl.glVertexAttribPointer(loc, 3, gl.GL_FLOAT, False, stride, offset) # OpenGL initalization self.elapsed_time = 0 gl.glClearColor(0, 0, 0, 1) gl.glDisable(gl.GL_DEPTH_TEST) gl.glEnable(gl.GL_BLEND) gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE) gl.glEnable(34370) # gl.GL_VERTEX_PROGRAM_POINT_SIZE gl.glEnable(34913) # gl.GL_POINT_SPRITE gl.glViewport(0, 0, *self.physical_size) self.new_explosion() self.timer = app.Timer('auto', self.on_timer, start=True)
def on_initialize(self, event): gl.glClearColor(0,0,0,1); # Enable blending gl.glEnable(gl.GL_BLEND) gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE) # Create shader program self._prog_handle = gl.glCreateProgram() # Create vertex shader shader = gl.glCreateShader(gl.GL_VERTEX_SHADER) gl.glShaderSource_compat(shader, VERT_CODE) gl.glCompileShader(shader) status = gl.glGetShaderiv(shader, gl.GL_COMPILE_STATUS) if not status: # We could show more useful info here, but that takes a few lines raise RuntimeError('Vertex shader did not compile.') else: gl.glAttachShader(self._prog_handle, shader) # Create fragment shader shader = gl.glCreateShader(gl.GL_FRAGMENT_SHADER) need_enabled = gl.glShaderSource_compat(shader, FRAG_CODE) gl.glCompileShader(shader) status = gl.glGetShaderiv(shader, gl.GL_COMPILE_STATUS) if not status: # We could show more useful info here, but that takes a few lines raise RuntimeError('Fragment shader did not compile.') else: gl.glAttachShader(self._prog_handle, shader) # Enable point sprites for enum in need_enabled: gl.glEnable(enum) # Link gl.glLinkProgram(self._prog_handle) status = gl.glGetProgramiv(self._prog_handle, gl.GL_LINK_STATUS) if not status: # We could show more useful info here, but that takes a few lines raise RuntimeError('Program did not link.') # Create texture self._tex_handle = gl.glGenTextures(1) gl.glPixelStorei(gl.GL_UNPACK_ALIGNMENT, 1) gl.glBindTexture(gl.GL_TEXTURE_2D, self._tex_handle) gl.glTexImage2D(gl.GL_TEXTURE_2D, 0, gl.GL_LUMINANCE, im1.shape[1], im1.shape[0], 0, gl.GL_LUMINANCE, gl.GL_FLOAT, im1.astype(np.float32)) gl.glTexParameter(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MIN_FILTER, gl.GL_LINEAR) gl.glTexParameter(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MAG_FILTER, gl.GL_LINEAR) # Create vertex buffer self._vbo_handle = gl.glGenBuffers(1)
def on_initialize(self, event): gl.glClearColor(1,1,1,1) gl.glEnable(gl.GL_BLEND) gl.glBlendFunc (gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA) n = 10000 self.discs = DiscCollection() self.discs.line_width = 2. self.discs.position = 0.25 * np.random.randn(n, 2).astype(np.float32) self.discs.color = np.random.uniform(0,1,(n,3)).astype(np.float32) self.discs.size = np.random.uniform(2,12,(n,1)).astype(np.float32)
def on_initialize(self, event): gl.glClearColor(1, 1, 1, 1) gl.glEnable(gl.GL_BLEND) gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA) n = 10000 self.discs = DiscCollection() self.discs.line_width = 2. self.discs.position = 0.25 * np.random.randn(n, 2).astype(np.float32) self.discs.color = np.random.uniform(0, 1, (n, 3)).astype(np.float32) self.discs.size = np.random.uniform(2, 12, (n, 1)).astype(np.float32)
def on_initialize(self, event): # Build & activate program self.program = gl.glCreateProgram() vertex = gl.glCreateShader(gl.GL_VERTEX_SHADER) fragment = gl.glCreateShader(gl.GL_FRAGMENT_SHADER) gl.glShaderSource(vertex, vertex_code) gl.glShaderSource(fragment, fragment_code) gl.glCompileShader(vertex) gl.glCompileShader(fragment) gl.glAttachShader(self.program, vertex) gl.glAttachShader(self.program, fragment) gl.glLinkProgram(self.program) gl.glDetachShader(self.program, vertex) gl.glDetachShader(self.program, fragment) gl.glUseProgram(self.program) # Build vertex buffer n = 10000 self.data = np.zeros(n, dtype=[('lifetime', np.float32, 1), ('start', np.float32, 3), ('end', np.float32, 3)]) vbuffer = gl.glCreateBuffer() gl.glBindBuffer(gl.GL_ARRAY_BUFFER, vbuffer) gl.glBufferData(gl.GL_ARRAY_BUFFER, self.data, gl.GL_DYNAMIC_DRAW) # Bind buffer attributes stride = self.data.strides[0] offset = 0 loc = gl.glGetAttribLocation(self.program, "lifetime") gl.glEnableVertexAttribArray(loc) gl.glVertexAttribPointer(loc, 1, gl.GL_FLOAT, False, stride, offset) offset = self.data.dtype["lifetime"].itemsize loc = gl.glGetAttribLocation(self.program, "start") gl.glEnableVertexAttribArray(loc) gl.glVertexAttribPointer(loc, 3, gl.GL_FLOAT, False, stride, offset) offset = self.data.dtype["start"].itemsize loc = gl.glGetAttribLocation(self.program, "end") gl.glEnableVertexAttribArray(loc) gl.glVertexAttribPointer(loc, 3, gl.GL_FLOAT, False, stride, offset) # OpenGL initalization self.elapsed_time = 0 gl.glClearColor(0, 0, 0, 1) gl.glDisable(gl.GL_DEPTH_TEST) gl.glEnable(gl.GL_BLEND) gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE) gl.glEnable(34370) # gl.GL_VERTEX_PROGRAM_POINT_SIZE gl.glEnable(34913) # gl.GL_POINT_SPRITE gl.glViewport(0, 0, *self.physical_size) self.new_explosion() self.timer = app.Timer('auto', self.on_timer, start=True)
def _test_functonality(backend): """ Create app and canvas so we have a context. Then run tests. """ # use the backend gl.use(backend) # Note that we explicitly use pyglet because with Qt we seem # to get errors for this test with app_opengl_context('qt') as context: _clear_screen() # Prepare w, h = context.c.size gl.glViewport(0, 0, w, h) gl.glScissor(0, 0, w, h) # touch gl.glClearColor(0.0, 0.0, 0.0, 1.0) # Setup visualization, ensure to do it in a paint event objects = context.test(_prepare_vis) _clear_screen() # Draw 1 context.test(_draw1) if SHOW: context.c.swap_buffers() app.process_events() time.sleep(1.0) _clear_screen() # Draw 2 context.test(_draw2) if SHOW: context.c.swap_buffers() app.process_events() time.sleep(1.0) _clear_screen() # Draw 3 context.test(_draw3) if SHOW: context.c.swap_buffers() app.process_events() time.sleep(1.0) # Clean up for delete_func, handle in objects: delete_func(handle)
def _test_setting_stuff(): # Set stuff to touch functions gl.glClear(gl.GL_COLOR_BUFFER_BIT) # gl.glBlendColor(1.0, 1.0, 1.0, 1.0) gl.glBlendEquation(gl.GL_FUNC_ADD) gl.glBlendEquationSeparate(gl.GL_FUNC_ADD, gl.GL_FUNC_ADD) gl.glBlendFunc(gl.GL_ONE, gl.GL_ZERO) gl.glBlendFuncSeparate(gl.GL_ONE, gl.GL_ZERO, gl.GL_ONE, gl.GL_ZERO) # gl.glClearColor(0.0, 0.0, 0.0, 1.0) gl.glClearDepth(1) gl.glClearStencil(0) # gl.glColorMask(True, True, True, True) gl.glDepthMask(False) gl.glStencilMask(255) gl.glStencilMaskSeparate(gl.GL_FRONT, 128) # gl.glStencilFunc(gl.GL_ALWAYS, 0, 255) gl.glStencilFuncSeparate(gl.GL_FRONT, gl.GL_ALWAYS, 0, 255) gl.glStencilOp(gl.GL_KEEP, gl.GL_KEEP, gl.GL_KEEP) gl.glStencilOpSeparate(gl.GL_FRONT, gl.GL_KEEP, gl.GL_KEEP, gl.GL_KEEP) # gl.glFrontFace(gl.GL_CW) gl.glHint(gl.GL_GENERATE_MIPMAP_HINT, gl.GL_FASTEST) gl.glLineWidth(2.0) gl.glPolygonOffset(0.0, 0.0) gl.glSampleCoverage(1.0, False) # And getting stuff try: with use_log_level('error', print_msg=False): r, p = gl.glGetShaderPrecisionFormat(gl.GL_FRAGMENT_SHADER, gl.GL_HIGH_FLOAT) gl.check_error() # Sometimes the func is there but OpenGL errs except Exception: pass # accept if the function is not there ... # We should catch RuntimeError and GL.error.NullFunctionError, # but PyOpenGL may not be available. # On Travis this function was not there on one machine according # to PyOpenGL, but our desktop backend worked fine ... # v = gl.glGetParameter(gl.GL_VERSION) assert_true(isinstance(v, string_types)) assert_true(len(v) > 0) gl.check_error()
def __init__(self, n=50): app.Canvas.__init__(self) self.program = gloo.Program(vertex, fragment) gl.glClearColor(1,1,1,1) self.data = np.zeros((10,n), [('x', np.float32, 1), ('y', np.float32, 1), ('i', np.float32, 1)]) self.data['x'] = np.linspace(-1.0, +1.0, n) self.data['y'] = np.random.uniform(-0.1, +0.1, (10,n)) self.data['i'] = np.repeat(np.arange(10),n).reshape(10,n) self.vdata = gloo.VertexBuffer(self.data) self.program.bind(self.vdata)
def __init__(self, n=50): app.Canvas.__init__(self) self.program = gloo.Program(vertex, fragment) gl.glClearColor(1, 1, 1, 1) self.data = np.zeros((10, n), [('x', np.float32, 1), ('y', np.float32, 1), ('i', np.float32, 1)]) self.data['x'] = np.linspace(-1.0, +1.0, n) self.data['y'] = np.random.uniform(-0.1, +0.1, (10, n)) self.data['i'] = np.repeat(np.arange(10), n).reshape(10, n) self.vdata = gloo.VertexBuffer(self.data) self.program.bind(self.vdata)
def __init__(self, n=50): app.Canvas.__init__(self) self.program = gloo.Program(vertex, fragment, n) gl.glClearColor(1, 1, 1, 1) self.data = np.zeros(n, [('x', np.float32, 1), ('y', np.float32, 1)]) self.data['x'] = np.linspace(-1.0, +1.0, n) self.data['y'] = np.random.uniform(-0.5, +0.5, n).astype(np.float32) self.vdata = gloo.VertexBuffer(self.data) self.program.bind(self.vdata) self._timer = app.Timer(1.0 / 60) self._timer.connect(self.on_timer) self._timer.start() self.index = 0
def __init__(self, n=50): app.Canvas.__init__(self) self.program = gloo.Program(vertex, fragment, n) gl.glClearColor(1,1,1,1) self.data = np.zeros(n, [('x', np.float32, 1), ('y', np.float32, 1)]) self.data['x'] = np.linspace(-1.0, +1.0, n) self.data['y'] = np.random.uniform(-0.5, +0.5, n).astype(np.float32) self.vdata = gloo.VertexBuffer(self.data) self.program.bind(self.vdata) self._timer = app.Timer(1.0/60) self._timer.connect(self.on_timer) self._timer.start() self.index = 0
def _test_setting_parameters(): # Set some parameters and get result clr = 1.0, 0.1, 0.2, 0.7 gl.glClearColor(*clr) assert_almost_equal(gl.glGetParameter(gl.GL_COLOR_CLEAR_VALUE), clr) # gl.glCullFace(gl.GL_FRONT) assert_equal(gl.glGetParameter(gl.GL_CULL_FACE_MODE), gl.GL_FRONT) gl.glCullFace(gl.GL_BACK) assert_equal(gl.glGetParameter(gl.GL_CULL_FACE_MODE), gl.GL_BACK) # gl.glDepthFunc(gl.GL_NOTEQUAL) assert_equal(gl.glGetParameter(gl.GL_DEPTH_FUNC), gl.GL_NOTEQUAL) # val = 0.2, 0.3 gl.glDepthRange(*val) assert_almost_equal(gl.glGetParameter(gl.GL_DEPTH_RANGE), val) gl.check_error()
def on_paint(self, event): # Set geometry (is no-op if the size does not change) self._fbo.set_size(*self.size) # Draw the same scene as as in hello_quad.py, but draw it to the FBO with self._fbo: # Init gl.glClearColor(0,0.0,0.5,1); gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT) # Draw self._program1.draw(gl.GL_TRIANGLE_STRIP) # Now draw result to a full-screen quad # Init gl.glClearColor(1,1,1,1); gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT) # Draw self._program2.draw(gl.GL_TRIANGLE_STRIP)
def on_draw(self, event): # Set geometry (is no-op if the size does not change) self._fbo.set_size(*self.size) # Draw the same scene as as in hello_quad.py, but draw it to the FBO with self._fbo: # Init gl.glClearColor(0, 0.0, 0.5, 1) gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT) # Draw self._program1.draw(gl.GL_TRIANGLE_STRIP) # Now draw result to a full-screen quad # Init gl.glClearColor(1, 1, 1, 1) gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT) # Draw self._program2.draw(gl.GL_TRIANGLE_STRIP)
def __init__(self, n=50): app.Canvas.__init__(self, size=(1000,500)) self.program = gloo.Program(vertex, fragment) gl.glClearColor(1,1,1,1) self.data = np.zeros((100,n), [('x', np.float32, 1), ('y', np.float32, 1), ('a', np.float32, 1), ('i', np.float32, 1)]) self.data['x'] = np.linspace(-1.0, +1.0, n) self.data['y'] = np.random.uniform(-0.01, +0.01, (100,n)) self.data['a'] = np.linspace(0.0, +1.0, n) self.data['i'] = np.repeat(np.arange(100),n).reshape(100,n) self.vdata = gloo.VertexBuffer(self.data) self.program.bind(self.vdata) self._timer = app.Timer(1.0/60) self._timer.connect(self.on_timer) self._timer.start() self.index = 0
def __init__(self, n=50): app.Canvas.__init__(self, size=(1000, 500)) self.program = gloo.Program(vertex, fragment) gl.glClearColor(1, 1, 1, 1) self.data = np.zeros((100, n), [('x', np.float32, 1), ('y', np.float32, 1), ('a', np.float32, 1), ('i', np.float32, 1)]) self.data['x'] = np.linspace(-1.0, +1.0, n) self.data['y'] = np.random.uniform(-0.01, +0.01, (100, n)) self.data['a'] = np.linspace(0.0, +1.0, n) self.data['i'] = np.repeat(np.arange(100), n).reshape(100, n) self.vdata = gloo.VertexBuffer(self.data) self.program.bind(self.vdata) self._timer = app.Timer(1.0 / 60) self._timer.connect(self.on_timer) self._timer.start() self.index = 0
def on_initialize(self, event): gl.glClearColor(0, 0, 0, 1) print('on_initialize')
def on_paint(self, event): gl.glClearColor(0.2, 0.4, 0.6, 1.0) gl.glClear(gl.GL_COLOR_BUFFER_BIT) self.program.draw(gl.GL_TRIANGLE_STRIP)
def on_initialize(self, event): gl.glClearColor(1, 1, 1, 1) gl.glEnable(gl.GL_BLEND) gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)
def paint(event): print(' {0:7}: {1}'.format(backend, bgcolor[backend])) gl.glViewport(0, 0, *list(_win_size)) gl.glClearColor(*bgcolor[backend]) gl.glClear(gl.GL_COLOR_BUFFER_BIT) gl.glFinish()
def on_initialize(self, event): gl.glClearColor(0, 0, 0, 1) gl.glDisable(gl.GL_DEPTH_TEST) gl.glEnable(gl.GL_BLEND) gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)
def on_draw(ev): gl.glClearColor(0.0, 0.0, 0.0, 0.0) gl.glClear(gl.GL_COLOR_BUFFER_BIT) canvas.swap_buffers()
def on_initialize(self, event): gl.glClearColor(0, 0, 0, 1) gl.glEnable(gl.GL_DEPTH_TEST)
def on_initialize(self, event): gl.glClearColor(1, 1, 1, 1) gl.glEnable(gl.GL_DEPTH_TEST)
def on_initialize(self, event): gl.glClearColor(0, 0, 0, 1) # Enable blending gl.glEnable(gl.GL_BLEND) gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE)
def on_initialize(self, event): gl.glClearColor(1, 1, 1, 1)
def __init__(self, n=50): app.Canvas.__init__(self) self.program = gloo.Program(vertex, fragment, n) gl.glClearColor(1, 1, 1, 1) self.program['x'] = np.linspace(-1.0, +1.0, n) self.program['y'] = np.random.uniform(-0.5, +0.5, n)
def on_initialize(self, event): # Build & activate cube program self.cube = gl.glCreateProgram() vertex = gl.glCreateShader(gl.GL_VERTEX_SHADER) fragment = gl.glCreateShader(gl.GL_FRAGMENT_SHADER) gl.glShaderSource(vertex, cube_vertex) gl.glShaderSource(fragment, cube_fragment) gl.glCompileShader(vertex) gl.glCompileShader(fragment) gl.glAttachShader(self.cube, vertex) gl.glAttachShader(self.cube, fragment) gl.glLinkProgram(self.cube) gl.glDetachShader(self.cube, vertex) gl.glDetachShader(self.cube, fragment) gl.glUseProgram(self.cube) # Get data & build cube buffers vcube_data, self.icube_data = makecube() vcube = gl.glCreateBuffer() gl.glBindBuffer(gl.GL_ARRAY_BUFFER, vcube) gl.glBufferData(gl.GL_ARRAY_BUFFER, vcube_data, gl.GL_STATIC_DRAW) icube = gl.glCreateBuffer() gl.glBindBuffer(gl.GL_ELEMENT_ARRAY_BUFFER, icube) gl.glBufferData(gl.GL_ELEMENT_ARRAY_BUFFER, self.icube_data, gl.GL_STATIC_DRAW) # Bind cube attributes stride = vcube_data.strides[0] offset = 0 loc = gl.glGetAttribLocation(self.cube, "a_position") gl.glEnableVertexAttribArray(loc) gl.glVertexAttribPointer(loc, 3, gl.GL_FLOAT, False, stride, offset) offset = vcube_data.dtype["a_position"].itemsize loc = gl.glGetAttribLocation(self.cube, "a_texcoord") gl.glEnableVertexAttribArray(loc) gl.glVertexAttribPointer(loc, 2, gl.GL_FLOAT, False, stride, offset) # Create & bind cube texture crate = checkerboard() texture = gl.glCreateTexture() gl.glTexParameterf(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MIN_FILTER, gl.GL_LINEAR) gl.glTexParameterf(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MAG_FILTER, gl.GL_LINEAR) gl.glTexParameterf(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_WRAP_S, gl.GL_CLAMP_TO_EDGE) gl.glTexParameterf(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_WRAP_T, gl.GL_CLAMP_TO_EDGE) gl.glTexImage2D(gl.GL_TEXTURE_2D, 0, gl.GL_LUMINANCE, gl.GL_LUMINANCE, gl.GL_UNSIGNED_BYTE, crate.shape[:2]) gl.glTexSubImage2D(gl.GL_TEXTURE_2D, 0, 0, 0, gl.GL_LUMINANCE, gl.GL_UNSIGNED_BYTE, crate) loc = gl.glGetUniformLocation(self.cube, "u_texture") gl.glUniform1i(loc, texture) gl.glBindTexture(gl.GL_TEXTURE_2D, 0) # Create & bind cube matrices view = np.eye(4, dtype=np.float32) model = np.eye(4, dtype=np.float32) projection = np.eye(4, dtype=np.float32) translate(view, 0, 0, -7) self.phi, self.theta = 60, 20 rotate(model, self.theta, 0, 0, 1) rotate(model, self.phi, 0, 1, 0) loc = gl.glGetUniformLocation(self.cube, "u_model") gl.glUniformMatrix4fv(loc, 1, False, model) loc = gl.glGetUniformLocation(self.cube, "u_view") gl.glUniformMatrix4fv(loc, 1, False, view) loc = gl.glGetUniformLocation(self.cube, "u_projection") gl.glUniformMatrix4fv(loc, 1, False, projection) # OpenGL initalization gl.glClearColor(0.30, 0.30, 0.35, 1.00) gl.glEnable(gl.GL_DEPTH_TEST) self.timer.start()
def on_initialize(self, event): gl.glClearColor(1, 1, 1, 1) gl.glEnable(gl.GL_DEPTH_TEST) # Create shader program self._prog_handle = gl.glCreateProgram() # Create vertex shader shader = gl.glCreateShader(gl.GL_VERTEX_SHADER) gl.glShaderSource(shader, VERT_CODE) gl.glCompileShader(shader) status = gl.glGetShaderiv(shader, gl.GL_COMPILE_STATUS) if not status: # We could show more useful info here, but that takes a few lines raise RuntimeError('Vertex shader did not compile.') else: gl.glAttachShader(self._prog_handle, shader) # Create fragment shader shader = gl.glCreateShader(gl.GL_FRAGMENT_SHADER) gl.glShaderSource(shader, FRAG_CODE) gl.glCompileShader(shader) status = gl.glGetShaderiv(shader, gl.GL_COMPILE_STATUS) if not status: # We could show more useful info here, but that takes a few lines raise RuntimeError('Fragment shader did not compile.') else: gl.glAttachShader(self._prog_handle, shader) # Link gl.glLinkProgram(self._prog_handle) status = gl.glGetProgramiv(self._prog_handle, gl.GL_LINK_STATUS) if not status: # We could show more useful info here, but that takes a few lines raise RuntimeError('Program did not link.') # Create texture im = dataio.crate() self._tex_handle = gl.glGenTextures(1) gl.glPixelStorei(gl.GL_UNPACK_ALIGNMENT, 1) gl.glBindTexture(gl.GL_TEXTURE_2D, self._tex_handle) gl.glTexImage2D(gl.GL_TEXTURE_2D, 0, gl.GL_RGB, im.shape[1], im.shape[0], 0, gl.GL_RGB, gl.GL_UNSIGNED_BYTE, im) gl.glTexParameter(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MIN_FILTER, gl.GL_LINEAR) gl.glTexParameter(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MAG_FILTER, gl.GL_LINEAR) if use_buffers: # Create vertex buffer self._positions_handle = gl.glGenBuffers(1) gl.glBindBuffer(gl.GL_ARRAY_BUFFER, self._positions_handle) gl.glBufferData(gl.GL_ARRAY_BUFFER, positions.nbytes, positions, gl.GL_DYNAMIC_DRAW) # self._texcoords_handle = gl.glGenBuffers(1) gl.glBindBuffer(gl.GL_ARRAY_BUFFER, self._texcoords_handle) gl.glBufferData(gl.GL_ARRAY_BUFFER, texcoords.nbytes, texcoords, gl.GL_DYNAMIC_DRAW) # Create buffer for faces self._faces_handle = gl.glGenBuffers(1) gl.glBindBuffer(gl.GL_ELEMENT_ARRAY_BUFFER, self._faces_handle) gl.glBufferData(gl.GL_ELEMENT_ARRAY_BUFFER, faces.nbytes, faces, gl.GL_DYNAMIC_DRAW)
def on_timer(self, event): self.tick += 1 / 60.0 c = abs(math.sin(self.tick)) gl.glClearColor(c, c, c, 1) self.update()
def on_initialize(self, event): # Build & activate cube program self.cube = gl.glCreateProgram() vertex = gl.glCreateShader(gl.GL_VERTEX_SHADER) fragment = gl.glCreateShader(gl.GL_FRAGMENT_SHADER) gl.glShaderSource(vertex, cube_vertex) gl.glShaderSource(fragment, cube_fragment) gl.glCompileShader(vertex) gl.glCompileShader(fragment) gl.glAttachShader(self.cube, vertex) gl.glAttachShader(self.cube, fragment) gl.glLinkProgram(self.cube) gl.glDetachShader(self.cube, vertex) gl.glDetachShader(self.cube, fragment) gl.glUseProgram(self.cube) # Get data & build cube buffers vcube_data, self.icube_data = makecube() vcube = gl.glCreateBuffer() gl.glBindBuffer(gl.GL_ARRAY_BUFFER, vcube) gl.glBufferData(gl.GL_ARRAY_BUFFER, vcube_data, gl.GL_STATIC_DRAW) icube = gl.glCreateBuffer() gl.glBindBuffer(gl.GL_ELEMENT_ARRAY_BUFFER, icube) gl.glBufferData(gl.GL_ELEMENT_ARRAY_BUFFER, self.icube_data, gl.GL_STATIC_DRAW) # Bind cube attributes stride = vcube_data.strides[0] offset = 0 loc = gl.glGetAttribLocation(self.cube, "a_position") gl.glEnableVertexAttribArray(loc) gl.glVertexAttribPointer(loc, 3, gl.GL_FLOAT, False, stride, offset) offset = vcube_data.dtype["a_position"].itemsize loc = gl.glGetAttribLocation(self.cube, "a_texcoord") gl.glEnableVertexAttribArray(loc) gl.glVertexAttribPointer(loc, 2, gl.GL_FLOAT, False, stride, offset) # Create & bind cube texture crate = checkerboard() texture = gl.glCreateTexture() gl.glTexParameterf(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MIN_FILTER, gl.GL_LINEAR) gl.glTexParameterf(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MAG_FILTER, gl.GL_LINEAR) gl.glTexParameterf(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_WRAP_S, gl.GL_CLAMP_TO_EDGE) gl.glTexParameterf(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_WRAP_T, gl.GL_CLAMP_TO_EDGE) gl.glTexImage2D(gl.GL_TEXTURE_2D, 0, gl.GL_LUMINANCE, gl.GL_LUMINANCE, gl.GL_UNSIGNED_BYTE, crate.shape[:2]) gl.glTexSubImage2D(gl.GL_TEXTURE_2D, 0, 0, 0, gl.GL_LUMINANCE, gl.GL_UNSIGNED_BYTE, crate) loc = gl.glGetUniformLocation(self.cube, "u_texture") gl.glUniform1i(loc, texture) gl.glBindTexture(gl.GL_TEXTURE_2D, 0) # Create & bind cube matrices view = np.eye(4, dtype=np.float32) model = np.eye(4, dtype=np.float32) projection = np.eye(4, dtype=np.float32) translate(view, 0, 0, -7) self.phi, self.theta = 60, 20 rotate(model, self.theta, 0, 0, 1) rotate(model, self.phi, 0, 1, 0) loc = gl.glGetUniformLocation(self.cube, "u_model") gl.glUniformMatrix4fv(loc, 1, False, model) loc = gl.glGetUniformLocation(self.cube, "u_view") gl.glUniformMatrix4fv(loc, 1, False, view) loc = gl.glGetUniformLocation(self.cube, "u_projection") gl.glUniformMatrix4fv(loc, 1, False, projection) # OpenGL initalization gl.glClearColor(0.30, 0.30, 0.35, 1.00) gl.glEnable(gl.GL_DEPTH_TEST) self._resize(*(self.size + self.physical_size)) self.timer = app.Timer('auto', self.on_timer, start=True)
def on_initialize(self, event): gl.glClearColor(0,0,0,1) gl.glDisable(gl.GL_DEPTH_TEST) gl.glEnable(gl.GL_BLEND) gl.glBlendFunc (gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)
def on_initialize(self, event): gl.glClearColor(1,1,1,1) gl.glEnable(gl.GL_BLEND) gl.glBlendFunc (gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)
def on_paint(self, event): gl.glClearColor(0.2, 0.4, 0.6, 1.0) gl.glClear(gl.GL_COLOR_BUFFER_BIT) self.program.draw(gl.GL_POINTS)
def on_paint(event): gl.glClearColor(0.2, 0.4, 0.6, 1.0) gl.glClear(gl.GL_COLOR_BUFFER_BIT)
def on_timer(self, event): self.tick += 1/60.0 c = abs(math.sin(self.tick)) gl.glClearColor(c,c,c,1) self.update()
def on_initialize(self, event): gl.glClearColor(1, 1, 1, 1) gl.glEnable(gl.GL_DEPTH_TEST) gl.glPolygonOffset(1, 1)