Jzone
23-04-2009 21:38:04
I'm currently playing around with the python implementation of WriteToTexture, and I'm having a couple problems.
I have a handful of differently colored textures for the same mesh. These colors can change throughout the program, and will be regularly written to with some information. This... somewhat works. The problem is that when a box changes to a differently colored texture, not all of the previous texture is removed. (You can see this in the image below)

The top bar shows the green of the previous texture on the top(not seen) and bottom, while the bottom bar is displayed properly.
The second problem is that if I start the text with a " " (space), the leading space(s) are stripped, forcing the text all the way left. This is problematic because I do not want to have to manually position the text. (what if I want to change fonts or font sizes later?)
I have been looking at this code for several hours now and I'm getting nowhere fast. Any help would be greatly appreciated.
Relevant code for texture changes:
Code for WriteToTexture can be found at the link at the beginning of this post.
Update:
I have found a (temporary at the very least) solution to the problem of the colors not being overwritten properly. I don't like this solution, as I presume it's using more memory and processor cycles than it needs to. But unless someone can give me some insight, it will have to do for now.
I have a handful of differently colored textures for the same mesh. These colors can change throughout the program, and will be regularly written to with some information. This... somewhat works. The problem is that when a box changes to a differently colored texture, not all of the previous texture is removed. (You can see this in the image below)
The top bar shows the green of the previous texture on the top(not seen) and bottom, while the bottom bar is displayed properly.
The second problem is that if I start the text with a " " (space), the leading space(s) are stripped, forcing the text all the way left. This is problematic because I do not want to have to manually position the text. (what if I want to change fonts or font sizes later?)
I have been looking at this code for several hours now and I'm getting nowhere fast. Any help would be greatly appreciated.
Relevant code for texture changes:
## Some variables we will use
strkey = 'uniqueIdentifier'
box_text = ' sample text '
# Get the original untouched texture for the color we need
origTexture = ogre.TextureManager.getSingleton().getByName(
"infobar_texture_%s.jpg" % self.colors[toUpdate[key]['tid']])
## If the entity already exists, we want to update it to the proper texture.
if self.sceneManager.hasEntity(strkey):
# If we had made the entity invisible, make it visible again.
if not self.sceneManager.getEntity(strkey).getVisible():
self.sceneManager.getEntity(strkey).setVisible(True)
# Get the node for our entity, and reposition it.
node = self.sceneManager.getSceneNode(strkey)
offset = ((toUpdate[key]['pos'] - 1) * 18)
node.setPosition(ogre.Vector3(0, offset, 0))
# Get our entities current texture, and blit with the color we want
# This should be clearing all text
# and replacing the old color completey --This is not working
texture = ogre.TextureManager.getSingleton().getByName(strkey)
texture.getBuffer().blit(origTexture.getBuffer())
# Finally, write onto the texture --Mostly works, lose leading spaces.
WriteToTexture(box_text, texture, ogre.Box(30,47,500,100),
self.font, ogre.ColourValue(1.0,1.0,1.0,1.0), 'l')
Code for WriteToTexture can be found at the link at the beginning of this post.
Update:
I have found a (temporary at the very least) solution to the problem of the colors not being overwritten properly. I don't like this solution, as I presume it's using more memory and processor cycles than it needs to. But unless someone can give me some insight, it will have to do for now.
## Some variables we will use
strkey = 'uniqueIdentifier'
box_text = ' sample text '
# Get the original untouched texture for the color we need
origTexture = ogre.TextureManager.getSingleton().getByName(
"infobar_texture_%s.jpg" % self.colors[toUpdate[key]['tid']])
## If the entity already exists, we want to update it to the proper texture.
if self.sceneManager.hasEntity(strkey):
# Part1 of temp solution. Create a new texture.
temptxr = ogre.TextureManager.getSingleton().createManual(strkey,"General",
ogre.TEX_TYPE_2D, 512, 512, ogre.MIP_UNLIMITED ,
ogre.PF_X8R8G8B8, ogre.TU_STATIC|ogre.TU_AUTOMIPMAP)
temptxr.getBuffer().blit(origTexture.getBuffer())
# If we had made the entity invisible, make it visible again.
if not self.sceneManager.getEntity(strkey).getVisible():
self.sceneManager.getEntity(strkey).setVisible(True)
# Get the node for our entity, and reposition it.
node = self.sceneManager.getSceneNode(strkey)
offset = ((toUpdate[key]['pos'] - 1) * 18)
node.setPosition(ogre.Vector3(0, offset, 0))
# Get our entities current texture, and blit with the color we want
# This should be clearing all text
# and replacing the old color completey --This is not working
texture = ogre.TextureManager.getSingleton().getByName(strkey)
texture.getBuffer().blit(origTexture.getBuffer())
# Finally, write onto the texture --Mostly works, lose leading spaces.
WriteToTexture(box_text, texture, ogre.Box(30,47,500,100),
self.font, ogre.ColourValue(1.0,1.0,1.0,1.0), 'l',
tBuff=temptxr.getBuffer()) # slight modification here
# Replace the texture with the written temp texture, and unload our temp txr.
texture.getBuffer().blit(temptxr.getBuffer())
temptxr.unload())