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 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 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 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 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): # 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): # 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 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 _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 draw_model(self): gl.glEnable(gl.GL_DEPTH_TEST) gl.glDepthMask(gl.GL_TRUE) gl.glFrontFace(gl.GL_CCW) gl.glDisable(gl.GL_BLEND) gl.glBlendFunc(gl.GL_ZERO, gl.GL_ZERO) if self.render_params['transparent']: gl.glEnable(gl.GL_BLEND) gl.glDepthMask(gl.GL_FALSE) gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA) self.program_solids.draw('triangles')
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_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(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)