def drawSelf(self): self._tex.bind() with gl.glPushMatrix(GL.GL_MODELVIEW): GL.glLoadIdentity() yaw, pitch = self.sceneNode.yawPitch GL.glTranslatef(0.9, 0.1, 0.0) # position on lower right corner GL.glRotatef(pitch, 1., 0., 0.) # Tilt upward a bit if the view is pitched GL.glRotatef(yaw - 180, 0., 0., 1.) # adjust to north GL.glColor4f(1., 1., 1., 1.) with gl.glPushAttrib(GL.GL_ENABLE_BIT): GL.glDisable(GL.GL_DEPTH_TEST) with gl.glEnableClientState(GL.GL_TEXTURE_COORD_ARRAY): GL.glVertexPointer(2, GL.GL_FLOAT, 0, makeQuad(-.1, -.1, 0.2, 0.2)) GL.glTexCoordPointer(2, GL.GL_FLOAT, 0, makeQuad(0, 0, 1, 1)) with gl.glEnable(GL.GL_BLEND, GL.GL_TEXTURE_2D): GL.glDrawArrays(GL.GL_QUADS, 0, 4)
def drawFace(box, face, elementType=GL.GL_QUADS): x, y, z, = box.origin x2, y2, z2 = box.maximum if face == faces.FaceXDecreasing: faceVertices = numpy.array( (x, y2, z2, x, y2, z, x, y, z, x, y, z2, ), dtype='f4') elif face == faces.FaceXIncreasing: faceVertices = numpy.array( (x2, y, z2, x2, y, z, x2, y2, z, x2, y2, z2, ), dtype='f4') elif face == faces.FaceYDecreasing: faceVertices = numpy.array( (x2, y, z2, x, y, z2, x, y, z, x2, y, z, ), dtype='f4') elif face == faces.FaceYIncreasing: faceVertices = numpy.array( (x2, y2, z, x, y2, z, x, y2, z2, x2, y2, z2, ), dtype='f4') elif face == faces.FaceZDecreasing: faceVertices = numpy.array( (x, y, z, x, y2, z, x2, y2, z, x2, y, z, ), dtype='f4') elif face == faces.FaceZIncreasing: faceVertices = numpy.array( (x2, y, z2, x2, y2, z2, x, y2, z2, x, y, z2, ), dtype='f4') else: raise ValueError("Unknown face %s" % face) faceVertices.shape = (4, 3) dim = face >> 1 dims = [0, 1, 2] dims.remove(dim) texVertices = numpy.array( faceVertices[:, dims], dtype='f4' ).flatten() faceVertices.shape = (12,) texVertices *= 16 with gl.glEnableClientState(GL.GL_TEXTURE_COORD_ARRAY): GL.glVertexPointer(3, GL.GL_FLOAT, 0, faceVertices) GL.glTexCoordPointer(2, GL.GL_FLOAT, 0, texVertices) with gl.glPushAttrib(GL.GL_POLYGON_BIT): GL.glEnable(GL.GL_POLYGON_OFFSET_FILL) GL.glEnable(GL.GL_POLYGON_OFFSET_LINE) if elementType is GL.GL_LINE_STRIP: indexes = numpy.array((0, 1, 2, 3, 0), dtype='uint32') GL.glDrawElements(elementType, 5, GL.GL_UNSIGNED_INT, indexes) else: GL.glDrawArrays(elementType, 0, 4)
def drawFace(box, face, elementType=GL.GL_QUADS): x, y, z, = box.origin x2, y2, z2 = box.maximum if face == faces.FaceXDecreasing: faceVertices = numpy.array(( x, y2, z2, x, y2, z, x, y, z, x, y, z2, ), dtype='f4') elif face == faces.FaceXIncreasing: faceVertices = numpy.array(( x2, y, z2, x2, y, z, x2, y2, z, x2, y2, z2, ), dtype='f4') elif face == faces.FaceYDecreasing: faceVertices = numpy.array(( x2, y, z2, x, y, z2, x, y, z, x2, y, z, ), dtype='f4') elif face == faces.FaceYIncreasing: faceVertices = numpy.array(( x2, y2, z, x, y2, z, x, y2, z2, x2, y2, z2, ), dtype='f4') elif face == faces.FaceZDecreasing: faceVertices = numpy.array(( x, y, z, x, y2, z, x2, y2, z, x2, y, z, ), dtype='f4') elif face == faces.FaceZIncreasing: faceVertices = numpy.array(( x2, y, z2, x2, y2, z2, x, y2, z2, x, y, z2, ), dtype='f4') else: raise ValueError("Unknown face %s" % face) faceVertices.shape = (4, 3) dim = face >> 1 dims = [0, 1, 2] dims.remove(dim) texVertices = numpy.array(faceVertices[:, dims], dtype='f4').flatten() faceVertices.shape = (12, ) texVertices *= 16 with gl.glEnableClientState(GL.GL_TEXTURE_COORD_ARRAY): GL.glVertexPointer(3, GL.GL_FLOAT, 0, faceVertices) GL.glTexCoordPointer(2, GL.GL_FLOAT, 0, texVertices) with gl.glPushAttrib(GL.GL_POLYGON_BIT): GL.glEnable(GL.GL_POLYGON_OFFSET_FILL) GL.glEnable(GL.GL_POLYGON_OFFSET_LINE) if elementType is GL.GL_LINE_STRIP: indexes = numpy.array((0, 1, 2, 3, 0), dtype='uint32') GL.glDrawElements(elementType, 5, GL.GL_UNSIGNED_INT, indexes) else: GL.glDrawArrays(elementType, 0, 4)