本文整理汇总了Python中opengltk.OpenGL.GL类的典型用法代码示例。如果您正苦于以下问题:Python GL类的具体用法?Python GL怎么用?Python GL使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了GL类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_0031
def test_0031(self ):
# example we test glMultMatrixf
import Tkinter
root = Tkinter.Tk()
vi = OGLTkWidget(root)
id = Numeric.array([1.,0.,0.,0.,
0.,1.,0.,0.,
0.,0.,1.,0.,
0.,0.,0.,1.], "d")
from opengltk.extent import _gllib as gllib
#GL.glMultMatrixf(id)
try:
gllib.cvar.checkArgumentsInCWrapper = 0
GL.glMultMatrixf(id)
# calling with bad argument
gllib.cvar.checkArgumentsInCWrapper = 1
#import numpy.oldnumeric as Numeric
id = Numeric.identity(4).astype('d')
try:
GL.glMultMatrixf(id)
raise RuntimeError('failed to catch type error in wrapper')
except TypeError:
print 'Type Error caught succefully in wrapper'
except ImportError:
pass
root.after(1000, root.quit )
root.mainloop()
root.destroy()
示例2: RedoDisplayList
def RedoDisplayList(self):
#print "Common2d3dObject.RedoDisplayList", self
if hasattr(self, 'dpyList') and self.dpyList is not None:
lNewList = self.dpyList[0]
else:
lNewList = GL.glGenLists(1)
self.viewer.deleteOpenglList()
#lNewList = self.newList
lContext = self.viewer.currentCamera.tk.call(self.viewer.currentCamera._w, 'contexttag')
#print "lNewList Common2d3dObject.RedoDisplayList", lNewList, lContext, self.name
self.dpyList = ( lNewList,
self.viewer.currentCamera.tk.call(self.viewer.currentCamera._w, 'contexttag')
)
GL.glNewList(self.dpyList[0], GL.GL_COMPILE)
#print '+%d'%self.dpyList[0], lContext, "glNewList Common2d3dObject"
if hasattr(self, 'Draw'):
status = self.Draw()
else:
status = 0
#print '*%d'%GL.glGetIntegerv(GL.GL_LIST_INDEX), "glEndList Common2d3dObject"
GL.glEndList()
if status == 0:
self.deleteOpenglList()
示例3: DrawArrays
def DrawArrays( mode, count, first=0):
"""glDrawArrays with default args
model - GLenum
count - GLsizei
first - GLint
"""
GL.glDrawArrays( mode, first, count)
示例4: _Enable
def _Enable(self, side):
"""Activate the clipping plane"""
eqnt = self.eqn * side
#eqnt[3] = 0.0 - eqnt[3]
GL.glClipPlane(self.clipPlaneNames[self.num], eqnt)
GL.glEnable(self.clipPlaneNames[self.num])
示例5: display
def display(self):
GL.glClear( GL.GL_COLOR_BUFFER_BIT)
GL.glColor3f( 1.0, 1.0, 1.0)
GL.glLoadIdentity() # clear the matrix
# viewing transformation
GLU.gluLookAt( 0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0)
GL.glScalef( 1.0, 2.0, 1.0) # modeling transformation
GLUT.glutWireCube( 1.0)
GL.glFlush()
示例6: Configure
def Configure(self, *dummy):
"""guillaume: set the opengl viewport"""
# unbind <configure, because changing size of togl widget creates such
# an event, hence causing an endless loop
self.unbind('<Configure>')
self.configure(width=self.width, height=self.height)
self.bind('<Configure>', self.Configure)
GL.glViewport(0, 0, self.width, self.height)
示例7: initProjection
def initProjection(self):
if self.imarray is None:
return
self.tk.call(self._w, 'makecurrent')
GL.glViewport(0, 0, self.width, self.height)
GL.glMatrixMode(GL.GL_PROJECTION)
GL.glLoadIdentity()
GL.glOrtho(0, float(self.width), 0, float(self.height), -1.0, 1.0)
GL.glMatrixMode(GL.GL_MODELVIEW)
示例8: DisplayFunction
def DisplayFunction(self):
""" display function. may be re-implemented by subclass
"""
#print "Common2d3dObject.DisplayFunction", self
if self.dpyList is not None:
currentcontext = self.viewer.currentCamera.tk.call(self.viewer.currentCamera._w, 'contexttag')
if currentcontext != self.dpyList[1]:
warnings.warn("""DisplayFunction failed because the current context is the wrong one""")
#print "currentcontext != self.dpyList[1]", currentcontext, self.dpyList[1]
else:
#print '#%d'%self.dpyList[0], currentcontext, "glCallList Common2d3d"
GL.glCallList(self.dpyList[0])
示例9: trRasterPos3f
def trRasterPos3f(self, x, y, z):
"""
Replacement for glRastePos3f() which avoids the problem with invalid
raster pos.
"""
if self.CurrentTile<0:
# not doing tile rendering right now. Let OpenGL do this.
GL.glRasterPos3f(float(x), float(y), float(z))
else:
# Get modelview, projection and viewport
modelview = GL.glGetDoublev(GL.GL_MODELVIEW_MATRIX)
proj = GL.glGetDoublev(GL.GL_PROJECTION_MATRIX)
viewport = [0, 0, self.CurrentTileWidth, self.CurrentTileHeight]
示例10: drawpolygons
def drawpolygons(self):
g = self.geom
vertices = g.getVertices()
faces = g.getFaces()
normals = g.getFNormals()
GL.glDisable(GL.GL_CULL_FACE)
for i,f in enumerate(faces):
GL.glBegin(GL.GL_POLYGON)
GL.glNormal3fv(normals[i])
for vi in f:
GL.glVertex3fv(vertices[vi])
GL.glEnd()
i+=1
示例11: drawOneLine
def drawOneLine(self, x1, y1, x2, y2):
GL.glBegin( GL.GL_LINES)
try:
GL.glVertex2f( x1, y1)
GL.glVertex2f( x2, y2)
finally:
GL.glEnd()
示例12: doloop
def doloop(self, name, shademodel, cbdisplay, cbreshape, cbkeyboard):
GLUT.glutInit( sys.argv)
GLUT.glutInitDisplayMode( GLUT.GLUT_SINGLE | GLUT.GLUT_RGB)
GLUT.glutInitWindowSize( 500, 500)
GLUT.glutInitWindowPosition( 100, 100)
GLUT.glutCreateWindow( name)
GL.glClearColor( 0.0, 0.0, 0.0, 0.0)
GL.glShadeModel( GL.GL_FLAT)
GLUT.glutDisplayFunc( cbdisplay)
GLUT.glutReshapeFunc( cbreshape)
GLUT.glutKeyboardFunc( cbkeyboard)
GLUT.glutTimerFunc(1000, self.exitloop, 0)
GLUT.glutMainLoop()
示例13: glMaterialWithCheck
def glMaterialWithCheck(face, property, material, eps=0.001, check=True):
"""
Only calls glMaterial if the material is different from he current value
face can be GL_FRONT or GL_BACK
propety can be GL_AMBIENT, GL_DIFFUSE, GL_SPECULAR or GL_EMISSION
material is a 3-sequence RGBA, Alpha values are only test for ambient and
diffuse properties
"""
global materialMemory
#print 'glMaterialWithCheck', property, material
if face==GL.GL_FRONT_AND_BACK:
face=GL.GL_FRONT
if property==GL.GL_SHININESS:
matMem = materialMemory[face]
if not check or fabs(matMem[4]-material) > eps:
matMem[4] = material
#GL.glMaterialfv( face, property, matMem[4] )
GL.glMaterialf( face, property, float(matMem[4]) )
else:
if not material.flags.contiguous:
material = Numeric.array(material,copy=1)
propNum = viewerConst.propNum[property]
matMem = materialMemory[face][propNum]
## print 'DIFFERENCE'
## print id(matMem), id(materialMemory[face][propNum])
## print matMem
## print material
## print fabs(matMem[0]-material[0]) > eps
## print fabs(matMem[1]-material[1]) > eps
## print fabs(matMem[2]-material[2]) > eps
## print (fabs(matMem[3]-material[3]) > eps and propNum in (0,1))
if check:
newCol = fabs(matMem[0]-material[0]) > eps or \
fabs(matMem[1]-material[1]) > eps or \
fabs(matMem[2]-material[2]) > eps or \
(fabs(matMem[3]-material[3]) > eps and propNum in (0,1))
else:
newCol = True
if newCol:
#GL.glMaterialfv( face, property, material.tolist() )
#print 'SETTING'
gllib.glMaterialfv( face, property, material)
matMem[0] = material[0]
matMem[1] = material[1]
matMem[2] = material[2]
matMem[3] = material[3]
示例14: deleteTemplate
def deleteTemplate(self):
#print "Ellipsoids.deleteTemplate"
# it is asumed the right OpenGL context is active
assert self.templateDSPL is not None
currentcontext = self.viewer.currentCamera.tk.call(self.viewer.currentCamera._w, 'contexttag')
if currentcontext != self.templateDSPL[1]:
import traceback;traceback.print_stack()
warnings.warn('deleteTemplate failed because the current context is the wrong one')
print "currentcontext != self.templateDSPL[1]", currentcontext, self.templateDSPL[1]
else:
#print '-%d'%self.templateDSPL[0], currentcontext, "glDeleteLists Ellipsoids"
#print '-%d'%(self.templateDSPL[0]+1), currentcontext, "glDeleteLists Ellipsoids"
#print '-%d'%(self.templateDSPL[0]+2), currentcontext, "glDeleteLists Ellipsoids"
GL.glDeleteLists(self.templateDSPL[0], 3)
self.templateDSPL = None
示例15: clearCache_cb
def clearCache_cb(self):
#print "clearing cache: "
vi = self.vf.GUI.VIEWER
currentcontext = vi.currentCamera.tk.call(vi.currentCamera._w, 'getcurrentcontext')
for dl in self.dpyLists.keys():
if self.dpyLists[dl]is not None:
if currentcontext != self.dpyLists[dl][1]:
print "currentcontext != self.dpyLists[%d][1]" %(dl,), currentcontext, self.dpyLists[dl][1]
c = vi.currentCamera
c.tk.call(c._w, 'makecurrent')
#import pdb; pdb.set_trace()
#print "glDeleteLists TrajPlayerCached", self.dpyLists[dl][0]
GL.glDeleteLists(self.dpyLists[dl][0], 1)
self.dpyLists.pop(dl)