Python OpenGL.GL.glPopMatrix() Examples
The following are 19
code examples of OpenGL.GL.glPopMatrix().
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: ndwindow.py From spectral with MIT License | 6 votes |
def render_rgb_indexed_colors(self, **kwargs): '''Draws scene in the background buffer to extract mouse click info''' import OpenGL.GL as gl import OpenGL.GLU as glu gl.glMatrixMode(gl.GL_MODELVIEW) gl.glLoadIdentity() gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT) # camera_pos_rtp is relative to the target position. To get the # absolute camera position, we need to add the target position. gl.glPushMatrix() camera_pos_xyz = np.array(rtp_to_xyz(*self.camera_pos_rtp)) \ + self.target_pos glu.gluLookAt( *(list(camera_pos_xyz) + list(self.target_pos) + self.up)) self.draw_data_set() gl.glPopMatrix() gl.glFlush()
Example #2
Source File: leveleditor.py From GDMC with ISC License | 6 votes |
def freezeStatus(string): return # GL.glColor(1.0, 0., 0., 1.0) # # # glDrawBuffer(GL.GL_FRONT) # GL.glMatrixMode(GL.GL_PROJECTION) # GL.glPushMatrix() # glRasterPos(50, 100) # for i in string: # glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, ord(i)) # # # glDrawBuffer(GL.GL_BACK) # GL.glMatrixMode(GL.GL_PROJECTION) # GL.glPopMatrix() # glFlush() # display.flip() # # while(True): pass
Example #3
Source File: render_scene.py From holistic_scene_parsing with MIT License | 6 votes |
def add_object_seg(filename, xyz, unit, up_string, front_string, center, angle, size, segment_id, obj_info, layout_type=None): GL.glPushMatrix() x = xyz[0] y = xyz[1] z = xyz[2] # translate in view if layout_type is not None: GL.glTranslatef(center[0], center[1], center[2]) else: GL.glTranslatef(center[0], center[1], center[2] - size[2] / 2) GL.glRotate(angle, 0, 1, 0) GL.glScalef(size[0] * 100 / x, size[1] * 100 / y, size[2] * 100 / z) # normalize directions, rotate object to front: front -> 0,0,1 | up -> 0,1,0 alignment = align_directions(up_string, front_string) if not alignment: GL.glPopMatrix() return # obj = OBJ_NORMAL(filename, swapyz=False) obj = OBJ_SEG(obj_info['info'], color=[segment_id / 255.0, 0.0, 0.0], swapyz=False) GL.glCallList(obj.gl_list) GL.glPopMatrix() # angle is the object rotation angle
Example #4
Source File: hypercube.py From spectral with MIT License | 5 votes |
def on_paint(self, event): """Process the drawing event.""" import OpenGL.GL as gl import OpenGL.GLU as glu self.canvas.SetCurrent(self.canvas.context) if not self.gl_initialized: self.initgl() self.gl_initialized = True self.print_help() if self.light: gl.glEnable(gl.GL_LIGHTING) else: gl.glDisable(gl.GL_LIGHTING) gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT) gl.glLoadIdentity() gl.glPushMatrix() glu.gluLookAt(*(list(rtp_to_xyz( *self.camera_pos_rtp)) + list(self.target_pos) + list(self.up))) self.draw_cube() gl.glPopMatrix() gl.glFlush() self.SwapBuffers() event.Skip()
Example #5
Source File: fill.py From MCEdit-Unified with ISC License | 5 votes |
def drawToolMarkers(self): if self.editor.currentTool != self: return if self.panel and self.replacing: blockInfo = self.replaceBlockInfo else: blockInfo = self.blockInfo color = 1.0, 1.0, 1.0, 0.35 if blockInfo: terrainTexture = self.editor.level.materials.terrainTexture tex = self.editor.level.materials.blockTextures[blockInfo.ID, blockInfo.blockData, 0] # xxx tex = Texture(self.blockTexFunc(terrainTexture, tex)) # color = (1.5 - alpha, 1.0, 1.5 - alpha, alpha - 0.35) GL.glMatrixMode(GL.GL_TEXTURE) GL.glPushMatrix() GL.glScale(16., 16., 16.) else: tex = None # color = (1.0, 0.3, 0.3, alpha - 0.35) GL.glPolygonOffset(DepthOffset.FillMarkers, DepthOffset.FillMarkers) self.editor.drawConstructionCube(self.selectionBox(), color, texture=tex) if blockInfo: GL.glMatrixMode(GL.GL_TEXTURE) GL.glPopMatrix()
Example #6
Source File: glutils.py From MCEdit-Unified with ISC License | 5 votes |
def glPushMatrix(cls, matrixmode): try: GL.glMatrixMode(matrixmode) GL.glPushMatrix() yield finally: GL.glMatrixMode(matrixmode) GL.glPopMatrix()
Example #7
Source File: glutils.py From GDMC with ISC License | 5 votes |
def glPushMatrix(cls, matrixmode): try: GL.glMatrixMode(matrixmode) GL.glPushMatrix() yield finally: GL.glMatrixMode(matrixmode) GL.glPopMatrix()
Example #8
Source File: fill.py From GDMC with ISC License | 5 votes |
def drawToolMarkers(self): if self.editor.currentTool != self: return if self.panel and self.replacing: blockInfo = self.replaceBlockInfo else: blockInfo = self.blockInfo color = 1.0, 1.0, 1.0, 0.35 if blockInfo: terrainTexture = self.editor.level.materials.terrainTexture tex = self.editor.level.materials.blockTextures[blockInfo.ID, blockInfo.blockData, 0] # xxx tex = Texture(self.blockTexFunc(terrainTexture, tex)) # color = (1.5 - alpha, 1.0, 1.5 - alpha, alpha - 0.35) GL.glMatrixMode(GL.GL_TEXTURE) GL.glPushMatrix() GL.glScale(16., 16., 16.) else: tex = None # color = (1.0, 0.3, 0.3, alpha - 0.35) GL.glPolygonOffset(DepthOffset.FillMarkers, DepthOffset.FillMarkers) self.editor.drawConstructionCube(self.selectionBox(), color, texture=tex) if blockInfo: GL.glMatrixMode(GL.GL_TEXTURE) GL.glPopMatrix()
Example #9
Source File: render_scene.py From holistic_scene_parsing with MIT License | 5 votes |
def add_object(filename, xyz, unit, up_string, front_string, center, angle, size, obj_color, obj_info, layout_type=None): # x_min,y_min,z_min,x_max,y_max,z_max GL.glPushMatrix() # after unit conversion... x = xyz[0] y = xyz[1] z = xyz[2] # print center, size # translate in view if layout_type is not None: GL.glTranslatef(center[0], center[1], center[2]) else: GL.glTranslatef(center[0], center[1], center[2] - size[2] / 2) GL.glRotate(angle, 0, 1, 0) GL.glScalef(size[0] * 100 / x, size[1] * 100 / y, size[2] * 100 / z) # x,y,z y is up # normalize directions, rotate object to front: front -> 0,0,1 | up -> 0,1,0 alignment = align_directions(up_string, front_string) if not alignment: GL.glPopMatrix() return # obj = OBJ_NORMAL(filename, swapyz=False) obj = OBJ(obj_info['info'], obj_color=obj_color, swapyz=False) GL.glCallList(obj.gl_list) GL.glPopMatrix() # read metadata info from csv file
Example #10
Source File: LicModel.py From lic with GNU General Public License v3.0 | 5 votes |
def callGLDisplayList(self, useDisplacement=False): if not useDisplacement: return # Must be called inside a glNewList/EndList pair if self.color is not None: color = list(self.color.rgba) if self.isSelected(): color[3] *= 0.6 GL.glPushAttrib(GL.GL_CURRENT_BIT) GL.glColor4fv(color) matrix = list(self.matrix) if self.displacement: matrix[12] += self.displacement[0] matrix[13] += self.displacement[1] matrix[14] += self.displacement[2] GL.glPushMatrix() GL.glMultMatrixf(matrix) # LicGLHelpers.drawCoordLines() self.doGLRotation() if self.isSelected(): self.drawGLBoundingBox() GL.glCallList(self.abstractPart.glDispID) GL.glPopMatrix() if self.color is not None: GL.glPopAttrib()
Example #11
Source File: render_scene.py From holistic_scene_parsing with MIT License | 5 votes |
def add_object_normal(filename, xyz, unit, up_string, front_string, center, angle, size, beta, obj_info, layout_type=None): GL.glPushMatrix() x = xyz[0] y = xyz[1] z = xyz[2] del rotation_matrix_list[:] # translate in view if layout_type is not None: GL.glTranslatef(center[0], center[1], center[2]) else: GL.glTranslatef(center[0], center[1], center[2] - size[2] / 2) GL.glRotate(angle, 0, 1, 0) rotation_matrix_list.append(rotation_matrix(angle, 0, 1, 0)) # scale object GL.glScalef(size[0] * 100 / x, size[1] * 100 / y, size[2] * 100 / z) # normalize directions, rotate object to front: front -> 0,0,1 | up -> 0,1,0 alignment = align_directions(up_string, front_string) if not alignment: GL.glPopMatrix() return rm = np.identity(3) for i in range(len(rotation_matrix_list) - 1, -1, -1): rm = rotation_matrix_list[i].dot(rm) rm = rotation_matrix(beta, 1, 0, 0).dot(rm) obj = OBJ_NORMAL(obj_info['info'], rotation_matrix=rm, swapyz=False, layout_type=layout_type) GL.glCallList(obj.gl_list) GL.glPopMatrix()
Example #12
Source File: player.py From GDMC with ISC License | 4 votes |
def _drawToolMarkers(self): GL.glColor(1.0, 1.0, 1.0, 0.5) GL.glEnable(GL.GL_DEPTH_TEST) GL.glMatrixMode(GL.GL_MODELVIEW) for player in self.editor.level.players: try: pos = self.editor.level.getPlayerPosition(player) yaw, pitch = self.editor.level.getPlayerOrientation(player) dim = self.editor.level.getPlayerDimension(player) self.inOtherDimension[dim].append(player) self.playerPos[dim][pos] = player self.revPlayerPos[dim][player] = pos if player != "Player" and config.settings.downloadPlayerSkins.get(): self.playerTexture[player] = loadPNGTexture(self.playercache.getPlayerSkin(player, force_download=False)) else: self.playerTexture[player] = self.charTex if dim != self.editor.level.dimNo: continue x, y, z = pos GL.glPushMatrix() GL.glTranslate(x, y, z) GL.glRotate(-yaw, 0, 1, 0) GL.glRotate(pitch, 1, 0, 0) GL.glColor(1, 1, 1, 1) self.drawCharacterHead(0, 0, 0, (x,y,z), self.editor.level.dimNo) GL.glPopMatrix() # GL.glEnable(GL.GL_BLEND) drawTerrainCuttingWire(FloatBox((x - .5, y - .5, z - .5), (1, 1, 1)), c0=(0.3, 0.9, 0.7, 1.0), c1=(0, 0, 0, 0), ) #GL.glDisable(GL.GL_BLEND) except Exception, e: print repr(e) continue
Example #13
Source File: player.py From MCEdit-Unified with ISC License | 4 votes |
def _drawToolMarkers(self): GL.glColor(1.0, 1.0, 1.0, 0.5) GL.glEnable(GL.GL_DEPTH_TEST) GL.glMatrixMode(GL.GL_MODELVIEW) for player in self.editor.level.players: try: pos = self.editor.level.getPlayerPosition(player) yaw, pitch = self.editor.level.getPlayerOrientation(player) dim = self.editor.level.getPlayerDimension(player) self.inOtherDimension[dim].append(player) self.playerPos[dim][pos] = player self.revPlayerPos[dim][player] = pos if player != "Player" and config.settings.downloadPlayerSkins.get(): # print 7 r = self.playercache.getPlayerSkin(player, force_download=False) if not isinstance(r, (str, unicode)): r = r.join() self.playerTexture[player] = loadPNGTexture(r) else: self.playerTexture[player] = self.charTex if dim != self.editor.level.dimNo: continue x, y, z = pos GL.glPushMatrix() GL.glTranslate(x, y, z) GL.glRotate(-yaw, 0, 1, 0) GL.glRotate(pitch, 1, 0, 0) GL.glColor(1, 1, 1, 1) self.drawCharacterHead(0, 0, 0, (x,y,z), self.editor.level.dimNo) GL.glPopMatrix() # GL.glEnable(GL.GL_BLEND) drawTerrainCuttingWire(FloatBox((x - .5, y - .5, z - .5), (1, 1, 1)), c0=(0.3, 0.9, 0.7, 1.0), c1=(0, 0, 0, 0), ) #GL.glDisable(GL.GL_BLEND) except Exception, e: print "Exception in editortools.player.PlayerPositionTool._drawToolMarkers:", repr(e) import traceback print traceback.format_exc() continue
Example #14
Source File: camera.py From MCEdit-Unified with ISC License | 4 votes |
def _drawSkyBackground(self): GL.glMatrixMode(GL.GL_MODELVIEW) GL.glPushMatrix() GL.glLoadIdentity() GL.glMatrixMode(GL.GL_PROJECTION) GL.glPushMatrix() GL.glLoadIdentity() GL.glEnableClientState(GL.GL_COLOR_ARRAY) quad = numpy.array([-1, -1, -1, 1, 1, 1, 1, -1], dtype='float32') if self.editor.level.dimNo == -1: colors = numpy.array([0x90, 0x00, 0x00, 0xff, 0x90, 0x00, 0x00, 0xff, 0x90, 0x00, 0x00, 0xff, 0x90, 0x00, 0x00, 0xff, ], dtype='uint8') elif self.editor.level.dimNo == 1: colors = numpy.array([0x22, 0x27, 0x28, 0xff, 0x22, 0x27, 0x28, 0xff, 0x22, 0x27, 0x28, 0xff, 0x22, 0x27, 0x28, 0xff, ], dtype='uint8') else: colors = numpy.array([0x48, 0x49, 0xBA, 0xff, 0x8a, 0xaf, 0xff, 0xff, 0x8a, 0xaf, 0xff, 0xff, 0x48, 0x49, 0xBA, 0xff, ], dtype='uint8') alpha = 1.0 if alpha > 0.0: if alpha < 1.0: GL.glEnable(GL.GL_BLEND) GL.glVertexPointer(2, GL.GL_FLOAT, 0, quad) GL.glColorPointer(4, GL.GL_UNSIGNED_BYTE, 0, colors) GL.glDrawArrays(GL.GL_QUADS, 0, 4) if alpha < 1.0: GL.glDisable(GL.GL_BLEND) GL.glDisableClientState(GL.GL_COLOR_ARRAY) GL.glMatrixMode(GL.GL_PROJECTION) GL.glPopMatrix() GL.glMatrixMode(GL.GL_MODELVIEW) GL.glPopMatrix()
Example #15
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 #16
Source File: electrodeGUI.py From simnibs with GNU General Public License v3.0 | 4 votes |
def drawPointAndDirs(self): xAxis = numpy.array([1,0,0], 'float') yAxis = numpy.array([0,1,0], 'float') zAxis = numpy.array([0,0,1], 'float') center =numpy.array([0,0,0], 'float') qobj = GLU.gluNewQuadric() sphere_radius = 0.1 cyl_height = 1 cyl_radius = 0.01 z_dir = numpy.array([0.,0.,1.], dtype = 'float64') genList = GL.glGenLists(1) GL.glNewList(genList, GL.GL_COMPILE) #Cylinder along z, we want it to be allong xAxis #Solution: use the appropriate rotation matrix #We have to choose the right axis, perpendicular to both, and rotate by the appropriate angle, the angle between the 2 vectors self.qglColor(QtGui.QColor.fromCmykF(0., 1., 1., 0.)) rotation_dir = numpy.cross(z_dir,xAxis) angle = math.acos(z_dir.dot(xAxis))*180/3.14159 GL.glPushMatrix() GL.glTranslatef(center[0],center[1],center[2]) GL.glRotatef(angle, rotation_dir[0],rotation_dir[1],rotation_dir[2]) GLU.gluCylinder(qobj,cyl_radius,cyl_radius,cyl_height,20,20) GL.glPopMatrix() self.qglColor(QtGui.QColor.fromCmykF(1., 0., 1., 0.)) rotation_dir = numpy.cross(z_dir,yAxis) angle = math.acos(z_dir.dot(yAxis))*180/3.14159 GL.glPushMatrix() GL.glTranslatef(center[0],center[1],center[2]) GL.glRotatef(angle, rotation_dir[0],rotation_dir[1],rotation_dir[2]) GLU.gluCylinder(qobj,cyl_radius,cyl_radius,cyl_height,20,20) GL.glPopMatrix() GL.glEndList() return genList
Example #17
Source File: camera.py From GDMC with ISC License | 4 votes |
def _drawSkyBackground(self): GL.glMatrixMode(GL.GL_MODELVIEW) GL.glPushMatrix() GL.glLoadIdentity() GL.glMatrixMode(GL.GL_PROJECTION) GL.glPushMatrix() GL.glLoadIdentity() GL.glEnableClientState(GL.GL_COLOR_ARRAY) quad = numpy.array([-1, -1, -1, 1, 1, 1, 1, -1], dtype='float32') if self.editor.level.dimNo == -1: colors = numpy.array([0x90, 0x00, 0x00, 0xff, 0x90, 0x00, 0x00, 0xff, 0x90, 0x00, 0x00, 0xff, 0x90, 0x00, 0x00, 0xff, ], dtype='uint8') elif self.editor.level.dimNo == 1: colors = numpy.array([0x22, 0x27, 0x28, 0xff, 0x22, 0x27, 0x28, 0xff, 0x22, 0x27, 0x28, 0xff, 0x22, 0x27, 0x28, 0xff, ], dtype='uint8') else: colors = numpy.array([0x48, 0x49, 0xBA, 0xff, 0x8a, 0xaf, 0xff, 0xff, 0x8a, 0xaf, 0xff, 0xff, 0x48, 0x49, 0xBA, 0xff, ], dtype='uint8') alpha = 1.0 if alpha > 0.0: if alpha < 1.0: GL.glEnable(GL.GL_BLEND) GL.glVertexPointer(2, GL.GL_FLOAT, 0, quad) GL.glColorPointer(4, GL.GL_UNSIGNED_BYTE, 0, colors) GL.glDrawArrays(GL.GL_QUADS, 0, 4) if alpha < 1.0: GL.glDisable(GL.GL_BLEND) GL.glDisableClientState(GL.GL_COLOR_ARRAY) GL.glMatrixMode(GL.GL_PROJECTION) GL.glPopMatrix() GL.glMatrixMode(GL.GL_MODELVIEW) GL.glPopMatrix()
Example #18
Source File: ndwindow.py From spectral with MIT License | 4 votes |
def on_paint(self, event): '''Renders the entire scene.''' import OpenGL.GL as gl import OpenGL.GLU as glu self.canvas.SetCurrent(self.canvas.context) if not self.gl_initialized: self.initgl() self.gl_initialized = True self.print_help() self.resize(*self.size) gl.glMatrixMode(gl.GL_MODELVIEW) gl.glLoadIdentity() gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT) while len(self._display_commands) > 0: self._display_commands.pop(0)() if self._refresh_display_lists: self.create_display_lists() gl.glPushMatrix() # camera_pos_rtp is relative to target position. To get the absolute # camera position, we need to add the target position. camera_pos_xyz = np.array(rtp_to_xyz(*self.camera_pos_rtp)) \ + self.target_pos glu.gluLookAt( *(list(camera_pos_xyz) + list(self.target_pos) + self.up)) if self.show_axes_tf: gl.glCallList(self.gllist_id) self.draw_data_set() gl.glPopMatrix() gl.glFlush() if self._selection_box is not None: self.draw_box(*self._selection_box) self.SwapBuffers() event.Skip()
Example #19
Source File: head_model_OGL.py From simnibs with GNU General Public License v3.0 | 4 votes |
def drawAxis(self): GL.glMatrixMode(GL.GL_PROJECTION) GL.glPushMatrix() GL.glLoadIdentity() width = float(self.width()) height = float(self.height()) frustrumx = 60*width/self.sizeHint().width() frustrumy = 60*height/self.sizeHint().height() GL.glFrustum(-frustrumx, frustrumx, frustrumy, -frustrumy, 200, 500) GL.glMatrixMode(GL.GL_MODELVIEW) GL.glPushMatrix() GL.glLoadIdentity() qobj = GLU.gluNewQuadric() GL.glTranslatef(1.7*frustrumx, 1.7*frustrumy, -400) GL.glRotatef(self.xRot / 16.0, 1.0, 0.0, 0.0) GL.glRotatef(self.yRot / 16.0, 0.0, 1.0, 0.0) GL.glRotatef(self.zRot / 16.0, 0.0, 0.0, 1.0) GL.glDisable(GL.GL_LIGHTING) GL.glBegin(GL.GL_LINES) self.qglColor(RED) GL.glVertex3f(-20.0,0,0) #X is inverted GL.glVertex3f(0.,0.,0.) self.qglColor(GREEN) GL.glVertex3f(0,20,0) GL.glVertex3f(0.,0.,0.) self.qglColor(BLUE) GL.glVertex3f(0,0,20) GL.glVertex3f(0.,0.,0.) GL.glEnd() GL.glEnable(GL.GL_LIGHTING) GL.glPopMatrix() GL.glMatrixMode(GL.GL_PROJECTION) GL.glPopMatrix() GL.glMatrixMode(GL.GL_MODELVIEW) #Scale for HeatMap