Python OpenGL.GL.glColor4f() Examples
The following are 8
code examples of OpenGL.GL.glColor4f().
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: LicModel.py From lic with GNU General Public License v3.0 | 6 votes |
def drawConditionalLines(self): if self.type != GL.GL_LINES or len(self.points) != 12: return # Not a conditional line p = self.points p0 = GLU.gluProject(p[0], p[1], p[2]) p1 = GLU.gluProject(p[3], p[4], p[5]) c0 = GLU.gluProject(p[6], p[7], p[8]) c1 = GLU.gluProject(p[9], p[10], p[11]) winding1 = self.pointWinding(p0, p1, c0) winding2 = self.pointWinding(p0, p1, c1) if winding1 != winding2: return GL.glPushAttrib(GL.GL_CURRENT_BIT) GL.glColor4f(1.0, 1.0, 0.0, 1.0) GL.glBegin(self.type) GL.glVertex3f(p[0], p[1], p[2]) GL.glVertex3f(p[3], p[4], p[5]) GL.glEnd() GL.glPopAttrib()
Example #2
Source File: brush.py From GDMC with ISC License | 5 votes |
def drawTerrainReticle(self): """ Draws the white reticle where the cursor is pointing. Called by leveleditor.render """ if self.optionBackup != self.options: self.saveBrushPreset('__temp__') self.optionBackup = copy.copy(self.options) if not hasattr(self, 'brushMode'): return if self.options[getattr(self.brushMode, 'mainBlock', 'Block')] != self.renderedBlock and not getattr(self.brushMode, 'addPasteButton', False): self.setupPreview() self.renderedBlock = self.options[getattr(self.brushMode, 'mainBlock', 'Block')] if self.pickBlockKey == 1: #Alt is pressed self.editor.drawWireCubeReticle(color=(0.2, 0.6, 0.9, 1.0)) else: pos, direction = self.editor.blockFaceUnderCursor reticlePoint = self.getReticlePoint(pos, direction) self.editor.drawWireCubeReticle(position=reticlePoint) if reticlePoint != pos: GL.glColor4f(1.0, 1.0, 0.0, 0.7) with gl.glBegin(GL.GL_LINES): GL.glVertex3f(*map(lambda a: a + 0.5, reticlePoint)) #Center of reticle block GL.glVertex3f(*map(lambda a, b: a + 0.5 + b * 0.5, pos, direction)) #Top side of surface block dirtyBox = self.getDirtyBox(reticlePoint, self) self.drawTerrainPreview(dirtyBox.origin) if self.lineToolKey and self.lastPosition and getattr(self.brushMode, 'draggableBrush', True): #If dragging mouse with Linetool pressed. GL.glColor4f(1.0, 1.0, 1.0, 0.7) with gl.glBegin(GL.GL_LINES): GL.glVertex3f(*map(lambda a: a + 0.5, self.lastPosition)) GL.glVertex3f(*map(lambda a: a + 0.5, reticlePoint))
Example #3
Source File: LicModel.py From lic with GNU General Public License v3.0 | 5 votes |
def __callPreviousGLDisplayLists(self, isCurrent=False): # Call all previous step's CSI display list prevStep = self.parentItem().getPrevStep() if prevStep: # if prevStep.csi.glDispID == LicGLHelpers.UNINIT_GL_DISPID: prevStep.csi.__callPreviousGLDisplayLists(False) # else: # GL.glCallList(prevStep.csi.glDispID) # Draw all the parts in this CSI # First their edges GL.glPushAttrib(GL.GL_CURRENT_BIT | GL_ENABLE_BIT) GL.glColor4f(0.0, 0.0, 0.0, 1.0) GL.glDisable(GL_LIGHTING) for partItem in self.parts: for part in partItem.parts: part.callGLDisplayList(isCurrent, True) GL.glPopAttrib() # Than their contents for partItem in self.parts: for part in partItem.parts: part.callGLDisplayList(isCurrent, False)
Example #4
Source File: brush.py From MCEdit-Unified with ISC License | 5 votes |
def drawTerrainReticle(self): """ Draws the white reticle where the cursor is pointing. Called by leveleditor.render """ if self.optionBackup != self.options: self.saveBrushPreset('__temp__') self.optionBackup = copy.copy(self.options) if not hasattr(self, 'brushMode'): return if self.options[getattr(self.brushMode, 'mainBlock', 'Block')] != self.renderedBlock and not getattr(self.brushMode, 'addPasteButton', False): self.setupPreview() self.renderedBlock = self.options[getattr(self.brushMode, 'mainBlock', 'Block')] if self.pickBlockKey == 1: #Alt is pressed self.editor.drawWireCubeReticle(color=(0.2, 0.6, 0.9, 1.0)) else: pos, direction = self.editor.blockFaceUnderCursor reticlePoint = self.getReticlePoint(pos, direction) self.editor.drawWireCubeReticle(position=reticlePoint) if reticlePoint != pos: GL.glColor4f(1.0, 1.0, 0.0, 0.7) with gl.glBegin(GL.GL_LINES): GL.glVertex3f(*[a + 0.5 for a in reticlePoint]) #Center of reticle block GL.glVertex3f(*map(lambda a, b: a + 0.5 + b * 0.5, pos, direction)) #Top side of surface block dirtyBox = self.getDirtyBox(reticlePoint, self) self.drawTerrainPreview(dirtyBox.origin) if self.lineToolKey and self.lastPosition and getattr(self.brushMode, 'draggableBrush', True): #If dragging mouse with Linetool pressed. GL.glColor4f(1.0, 1.0, 1.0, 0.7) with gl.glBegin(GL.GL_LINES): GL.glVertex3f(*[a + 0.5 for a in self.lastPosition]) GL.glVertex3f(*[a + 0.5 for a in reticlePoint])
Example #5
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 #6
Source File: LicModel.py From lic with GNU General Public License v3.0 | 4 votes |
def callGLDisplayList(self, useDisplacement, paintingEdge): # must be called inside a glNewList/EndList pair if self.inverted: GL.glPushAttrib(GL.GL_POLYGON_BIT) GL.glFrontFace(GL.GL_CW) if self.matrix: matrix = list(self.matrix) if useDisplacement and self.displacement: matrix[12] += self.displacement[0] matrix[13] += self.displacement[1] matrix[14] += self.displacement[2] GL.glPushMatrix() GL.glMultMatrixf(matrix) if useDisplacement and (self.isSelected() or CSI.highlightNewParts): GL.glPushAttrib(GL.GL_CURRENT_BIT) GL.glColor4f(1.0, 0.0, 0.0, 1.0) self.drawGLBoundingBox() GL.glPopAttrib() if self.color is not None: GL.glPushAttrib(GL.GL_CURRENT_BIT) if paintingEdge: if self.color is not None and self.color.edgeRgba is not None: color = list(self.color.edgeRgba) if useDisplacement and self.isSelected(): color[3] *= 0.6 GL.glColor4fv(color) GL.glCallList(self.abstractPart.glEdgeDispID) else: if self.color is not None: color = list(self.color.rgba) if useDisplacement and self.isSelected(): color[3] *= 0.5 GL.glColor4fv(color) GL.glCallList(self.abstractPart.glDispID) if self.color is not None: GL.glPopAttrib() # self.abstractPart.drawConditionalLines() if self.matrix: GL.glPopMatrix() if self.inverted: GL.glPopAttrib() if not paintingEdge: for arrow in self.arrows: arrow.callGLDisplayList(useDisplacement)
Example #7
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 #8
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()