Hi everybody,
I’ve been struggling with some transparency issues and I was wondering if anybody could shed some light on the way forward.
The code is reported below, and it does pretty much what you’d expect: it displayes the image “aTexture.png”, inclusive of its transparencies. The PNG in question is actually a 256x256 image done with Inkscape: a white frame 8 pixels thick with rounded corners, encasing an empty, black area. Notice that the image is not just b&w: the borders are antialiased as the shape is rasterized before it is saved into a PNG file.
The question is: what is the proper way to give a color to this otherwise white frame on the default grey of Panda’s background? I tried with the two commented lines at the end of the code: the result with each is identical and is largely correct, but has some unsightly dark/black pixels in the antialiased area of the rounded corners, as if the alpha-based blending of the color of the frame and that of the background behind it dind’t quite work. Strangely enough, while using this method to tint the frame in colors such as r, g, b produces the problem, choosing secondary ones (c, m, y) or white seems to render the problem imperceptible.
Now I’m not quite sure what to think. Am I choosing a bad method to tinge this texture or am I producing or using the source image incorrectly?
Any idea would be much appreciated.
Manu
from direct.directbase.DirectStart import *
from direct.gui.DirectGui import *
from pandac.PandaModules import *
# resizing the image so that it should be pixel-perfect on screen
imgWidth, imgHeight = 256, 256
winWidth = base.win.getXSize()
winHeight = base.win.getYSize()
aspectRatio = base.getAspectRatio()
glUnitsImageHeight = 2.0 * imgHeight / winHeight
glUnitsImageWidth = 2.0 * imgWidth / winWidth * aspectRatio
# placing the texture on the card: notice that the same
# source PNG is used for both the color and the alpha channels.
aTexture = loader.loadTexture("aTexture.png", "aTexture.png")
ts = TextureStage('ts')
cm = CardMaker('card')
aCard = render.attachNewNode(cm.generate())
aCard.setTexture(ts, aTexture)
df = DirectFrame()
df.setTransparency(TransparencyAttrib.MAlpha)
df["geom"] = aCard
df["geom_scale"] = (glUnitsImageWidth, 1.0, glUnitsImageHeight)
#aCard.setColor(VBase4(0,0,1,1))
#df.setColor(VBase4(1,0,0,1))
run()
I’ve saved in manu3d.com/tmp/ the image mentioned in the script above and an image highlighting the dark-rim problem.