Text as Texture?

Panda3D Forum Index -> Scripting Issues Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
elena


Posts: 3

PostPosted: Sat Jun 21, 2008 6:19 pm    Post subject: Text as Texture? Reply with quote
Hi,

is it possible to use textnodes as textures for other pandanodes?
Can it be done that the text remains dynamic, i.e. allowing to change the text dynamically?

If so can anyone show how to do that?

Thanks a lot for your help,

-- Elena
treeform


Posts: 2027
Location: Seattle

PostPosted: Sun Jun 22, 2008 2:20 am    Post subject: Reply with quote
No text nodes don't modify the texture. All text nodes are collections of blocks that share set of textures. But what you can do is create an off screen buffer and camera. Have camera look at the text. When text changes you refresh the buffer.
_________________
Panda3d IRC irc://irc.freenode.net/panda3d | BUGs https://bugs.launchpad.net/panda3d
My MMORTS game: http://aff2aw.com
GitHub: http://github.com/treeform | Twitter: http://twitter.com/treeform
ynjh_jo


Posts: 1596
Location: Malang, Indonesia

PostPosted: Sun Jun 22, 2008 11:35 am    Post subject: Reply with quote
Code:
from pandac.PandaModules import NodePath,Texture,TextureStage,Mat4,Vec4
from direct.gui.OnscreenText import OnscreenText
from direct.task import Task
import direct.directbase.DirectStart
import random,string

def changeText(t):
    num=random.randint(1,7)
    text['text']='%s\n%s'%(num,random.choice(string.uppercase)*num)
    b3=text.getTightBounds()
    bHalf=(b3[0]+b3[1])*.5
    b=(b3[1]-b3[0])*.5
    ratio=b[0]/b[2]
    # max zoom along X if text is long,
    # else along Z if text is high
    b.setZ(b[0]) if ratio>1 else b.setX(b[2])
    textCam.setPos(bHalf) # put it exactly at text's center
    textCam.setScale(b[0],1,b[2]) # auto-zoom in to text
    buf.setActive(1) # enable RTT only when needed
    base.graphicsEngine.renderFrame() # render the text
    buf.setActive(0) # disable RTT
    return Task.again
taskMgr.doMethodLater(.5,changeText,'changeText')

textSG=NodePath('')
text=OnscreenText('X',parent=textSG,fg=(1,0,0,1),mayChange=1)

buf=base.win.makeTextureBuffer('textbuf',512,512)
buf.setActive(0) # enable it later, when needed
bufTex=buf.getTexture()
# set wrap modes to repeat so the text texture entirely covers smiley
bufTex.setWrapU(Texture.WMRepeat)
bufTex.setWrapV(Texture.WMRepeat)
# RTT camera
textCam=base.makeCamera2d(buf)
textCam.reparentTo(textSG)

smi=loader.loadModel('smiley')
smi.reparentTo(render)
ts=TextureStage('')
ts.setMode(TextureStage.MDecal)
ts.setSort(1) # to win over the default texture stage (sort=0)
smi.setTexture(ts,bufTex)
smi.setTexScale(ts,7,7)

camera.setPos(4.64, -4.32, 3.30)
camera.setHpr(47.05, -27.49, 25.59)
camera.lookAt(render)
mat=Mat4(camera.getMat())
mat.invertInPlace()
base.mouseInterfaceNode.setMat(mat)

base.bufferViewer.toggleEnable()
run()

_________________
http://ynjh.panda3dprojects.com | http://ynjh.p3dp.com
Intel P4Prescott 2.8GHz HT | Elixir 1.5GB | ATI HD4670 1GB GDDR3
elena


Posts: 3

PostPosted: Sat Jun 28, 2008 5:33 pm    Post subject: Reply with quote
Hi ynjh_jo and treeform,

thanks for your replies and especially ynjh_jo for your code.
I will go testing and trying to understand it.

The reason for my question is: I am looking for an easy way of transferring text to arbitrary surface forms (spheres, cylinders, squares ...) I thought if texts can be used as textures I simply projekt them onto these forms.
(Thats why I miss the modules ProjectionScreen or NonLinearImager in the current panda3D release, see my below post)

Does this make sense or is there a more easy way?

Thanks a lot ,

Elena
ynjh_jo


Posts: 1596
Location: Malang, Indonesia

PostPosted: Sun Jun 29, 2008 12:23 am    Post subject: Reply with quote
Easy way of what ? Converting text to texture ? RTT is the only way. Once you get it as a texture, you can project it anyway you like, follow the manual. You don't need projectionscreen for that.
_________________
http://ynjh.panda3dprojects.com | http://ynjh.p3dp.com
Intel P4Prescott 2.8GHz HT | Elixir 1.5GB | ATI HD4670 1GB GDDR3
Display posts from previous:   
Post new topic   Reply to topic    Panda3D Forum Index -> Scripting Issues All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group