Python OpenGL.GL.GL_ONE_MINUS_SRC_ALPHA Examples
The following are 14
code examples of OpenGL.GL.GL_ONE_MINUS_SRC_ALPHA().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
OpenGL.GL
, or try the search function
.
Example #1
Source File: player.py From GDMC with ISC License | 6 votes |
def _drawToolMarkers(self): x, y, z = self.editor.level.playerSpawnPosition() GL.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA); GL.glEnable(GL.GL_BLEND); color = config.selectionColors.black.get() + (0.35,) GL.glColor(*color) GL.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_LINE) GL.glLineWidth(2.0) drawCube(FloatBox((x, y, z), (1, 1, 1))) GL.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_FILL) drawCube(FloatBox((x, y, z), (1, 1, 1))) GL.glDisable(GL.GL_BLEND) GL.glEnable(GL.GL_DEPTH_TEST) GL.glColor(1.0, 1.0, 1.0, 1.0) self.drawCage(x, y, z) self.drawCharacterHead(x + 0.5, y + 0.5 + 0.125 * numpy.sin(self.editor.frames * 0.05), z + 0.5) GL.glDisable(GL.GL_DEPTH_TEST)
Example #2
Source File: blipdriver.py From bluesky with GNU General Public License v3.0 | 6 votes |
def initializeGL(self): """Initialize OpenGL, VBOs, upload data on the GPU, etc.""" # First check for supported GL version gl_version = float(gl.glGetString(gl.GL_VERSION)[:3]) if gl_version < 3.3: return # background color gl.glClearColor(0, 0, 0, 0) gl.glEnable(gl.GL_BLEND) gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA) # self.mcp_data = mcpUBO() self.globaldata = ndUBO() self.mcp_col_shader = BlueSkyProgram('mcp.vert', 'color.frag') self.mcp_tex_shader = BlueSkyProgram('mcp.vert', 'texture.frag') self.mcp_txt_shader = BlueSkyProgram('mcp_text.vert', 'mcp_text.frag') self.color_shader = BlueSkyProgram('normal.vert', 'color.frag') self.text_shader = BlueSkyProgram('text.vert', 'text.frag') self.text_shader.bind_uniform_buffer('global_data', self.globaldata) self.create_objects() self.update_lcd()
Example #3
Source File: player.py From MCEdit-Unified with ISC License | 6 votes |
def _drawToolMarkers(self): x, y, z = self.editor.level.playerSpawnPosition() GL.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA) GL.glEnable(GL.GL_BLEND) color = config.selectionColors.black.get() + (0.35,) GL.glColor(*color) GL.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_LINE) GL.glLineWidth(2.0) drawCube(FloatBox((x, y, z), (1, 1, 1))) GL.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_FILL) drawCube(FloatBox((x, y, z), (1, 1, 1))) GL.glDisable(GL.GL_BLEND) GL.glEnable(GL.GL_DEPTH_TEST) GL.glColor(1.0, 1.0, 1.0, 1.0) self.drawCage(x, y, z) self.drawCharacterHead(x + 0.5, y + 0.5 + 0.125 * numpy.sin(self.editor.frames * 0.05), z + 0.5) GL.glDisable(GL.GL_DEPTH_TEST)
Example #4
Source File: widget.py From GDMC with ISC License | 5 votes |
def gl_draw_all(self, root, offset): if not self.visible: return from OpenGL import GL, GLU rect = self.rect.move(offset) if self.is_gl_container: self.gl_draw_self(root, offset) suboffset = rect.topleft for subwidget in self.subwidgets: subwidget.gl_draw_all(root, suboffset) else: try: surface = Surface(self.size, SRCALPHA) except Exception: #size error? return self.draw_all(surface) data = image.tostring(surface, 'RGBA', 1) w, h = root.size GL.glViewport(0, 0, w, h) GL.glMatrixMode(GL.GL_PROJECTION) GL.glLoadIdentity() GLU.gluOrtho2D(0, w, 0, h) GL.glMatrixMode(GL.GL_MODELVIEW) GL.glLoadIdentity() GL.glRasterPos2i(max(rect.left, 0), max(h - rect.bottom, 0)) GL.glPushAttrib(GL.GL_COLOR_BUFFER_BIT) GL.glEnable(GL.GL_BLEND) GL.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA) GL.glDrawPixels(self.width, self.height, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, fromstring(data, dtype='uint8')) GL.glPopAttrib() GL.glFlush()
Example #5
Source File: player.py From GDMC with ISC License | 5 votes |
def drawCharacterHead(self, x, y, z, realCoords=None, dim=0): GL.glEnable(GL.GL_CULL_FACE) origin = (x - 0.25, y - 0.25, z - 0.25) size = (0.5, 0.5, 0.5) box = FloatBox(origin, size) hat_origin = (x - 0.275, y - 0.275, z - 0.275) hat_size = (0.55, 0.55, 0.55) hat_box = FloatBox(hat_origin, hat_size) if realCoords is not None and self.playerPos[dim][realCoords] != "Player" and config.settings.downloadPlayerSkins.get(): drawCube(box, texture=self.playerTexture[self.playerPos[dim][realCoords]], textureVertices=self.texVerts[0]) GL.glEnable(GL.GL_BLEND) GL.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA) drawCube(hat_box, texture=self.playerTexture[self.playerPos[dim][realCoords]], textureVertices=self.texVerts[1]) GL.glDisable(GL.GL_BLEND) else: drawCube(box, texture=self.charTex, textureVertices=self.texVerts[0]) GL.glDisable(GL.GL_CULL_FACE) #@property #def statusText(self): # if not self.panel: # return "" # player = self.panel.selectedPlayer # if player == "Player": # return "Click to move the player" # # return _("Click to move the player \"{0}\"").format(player)
Example #6
Source File: test_opengl.py From spimagine with BSD 3-Clause "New" or "Revised" License | 5 votes |
def initializeGL(self): GL.glClearColor(1.0, 0.0, 0.0, 1.0) GL.glEnable(GL.GL_BLEND) GL.glBlendFunc (GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA) GL.glClear(GL.GL_COLOR_BUFFER_BIT) print("OpenGL.GL: " + str(GL.glGetString(GL.GL_VERSION))) print("GL.GLSL: " + str(GL.glGetString(GL.GL_SHADING_LANGUAGE_VERSION))) print("OpenGL ATTRIBUTES:\n",", ".join(d for d in dir(GL) if d.startswith("GL_"))) self.program = QOpenGLShaderProgram() self.program.addShaderFromSourceCode(QOpenGLShader.Vertex, """#version 120 attribute vec2 position; attribute vec2 texcoord; varying vec2 mytexcoord; void main() { gl_Position = vec4(position, 0., 1.0); mytexcoord = texcoord; }""") self.program.addShaderFromSourceCode(QOpenGLShader.Fragment, """#version 120 uniform sampler2D texture; varying vec2 mytexcoord; void main() { gl_FragColor = texture2D(texture,mytexcoord); }""") print(self.program.log()) self.program.link() self.texture = fillTexture2d(np.outer(np.linspace(0, 1, 128), np.ones(128)))
Example #7
Source File: nd.py From bluesky with GNU General Public License v3.0 | 5 votes |
def initializeGL(self): """Initialize OpenGL, VBOs, upload data on the GPU, etc.""" # First check for supported GL version gl_version = float(gl.glGetString(gl.GL_VERSION)[:3]) if gl_version < 3.3: return # background color gl.glClearColor(0, 0, 0, 0) gl.glEnable(gl.GL_BLEND) gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA) self.globaldata = ndUBO() try: # Compile shaders and link color shader program self.color_shader = BlueSkyProgram('data/graphics/shaders/nd-normal.vert', 'data/graphics/shaders/nd-color.frag') self.color_shader.bind_uniform_buffer('global_data', self.globaldata) # Compile shaders and link text shader program self.text_shader = BlueSkyProgram('data/graphics/shaders/nd-text.vert', 'data/graphics/shaders/nd-text.frag') self.text_shader.bind_uniform_buffer('global_data', self.globaldata) except RuntimeError as e: qCritical('Error compiling shaders in radarwidget: ' + e.args[0]) return # Set initial zoom self.globaldata.set_zoom(4.0) self.create_objects()
Example #8
Source File: widget.py From MCEdit-Unified with ISC License | 5 votes |
def gl_draw_all(self, root, offset): if not self.visible: return #from OpenGL import GL, GLU rect = self.rect.move(offset) if self.is_gl_container: self.gl_draw_self(root, offset) suboffset = rect.topleft for subwidget in self.subwidgets: subwidget.gl_draw_all(root, suboffset) else: try: surface = Surface(self.size, SRCALPHA) except: #size error? return self.draw_all(surface) data = image.tostring(surface, 'RGBA', 1) w, h = root.size GL.glViewport(0, 0, w, h) GL.glMatrixMode(GL.GL_PROJECTION) GL.glLoadIdentity() GLU.gluOrtho2D(0, w, 0, h) GL.glMatrixMode(GL.GL_MODELVIEW) GL.glLoadIdentity() GL.glRasterPos2i(max(rect.left, 0), max(h - rect.bottom, 0)) GL.glPushAttrib(GL.GL_COLOR_BUFFER_BIT) GL.glEnable(GL.GL_BLEND) GL.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA) GL.glDrawPixels(self.width, self.height, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, fromstring(data, dtype='uint8')) GL.glPopAttrib() GL.glFlush()
Example #9
Source File: player.py From MCEdit-Unified with ISC License | 5 votes |
def drawCharacterHead(self, x, y, z, realCoords=None, dim=0): GL.glEnable(GL.GL_CULL_FACE) origin = (x - 0.25, y - 0.25, z - 0.25) size = (0.5, 0.5, 0.5) box = FloatBox(origin, size) hat_origin = (x - 0.275, y - 0.275, z - 0.275) hat_size = (0.55, 0.55, 0.55) hat_box = FloatBox(hat_origin, hat_size) if realCoords is not None and self.playerPos[dim][realCoords] != "Player" and config.settings.downloadPlayerSkins.get(): drawCube(box, texture=self.playerTexture[self.playerPos[dim][realCoords]], textureVertices=self.texVerts[0]) GL.glEnable(GL.GL_BLEND) GL.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA) drawCube(hat_box, texture=self.playerTexture[self.playerPos[dim][realCoords]], textureVertices=self.texVerts[1]) GL.glDisable(GL.GL_BLEND) else: drawCube(box, texture=self.charTex, textureVertices=self.texVerts[0]) GL.glDisable(GL.GL_CULL_FACE) #@property #def statusText(self): # if not self.panel: # return "" # player = self.panel.selectedPlayer # if player == "Player": # return "Click to move the player" # # return _("Click to move the player \"{0}\"").format(player)
Example #10
Source File: PlotCurveItem.py From tf-pose with Apache License 2.0 | 4 votes |
def paintGL(self, p, opt, widget): p.beginNativePainting() import OpenGL.GL as gl ## set clipping viewport view = self.getViewBox() if view is not None: rect = view.mapRectToItem(self, view.boundingRect()) #gl.glViewport(int(rect.x()), int(rect.y()), int(rect.width()), int(rect.height())) #gl.glTranslate(-rect.x(), -rect.y(), 0) gl.glEnable(gl.GL_STENCIL_TEST) gl.glColorMask(gl.GL_FALSE, gl.GL_FALSE, gl.GL_FALSE, gl.GL_FALSE) # disable drawing to frame buffer gl.glDepthMask(gl.GL_FALSE) # disable drawing to depth buffer gl.glStencilFunc(gl.GL_NEVER, 1, 0xFF) gl.glStencilOp(gl.GL_REPLACE, gl.GL_KEEP, gl.GL_KEEP) ## draw stencil pattern gl.glStencilMask(0xFF) gl.glClear(gl.GL_STENCIL_BUFFER_BIT) gl.glBegin(gl.GL_TRIANGLES) gl.glVertex2f(rect.x(), rect.y()) gl.glVertex2f(rect.x()+rect.width(), rect.y()) gl.glVertex2f(rect.x(), rect.y()+rect.height()) gl.glVertex2f(rect.x()+rect.width(), rect.y()+rect.height()) gl.glVertex2f(rect.x()+rect.width(), rect.y()) gl.glVertex2f(rect.x(), rect.y()+rect.height()) gl.glEnd() gl.glColorMask(gl.GL_TRUE, gl.GL_TRUE, gl.GL_TRUE, gl.GL_TRUE) gl.glDepthMask(gl.GL_TRUE) gl.glStencilMask(0x00) gl.glStencilFunc(gl.GL_EQUAL, 1, 0xFF) try: x, y = self.getData() pos = np.empty((len(x), 2)) pos[:,0] = x pos[:,1] = y gl.glEnableClientState(gl.GL_VERTEX_ARRAY) try: gl.glVertexPointerf(pos) pen = fn.mkPen(self.opts['pen']) color = pen.color() gl.glColor4f(color.red()/255., color.green()/255., color.blue()/255., color.alpha()/255.) width = pen.width() if pen.isCosmetic() and width < 1: width = 1 gl.glPointSize(width) gl.glEnable(gl.GL_LINE_SMOOTH) gl.glEnable(gl.GL_BLEND) gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA) gl.glHint(gl.GL_LINE_SMOOTH_HINT, gl.GL_NICEST) gl.glDrawArrays(gl.GL_LINE_STRIP, 0, pos.size / pos.shape[-1]) finally: gl.glDisableClientState(gl.GL_VERTEX_ARRAY) finally: p.endNativePainting()
Example #11
Source File: controller.py From renpy-shader with MIT License | 4 votes |
def renderImage(self, context): width, height = self.getSize() gl.glViewport(0, 0, width, height) gl.glDisable(gl.GL_SCISSOR_TEST) gl.glEnable(gl.GL_ALPHA_TEST) gl.glAlphaFunc(gl.GL_GREATER, 0) gl.glEnable(gl.GL_BLEND) gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA) self.frameBuffer.bind() self.renderer.render(context) self.frameBuffer.unbind() #TODO Restore blend state. Any other states that need restoring...? gl.glBlendFunc(gl.GL_ONE, gl.GL_ONE_MINUS_SRC_ALPHA)
Example #12
Source File: radarwidget.py From bluesky with GNU General Public License v3.0 | 4 votes |
def initializeGL(self): """Initialize OpenGL, VBOs, upload data on the GPU, etc.""" # First check for supported GL version gl_version = float(gl.glGetString(gl.GL_VERSION)[:3]) if gl_version < 3.3: print(('OpenGL context created with GL version %.1f' % gl_version)) qCritical("""Your system reports that it supports OpenGL up to version %.1f. The minimum requirement for BlueSky is OpenGL 3.3. Generally, AMD/ATI/nVidia cards from 2008 and newer support OpenGL 3.3, and Intel integrated graphics from the Haswell generation and newer. If you think your graphics system should be able to support GL>=3.3 please open an issue report on the BlueSky Github page (https://github.com/ProfHoekstra/bluesky/issues)""" % gl_version) return # background color gl.glClearColor(*(palette.background + (0,))) gl.glEnable(gl.GL_BLEND) gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA) self.globaldata = radarUBO() try: shpath = path.join(settings.gfx_path, 'shaders') # Compile shaders and link color shader program self.color_shader = BlueSkyProgram(path.join(shpath, 'radarwidget-normal.vert'), path.join(shpath, 'radarwidget-color.frag')) self.color_shader.bind_uniform_buffer('global_data', self.globaldata) # Compile shaders and link texture shader program self.texture_shader = BlueSkyProgram(path.join(shpath, 'radarwidget-normal.vert'), path.join(shpath, 'radarwidget-texture.frag')) self.texture_shader.bind_uniform_buffer('global_data', self.globaldata) # Compile shaders and link text shader program self.text_shader = BlueSkyProgram(path.join(shpath, 'radarwidget-text.vert'), path.join(shpath, 'radarwidget-text.frag')) self.text_shader.bind_uniform_buffer('global_data', self.globaldata) self.ssd_shader = BlueSkyProgram(path.join(shpath, 'ssd.vert'), path.join(shpath, 'ssd.frag'), path.join(shpath, 'ssd.geom')) self.ssd_shader.bind_uniform_buffer('global_data', self.globaldata) self.ssd_shader.loc_vlimits = gl.glGetUniformLocation(self.ssd_shader.program, 'Vlimits') self.ssd_shader.loc_nac = gl.glGetUniformLocation(self.ssd_shader.program, 'n_ac') except RuntimeError as e: print('Error compiling shaders in radarwidget: ' + e.args[0]) qCritical('Error compiling shaders in radarwidget: ' + e.args[0]) return # create all vertex array objects try: self.create_objects() except Exception as e: print('Error while creating RadarWidget objects: ' + e.args[0])
Example #13
Source File: PlotCurveItem.py From soapy with GNU General Public License v3.0 | 4 votes |
def paintGL(self, p, opt, widget): p.beginNativePainting() import OpenGL.GL as gl ## set clipping viewport view = self.getViewBox() if view is not None: rect = view.mapRectToItem(self, view.boundingRect()) #gl.glViewport(int(rect.x()), int(rect.y()), int(rect.width()), int(rect.height())) #gl.glTranslate(-rect.x(), -rect.y(), 0) gl.glEnable(gl.GL_STENCIL_TEST) gl.glColorMask(gl.GL_FALSE, gl.GL_FALSE, gl.GL_FALSE, gl.GL_FALSE) # disable drawing to frame buffer gl.glDepthMask(gl.GL_FALSE) # disable drawing to depth buffer gl.glStencilFunc(gl.GL_NEVER, 1, 0xFF) gl.glStencilOp(gl.GL_REPLACE, gl.GL_KEEP, gl.GL_KEEP) ## draw stencil pattern gl.glStencilMask(0xFF) gl.glClear(gl.GL_STENCIL_BUFFER_BIT) gl.glBegin(gl.GL_TRIANGLES) gl.glVertex2f(rect.x(), rect.y()) gl.glVertex2f(rect.x()+rect.width(), rect.y()) gl.glVertex2f(rect.x(), rect.y()+rect.height()) gl.glVertex2f(rect.x()+rect.width(), rect.y()+rect.height()) gl.glVertex2f(rect.x()+rect.width(), rect.y()) gl.glVertex2f(rect.x(), rect.y()+rect.height()) gl.glEnd() gl.glColorMask(gl.GL_TRUE, gl.GL_TRUE, gl.GL_TRUE, gl.GL_TRUE) gl.glDepthMask(gl.GL_TRUE) gl.glStencilMask(0x00) gl.glStencilFunc(gl.GL_EQUAL, 1, 0xFF) try: x, y = self.getData() pos = np.empty((len(x), 2)) pos[:,0] = x pos[:,1] = y gl.glEnableClientState(gl.GL_VERTEX_ARRAY) try: gl.glVertexPointerf(pos) pen = fn.mkPen(self.opts['pen']) color = pen.color() gl.glColor4f(color.red()/255., color.green()/255., color.blue()/255., color.alpha()/255.) width = pen.width() if pen.isCosmetic() and width < 1: width = 1 gl.glPointSize(width) gl.glEnable(gl.GL_LINE_SMOOTH) gl.glEnable(gl.GL_BLEND) gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA) gl.glHint(gl.GL_LINE_SMOOTH_HINT, gl.GL_NICEST) gl.glDrawArrays(gl.GL_LINE_STRIP, 0, pos.size / pos.shape[-1]) finally: gl.glDisableClientState(gl.GL_VERTEX_ARRAY) finally: p.endNativePainting()
Example #14
Source File: PlotCurveItem.py From qgisSpaceSyntaxToolkit with GNU General Public License v3.0 | 4 votes |
def paintGL(self, p, opt, widget): p.beginNativePainting() import OpenGL.GL as gl ## set clipping viewport view = self.getViewBox() if view is not None: rect = view.mapRectToItem(self, view.boundingRect()) #gl.glViewport(int(rect.x()), int(rect.y()), int(rect.width()), int(rect.height())) #gl.glTranslate(-rect.x(), -rect.y(), 0) gl.glEnable(gl.GL_STENCIL_TEST) gl.glColorMask(gl.GL_FALSE, gl.GL_FALSE, gl.GL_FALSE, gl.GL_FALSE) # disable drawing to frame buffer gl.glDepthMask(gl.GL_FALSE) # disable drawing to depth buffer gl.glStencilFunc(gl.GL_NEVER, 1, 0xFF) gl.glStencilOp(gl.GL_REPLACE, gl.GL_KEEP, gl.GL_KEEP) ## draw stencil pattern gl.glStencilMask(0xFF) gl.glClear(gl.GL_STENCIL_BUFFER_BIT) gl.glBegin(gl.GL_TRIANGLES) gl.glVertex2f(rect.x(), rect.y()) gl.glVertex2f(rect.x()+rect.width(), rect.y()) gl.glVertex2f(rect.x(), rect.y()+rect.height()) gl.glVertex2f(rect.x()+rect.width(), rect.y()+rect.height()) gl.glVertex2f(rect.x()+rect.width(), rect.y()) gl.glVertex2f(rect.x(), rect.y()+rect.height()) gl.glEnd() gl.glColorMask(gl.GL_TRUE, gl.GL_TRUE, gl.GL_TRUE, gl.GL_TRUE) gl.glDepthMask(gl.GL_TRUE) gl.glStencilMask(0x00) gl.glStencilFunc(gl.GL_EQUAL, 1, 0xFF) try: x, y = self.getData() pos = np.empty((len(x), 2)) pos[:,0] = x pos[:,1] = y gl.glEnableClientState(gl.GL_VERTEX_ARRAY) try: gl.glVertexPointerf(pos) pen = fn.mkPen(self.opts['pen']) color = pen.color() gl.glColor4f(color.red()/255., color.green()/255., color.blue()/255., color.alpha()/255.) width = pen.width() if pen.isCosmetic() and width < 1: width = 1 gl.glPointSize(width) gl.glEnable(gl.GL_LINE_SMOOTH) gl.glEnable(gl.GL_BLEND) gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA) gl.glHint(gl.GL_LINE_SMOOTH_HINT, gl.GL_NICEST) gl.glDrawArrays(gl.GL_LINE_STRIP, 0, pos.size / pos.shape[-1]) finally: gl.glDisableClientState(gl.GL_VERTEX_ARRAY) finally: p.endNativePainting()