本文整理匯總了Python中texture.Texture.loadImage方法的典型用法代碼示例。如果您正苦於以下問題:Python Texture.loadImage方法的具體用法?Python Texture.loadImage怎麽用?Python Texture.loadImage使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類texture.Texture
的用法示例。
在下文中一共展示了Texture.loadImage方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: renderSkin
# 需要導入模塊: from texture import Texture [as 別名]
# 或者: from texture.Texture import loadImage [as 別名]
def renderSkin(dst, vertsPerPrimitive, verts, index = None, objectMatrix = None,
texture = None, UVs = None, textureMatrix = None,
color = None, clearColor = None):
if isinstance(dst, Texture):
glBindTexture(GL_TEXTURE_2D, dst.textureId)
elif isinstance(dst, Image):
dst = Texture(image = dst)
elif isinstance(dst, tuple):
dimensions = dst
dst = Texture(size = dimensions)
if dst.width < dimensions[0] or dst.height < dimensions[1]:
raise RuntimeError('Could not allocate render texture with dimensions: %s' % str(dst))
else:
raise RuntimeError('Unsupported destination: %r' % dst)
width, height = dst.width, dst.height
framebuffer = glGenFramebuffers(1)
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer)
glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, dst.textureId, 0)
glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, dst.textureId, 0)
if clearColor is not None:
glClearColor(clearColor[0], clearColor[1], clearColor[2], clearColor[3])
glClear(GL_COLOR_BUFFER_BIT)
glVertexPointer(verts.shape[-1], GL_FLOAT, 0, verts)
if texture is not None and UVs is not None:
if isinstance(texture, Image):
tex = Texture()
tex.loadImage(texture)
texture = tex
if isinstance(texture, Texture):
texture = texture.textureId
glEnable(GL_TEXTURE_2D)
glEnableClientState(GL_TEXTURE_COORD_ARRAY)
glBindTexture(GL_TEXTURE_2D, texture)
glTexCoordPointer(UVs.shape[-1], GL_FLOAT, 0, UVs)
if color is not None:
glColorPointer(color.shape[-1], GL_UNSIGNED_BYTE, 0, color)
glEnableClientState(GL_COLOR_ARRAY)
else:
glDisableClientState(GL_COLOR_ARRAY)
glColor4f(1, 1, 1, 1)
glDisableClientState(GL_NORMAL_ARRAY)
glDisable(GL_LIGHTING)
glDepthMask(GL_FALSE)
glDisable(GL_DEPTH_TEST)
# glDisable(GL_CULL_FACE)
glPushAttrib(GL_VIEWPORT_BIT)
glViewport(0, 0, width, height)
glMatrixMode(GL_MODELVIEW)
glPushMatrix()
if objectMatrix is not None:
glLoadTransposeMatrixd(objectMatrix)
else:
glLoadIdentity()
glMatrixMode(GL_PROJECTION)
glPushMatrix()
glLoadIdentity()
glOrtho(0, 1, 0, 1, -100, 100)
if textureMatrix is not None:
glMatrixMode(GL_TEXTURE)
glPushMatrix()
glLoadTransposeMatrixd(textureMatrix)
if index is not None:
glDrawElements(g_primitiveMap[vertsPerPrimitive-1], index.size, GL_UNSIGNED_INT, index)
else:
glDrawArrays(g_primitiveMap[vertsPerPrimitive-1], 0, verts[:,:,0].size)
if textureMatrix is not None:
glMatrixMode(GL_TEXTURE)
glPopMatrix()
glMatrixMode(GL_PROJECTION)
glPopMatrix()
glMatrixMode(GL_MODELVIEW)
glPopMatrix()
glPopAttrib()
glEnable(GL_DEPTH_TEST)
glDepthMask(GL_TRUE)
glEnable(GL_LIGHTING)
glEnableClientState(GL_NORMAL_ARRAY)
glEnableClientState(GL_COLOR_ARRAY)
#.........這裏部分代碼省略.........