本文整理汇总了Python中Texture.Texture类的典型用法代码示例。如果您正苦于以下问题:Python Texture类的具体用法?Python Texture怎么用?Python Texture使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Texture类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, context, ImgData):
self.ImgData = None
self.texture = None
self.context = context
self.cache = None
self.filename = ImgData
# Detect the type of data passed in
if type(ImgData) == file:
self.ImgData = ImgData.read()
elif type(ImgData) == str:
self.texture = Texture(ImgData)
elif isinstance(ImgData, Image.Image): #stump: let a PIL image be passed in
self.texture = Texture()
self.texture.loadImage(ImgData)
# Make sure we have a valid texture
if not self.texture:
if type(ImgData) == str:
e = "Unable to load texture for %s." % ImgData
else:
e = "Unable to load texture for SVG file."
Log.error(e)
raise RuntimeError(e)
self.pixelSize = self.texture.pixelSize
self.position = [0.0,0.0]
self.scale = [1.0,1.0]
self.angle = 0
self.color = (1.0,1.0,1.0)
self.rect = (0,1,0,1)
self.shift = -.5
self.createArrays()
示例2: __init__
def __init__(self, context, svgData):
self.svgData = None
self.texture = None
self.context = context
self.cache = None
self.transform = SvgTransform()
# Detect the type of data passed in
if type(svgData) == file:
self.svgData = svgData.read()
elif type(svgData) == str:
bitmapFile = svgData.replace(".svg", ".png")
# Load PNG files directly
if svgData.endswith(".png"):
self.texture = Texture(svgData)
# Check whether we have a prerendered bitmap version of the SVG file
elif svgData.endswith(".svg") and os.path.exists(bitmapFile):
Log.debug("Loading cached bitmap '%s' instead of '%s'." % (bitmapFile, svgData))
self.texture = Texture(bitmapFile)
else:
if not haveAmanith:
e = "PyAmanith support is deprecated and you are trying to load an SVG file."
Log.error(e)
raise RuntimeError(e)
Log.debug("Loading SVG file '%s'." % (svgData))
self.svgData = open(svgData).read()
# Make sure we have a valid texture
if not self.texture:
if type(svgData) == str:
e = "Unable to load texture for %s." % svgData
else:
e = "Unable to load texture for SVG file."
Log.error(e)
raise RuntimeError(e)
示例3: __init__
def __init__(self, filename=None, fontsize=None, charset=DEFAULT_CHARSET):
assert type(fontsize)==int
if filename==None:
filename=DEFAULT_FONT[0]
if fontsize==None:
fontsize=DEFAULT_FONT[1]
# lets create the image for the texture from the font
self._font=lib.Font(filename, fontsize)
self._font.RenderSet(charset=charset) # make the glyph size details for each character
image,extents=self._font.Render()
#image=tools.fromSDLImageToPILImage(image)
#print "IMAGE",image
image.save("temp.png")
self.extents=extents
# call constructor
Texture.__init__(self,image=image,filename=filename)
# create the alpha numeric tex list
self.charset=charset
self._metrics=self._font.metrics
# in a font, the tex's store is a hash rather than a list (not frames)
self.texchars=dict([ (ch,Tex(self,*extents[ch])) for ch in charset])
self.texframes=[Tex(self,0.0,0.0,1.0,1.0)]
示例4: __init__
def __init__(self, context, ImgData):
self.ImgData = None
self.texture = None
self.context = context
self.cache = None
self.transform = SvgTransform()
self.filename = ImgData
self.triangVtx = np.zeros((4,2), dtype=float32)
self.textriangVtx = np.zeros((4,2), dtype=float32)
# Detect the type of data passed in
if type(ImgData) == file:
self.ImgData = ImgData.read()
elif type(ImgData) == str:
self.texture = Texture(ImgData)
# bitmapFile = ImgData.replace(".svg", ".png")
# # Load PNG files directly
# if ImgData.endswith(".png"):
# self.texture = Texture(ImgData)
# elif ImgData.endswith(".jpg"):
# self.texture = Texture(ImgData)
# elif ImgData.endswith(".jpeg"):
# self.texture = Texture(ImgData)
# Check whether we have a prerendered bitmap version of the SVG file
# elif ImgData.endswith(".svg") and os.path.exists(bitmapFile):
# Log.debug("Loading cached bitmap '%s' instead of '%s'." % (bitmapFile, ImgData))
# self.texture = Texture(bitmapFile)
# else:
# if not haveAmanith:
# e = "PyAmanith support is deprecated and you are trying to load an SVG file."
# Log.error(e)
# raise RuntimeError(e)
# Log.debug("Loading SVG file '%s'." % (ImgData))
# self.ImgData = open(ImgData).read()
elif isinstance(ImgData, Image.Image): #stump: let a PIL image be passed in
self.texture = Texture()
self.texture.loadImage(ImgData)
# Make sure we have a valid texture
if not self.texture:
if type(ImgData) == str:
e = "Unable to load texture for %s." % ImgData
else:
e = "Unable to load texture for SVG file."
Log.error(e)
raise RuntimeError(e)
示例5: loadTexture
def loadTexture(self, name, target, param = Texture.Parameters(), settings = Texture.Settings()):
if name in self.textures:
return self.textures[name]
if name not in self.images:
return None
image = self.images[name]
self.textures[name] = texture = Texture.create(name, image.data, image.width, image.height,
target, image.textureFormat, param, settings)
return texture
示例6: testRenderToTexture
def testRenderToTexture(self):
scale = 4
fullwidth, fullheight = 512, 512
width, height = int(fullwidth / scale), int(fullheight / scale)
t = Texture()
self.e.svg.setProjection((0, 0, fullwidth, fullheight))
glViewport(0, 0, width, height)
glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
self.svg.transform.translate(width * scale / 2, height * scale / 2)
self.svg.transform.rotate(3.141592)
self.svg.draw()
glViewport(0, 0, fullwidth, fullheight)
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
gluOrtho2D(0.0, 1.0, 0.0, 1.0)
glMatrixMode(GL_MODELVIEW)
glLoadIdentity()
t.bind()
glEnable(GL_TEXTURE_2D)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
glClear(GL_COLOR_BUFFER_BIT)
glColor3f(1.0, 1.0, 1.0)
glBegin(GL_TRIANGLE_STRIP)
glTexCoord2f(0.0, 0.0)
glVertex2f(0.0, 0.0)
glTexCoord2f(1.0, 0.0)
glVertex2f(1.0, 0.0)
glTexCoord2f(0.0, 1.0)
glVertex2f(0.0, 1.0)
glTexCoord2f(1.0, 1.0)
glVertex2f(1.0, 1.0)
glEnd()
self.e.video.flip()
import time
time.sleep(2)
示例7: __init__
def __init__(self, context, ImgData):
self.ImgData = None
self.texture = None
self.context = context
self.cache = None
self.filename = ImgData
# Detect the type of data passed in
if isinstance(ImgData, file):
self.ImgData = ImgData.read()
elif isinstance(ImgData, basestring):
self.texture = Texture(ImgData)
elif isinstance(ImgData, Image.Image): #stump: let a PIL image be passed in
self.texture = Texture()
self.texture.loadImage(ImgData)
# Make sure we have a valid texture
if not self.texture:
if isinstance(ImgData, basestring):
e = "Unable to load texture for %s." % ImgData
else:
e = "Unable to load texture for SVG file."
Log.error(e)
raise RuntimeError(e)
self.pixelSize = self.texture.pixelSize #the size of the image in pixels (from texture)
self.position = [0.0,0.0] #position of the image in the viewport
self.scale = [1.0,1.0] #percentage scaling
self.angle = 0 #angle of rotation (degrees)
self.color = (1.0,1.0,1.0,1.0) #glColor rgba
self.rect = (0,1,0,1) #texture mapping coordinates
self.shift = -.5 #horizontal alignment
self.vshift = -.5 #vertical alignment
self.path = self.texture.name #path of the image file
self.texArray = np.zeros((4,2), dtype=np.float32)
self.createTex()
示例8: __init__
def __init__(self, path, text="", size=32, shadow=True):
self.font = pygame.font.Font(os.path.join("..", "data", "fonts", path), int(size))
self.texture = Texture()
self.cache = Cache()
# attributes
self.scale = (1.0, 1.0) # image bounds (width, height)
self.position = (0, 0) # where in the window it should render
self.angle = 0 # angle which the image is drawn
self.color = (255, 255, 255, 255) # colour of the image
self.rect = (0.0, 0.0, 1.0, 1.0) # left, top, right, bottom, crops the texture
self.alignment = 1 # alignment of the text (left, center , right)
self.shadow = True # does the font project a shadow
self.text = None
self.setText(text) # it is not necessary to enter a string upon initialization,
示例9: cacheGlyph
def cacheGlyph(self, ch):
"""
Add character and size to glyph caches
@param ch: Character
@return: Glyph instance
"""
# Font size
self.glyphSizeCache[ch] = self.font.size(ch)
# Font texture
s = self.font.render(ch, True, (255, 255, 255))
t = Texture()
t.setFilter(GL_LINEAR, GL_LINEAR)
t.setRepeat(GL_CLAMP, GL_CLAMP)
t.loadSurface(s, alphaChannel = True)
del s
self.glyphCache[ch] = t
return t
示例10: __init__
def __init__(self, context, imgPath):
self.imgPath = None
self.texture = None
self.context = context
self.cache = None
self.transform = ImgTransform()
# Load PNG files directly
if imgPath.endswith(".png"):
self.texture = Texture(imgPath)
else:
e = "Unsupported Image format."
Log.error(e)
raise RuntimeError(e)
# Make sure we have a valid texture
if not self.texture:
e = "Unable to load texture for %s." % imgPath
Log.error(e)
raise RuntimeError(e)
示例11: getGlyph
def getGlyph(self, ch):
"""
Get the L{Texture} for a given character.
@param ch: Character
@return: L{Texture} instance
"""
try:
return self.glyphCache[ch]
except KeyError:
s = self.font.render(ch, True, (255, 255, 255))
"""
# Draw outlines
import Image, ImageFilter
srcImg = Image.fromstring("RGBA", s.get_size(), pygame.image.tostring(s, "RGBA"))
img = Image.fromstring("RGBA", s.get_size(), pygame.image.tostring(s, "RGBA"))
for y in xrange(img.size[1]):
for x in xrange(img.size[0]):
a = 0
ns = 3
n = 0
for ny in range(max(0, y - ns), min(img.size[1], y + ns)):
for nx in range(max(0, x - ns), min(img.size[0], x + ns)):
a += srcImg.getpixel((nx, ny))[3]
n += 1
if a and srcImg.getpixel((x, y))[3] == 0:
img.putpixel((x, y), (0, 0, 0, a / n))
s = pygame.image.fromstring(img.tostring(), s.get_size(), "RGBA")
"""
t = Texture()
t.setFilter(GL_LINEAR, GL_LINEAR)
t.setRepeat(GL_CLAMP, GL_CLAMP)
t.loadSurface(s, alphaChannel = True)
del s
self.glyphCache[ch] = t
return t
示例12: ImgDrawing
class ImgDrawing(object):
VTX_ARRAY = np.array([[0.0, 1.0], [1.0, 1.0], [1.0, 0.0], [0.0, 0.0]], dtype=np.float32) #hard-coded quad for drawing textures onto
def drawImage(image, scale = (1.0, -1.0), coord = (0, 0), rot = 0, \
color = (1,1,1,1), rect = (0,1,0,1), stretched = 0, fit = CENTER, \
alignment = CENTER, valignment = CENTER):
"""
Draws the image/surface to screen
"""
if not isinstance(image, ImgDrawing):
return False
image.setRect(rect)
image.setScale(scale[0], scale[1], stretched)
image.setPosition(coord[0], coord[1], fit)
image.setAlignment(alignment)
image.setVAlignment(valignment)
image.setAngle(rot)
image.setColor(color)
image.draw()
return True
def __init__(self, context, ImgData):
self.ImgData = None
self.texture = None
self.context = context
self.cache = None
self.filename = ImgData
# Detect the type of data passed in
if isinstance(ImgData, file):
self.ImgData = ImgData.read()
elif isinstance(ImgData, basestring):
self.texture = Texture(ImgData)
elif isinstance(ImgData, Image.Image): #stump: let a PIL image be passed in
self.texture = Texture()
self.texture.loadImage(ImgData)
# Make sure we have a valid texture
if not self.texture:
if isinstance(ImgData, basestring):
e = "Unable to load texture for %s." % ImgData
else:
e = "Unable to load texture for SVG file."
Log.error(e)
raise RuntimeError(e)
self.pixelSize = self.texture.pixelSize #the size of the image in pixels (from texture)
self.position = [0.0,0.0] #position of the image in the viewport
self.scale = [1.0,1.0] #percentage scaling
self.angle = 0 #angle of rotation (degrees)
self.color = (1.0,1.0,1.0,1.0) #glColor rgba
self.rect = (0,1,0,1) #texture mapping coordinates
self.shift = -.5 #horizontal alignment
self.vshift = -.5 #vertical alignment
self.path = self.texture.name #path of the image file
self.texArray = np.zeros((4,2), dtype=np.float32)
self.createTex()
def createTex(self):
tA = self.texArray
rect = self.rect
#topLeft, topRight, bottomRight, bottomLeft
tA[0,0] = rect[0]; tA[0,1] = rect[3]
tA[1,0] = rect[1]; tA[1,1] = rect[3]
tA[2,0] = rect[1]; tA[2,1] = rect[2]
tA[3,0] = rect[0]; tA[3,1] = rect[2]
def width1(self):
"""
@return the width of the texture in pixels
"""
width = self.pixelSize[0]
if width:
return width
else:
return 0
def height1(self):
"""
@return the height of the texture in pixels
"""
height = self.pixelSize[1]
if height is not None:
return height
else:
return 0
def widthf(self, pixelw):
"""
@param pixelw - a width in pixels
@return the scaled ratio of the pixelw divided by the pixel width of the texture
"""
width = self.pixelSize[0]
#.........这里部分代码省略.........
示例13: ImgDrawing
class ImgDrawing(object):
def __init__(self, context, ImgData):
self.ImgData = None
self.texture = None
self.context = context
self.cache = None
self.transform = SvgTransform()
self.filename = ImgData
self.triangVtx = np.zeros((4,2), dtype=float32)
self.textriangVtx = np.zeros((4,2), dtype=float32)
# Detect the type of data passed in
if type(ImgData) == file:
self.ImgData = ImgData.read()
elif type(ImgData) == str:
self.texture = Texture(ImgData)
# bitmapFile = ImgData.replace(".svg", ".png")
# # Load PNG files directly
# if ImgData.endswith(".png"):
# self.texture = Texture(ImgData)
# elif ImgData.endswith(".jpg"):
# self.texture = Texture(ImgData)
# elif ImgData.endswith(".jpeg"):
# self.texture = Texture(ImgData)
# Check whether we have a prerendered bitmap version of the SVG file
# elif ImgData.endswith(".svg") and os.path.exists(bitmapFile):
# Log.debug("Loading cached bitmap '%s' instead of '%s'." % (bitmapFile, ImgData))
# self.texture = Texture(bitmapFile)
# else:
# if not haveAmanith:
# e = "PyAmanith support is deprecated and you are trying to load an SVG file."
# Log.error(e)
# raise RuntimeError(e)
# Log.debug("Loading SVG file '%s'." % (ImgData))
# self.ImgData = open(ImgData).read()
elif isinstance(ImgData, Image.Image): #stump: let a PIL image be passed in
self.texture = Texture()
self.texture.loadImage(ImgData)
# Make sure we have a valid texture
if not self.texture:
if type(ImgData) == str:
e = "Unable to load texture for %s." % ImgData
else:
e = "Unable to load texture for SVG file."
Log.error(e)
raise RuntimeError(e)
def convertToTexture(self, width, height):
if self.texture:
return
e = "SVG drawing does not have a valid texture image."
Log.error(e)
raise RuntimeError(e)
def _getEffectiveTransform(self):
transform = SvgTransform(self.transform)
transform.transform(self.context.transform)
return transform
def width1(self):
width = self.texture.pixelSize[0]
if not width == None:
return width
else:
return 0
#myfingershurt:
def height1(self):
height = self.texture.pixelSize[1]
if not height == None:
return height
else:
return 0
def widthf(self, pixelw):
width = self.texture.pixelSize[0]
wfactor = pixelw/width
if not width == None:
return wfactor
else:
return 0
def draw(self, color = (1, 1, 1, 1), rect = (0,1,0,1), lOffset = 0.0, rOffset = 0.0):
glMatrixMode(GL_TEXTURE)
glPushMatrix()
glMatrixMode(GL_PROJECTION)
glPushMatrix()
self.context.setProjection()
glMatrixMode(GL_MODELVIEW)
glPushMatrix()
glLoadIdentity()
self._getEffectiveTransform().applyGL()
glScalef(self.texture.pixelSize[0], self.texture.pixelSize[1], 1)
glTranslatef(-.5, -.5, 0)
glColor4f(*color)
#.........这里部分代码省略.........
示例14: ImgDrawing
class ImgDrawing(object):
def __init__(self, context, ImgData):
self.ImgData = None
self.texture = None
self.context = context
self.cache = None
self.filename = ImgData
# Detect the type of data passed in
if type(ImgData) == file:
self.ImgData = ImgData.read()
elif type(ImgData) == str:
self.texture = Texture(ImgData)
elif isinstance(ImgData, Image.Image): #stump: let a PIL image be passed in
self.texture = Texture()
self.texture.loadImage(ImgData)
# Make sure we have a valid texture
if not self.texture:
if type(ImgData) == str:
e = "Unable to load texture for %s." % ImgData
else:
e = "Unable to load texture for SVG file."
Log.error(e)
raise RuntimeError(e)
self.pixelSize = self.texture.pixelSize #the size of the image in pixels (from texture)
self.position = [0.0,0.0] #position of the image in the viewport
self.scale = [1.0,1.0] #percentage scaling
self.angle = 0 #angle of rotation (degrees)
self.color = (1.0,1.0,1.0,1.0) #glColor rgba
self.rect = (0,1,0,1) #texture mapping coordinates
self.shift = -.5 #horizontal alignment
self.vshift = -.5 #vertical alignment
self.path = self.texture.name #path of the image file
self.createArrays()
def createArrays(self):
self.vtxArray = np.zeros((4,2), dtype=np.float32)
self.texArray = np.zeros((4,2), dtype=np.float32)
self.createVtx()
self.createTex()
def createVtx(self):
vA = self.vtxArray #short hand variable casting
#topLeft, topRight, bottomRight, bottomLeft
vA[0,0] = 0.0; vA[0,1] = 1.0
vA[1,0] = 1.0; vA[1,1] = 1.0
vA[2,0] = 1.0; vA[2,1] = 0.0
vA[3,0] = 0.0; vA[3,1] = 0.0
def createTex(self):
tA = self.texArray
rect = self.rect
#topLeft, topRight, bottomRight, bottomLeft
tA[0,0] = rect[0]; tA[0,1] = rect[3]
tA[1,0] = rect[1]; tA[1,1] = rect[3]
tA[2,0] = rect[1]; tA[2,1] = rect[2]
tA[3,0] = rect[0]; tA[3,1] = rect[2]
def width1(self):
width = self.pixelSize[0]
if width:
return width
else:
return 0
#myfingershurt:
def height1(self):
height = self.pixelSize[1]
if height:
return height
else:
return 0
def widthf(self, pixelw):
width = self.pixelSize[0]
if width:
wfactor = pixelw/width
return wfactor
else:
return 0
def setPosition(self, x, y):
self.position = [x,y]
def setScale(self, width, height):
self.scale = [width, height]
def setAngle(self, angle):
self.angle = angle
def setRect(self, rect):
if not rect == self.rect:
self.rect = rect
#.........这里部分代码省略.........
示例15: __init__
class ImgDrawing:
def __init__(self, context, ImgData):
self.ImgData = None
self.texture = None
self.context = context
self.cache = None
self.transform = SvgTransform()
# Detect the type of data passed in
if type(ImgData) == file:
self.ImgData = ImgData.read()
elif type(ImgData) == str:
bitmapFile = ImgData.replace(".svg", ".png")
# Load PNG files directly
if ImgData.endswith(".png"):
self.texture = Texture(ImgData)
elif ImgData.endswith(".jpg"):
self.texture = Texture(ImgData)
elif ImgData.endswith(".jpeg"):
self.texture = Texture(ImgData)
# Check whether we have a prerendered bitmap version of the SVG file
elif ImgData.endswith(".svg") and os.path.exists(bitmapFile):
Log.debug("Loading cached bitmap '%s' instead of '%s'." % (bitmapFile, ImgData))
self.texture = Texture(bitmapFile)
else:
if not haveAmanith:
e = "PyAmanith support is deprecated and you are trying to load an SVG file."
Log.error(e)
raise RuntimeError(e)
Log.debug("Loading SVG file '%s'." % (ImgData))
self.ImgData = open(ImgData).read()
elif isinstance(ImgData, Image.Image): #stump: let a PIL image be passed in
self.texture = Texture()
self.texture.loadImage(ImgData)
# Make sure we have a valid texture
if not self.texture:
if type(ImgData) == str:
e = "Unable to load texture for %s." % ImgData
else:
e = "Unable to load texture for SVG file."
Log.error(e)
raise RuntimeError(e)
def _cacheDrawing(self, drawBoard):
self.cache.beginCaching()
parser = sax.make_parser()
sax.parseString(self.ImgData, SvgHandler(drawBoard, self.cache))
self.cache.endCaching()
del self.ImgData
def convertToTexture(self, width, height):
if self.texture:
return
e = "SVG drawing does not have a valid texture image."
Log.error(e)
raise RuntimeError(e)
def _getEffectiveTransform(self):
transform = SvgTransform(self.transform)
transform.transform(self.context.transform)
return transform
def width1(self):
width = self.texture.pixelSize[0]
if not width == None:
return width
else:
return 0
#myfingershurt:
def height1(self):
height = self.texture.pixelSize[1]
if not height == None:
return height
else:
return 0
def widthf(self, pixelw):
width = self.texture.pixelSize[0]
wfactor = pixelw/width
if not width == None:
return wfactor
else:
return 0
def _render(self, transform):
glMatrixMode(GL_TEXTURE)
glPushMatrix()
glMatrixMode(GL_MODELVIEW)
glPushAttrib(GL_ENABLE_BIT | GL_TEXTURE_BIT | GL_STENCIL_BUFFER_BIT | GL_TRANSFORM_BIT | GL_COLOR_BUFFER_BIT | GL_POLYGON_BIT | GL_CURRENT_BIT | GL_DEPTH_BUFFER_BIT)
if not self.cache:
self.cache = SvgCache(self.context.drawBoard)
self._cacheDrawing(self.context.drawBoard)
self.cache.draw(transform)
glPopAttrib()
#.........这里部分代码省略.........