File:Text attrib.png

Don't mind the mess!

We're currently in the process of migrating the Panda3D Manual to a new service. This is a temporary layout in the meantime.

Top
Python C++
Text_attrib.png(375 × 37 pixels, file size: 8 KB, MIME type: image/png)

This image was generated with the following program:

from direct.directbase.DirectStart import *
from pandac.PandaModules import *

# How much bigger to render the images onscreen, for antialiasing?
renderFactor = 5

# How much to scale the resulting image from what I originally had in
# mind?
outputFactor = 1.5

def saveImage(basename, color = 0):
    base.graphicsEngine.renderFrame()
    image = PNMImage()
    base.win.getScreenshot(image)
    if color:
        image.setColorType(PNMImage.CTColor)
    else:
        image.setColorType(PNMImage.CTGrayscale)

    filename = Filename('%s.png' % (basename))

    scale = float(outputFactor) / float(renderFactor)

    if scale != 1:
        reduced = PNMImage(int(image.getXSize() * scale),
                           int(image.getYSize() * scale),
                           image.getNumChannels())
        reduced.gaussianFilterFrom(0.5, image)
        reduced.write(filename)
    else:
        image.write(filename)
    print "wrote %s" % (filename.getFullpath())

base.setBackgroundColor(1, 1, 1, 1)
base.setFrameRateMeter(0)

wp = WindowProperties()
wp.setSize(250 * renderFactor, 25 * renderFactor)
base.win.requestProperties(wp)
base.aspect2d.setScale(1.0, 1.0, 250./25.)
base.graphicsEngine.openWindows()

text = TextNode('node name')
textNodePath = aspect2d.attachNewNode(text)
text.setTextColor(0, 0, 0, 1)
textNodePath.setPos(-.95, 0, -0.02)
textNodePath.setScale(0.095)

tpRed = TextProperties()
tpRed.setTextColor(1, 0, 0, 1)
tpSlant = TextProperties()
tpSlant.setSlant(0.3)
tpRoman = TextProperties()
cmr12 = loader.loadFont('cmr12.egg')
tpRoman.setFont(cmr12)

tpMgr = TextPropertiesManager.getGlobalPtr()
tpMgr.setProperties("red", tpRed)
tpMgr.setProperties("slant", tpSlant)
tpMgr.setProperties("roman", tpRoman)

text.setText("Every day in \1slant\1every way\2 I'm \1red\1getting \1roman\1better \1slant\1and\2 better.\2\2")
saveImage('Text_attrib', color = 1)

File history

Click on a date/time to view the file as it appeared at that time.

Date/TimeThumbnailDimensionsUserComment
current09:03, 13 January 2006Thumbnail for version as of 09:03, 13 January 2006375 × 37 (8 KB)Drwr (Talk | contribs)

The following page links to this file:

Top