I’m having a little trouble getting DirectWaitBar to display properly when it’s parented to a 3d object. The odd thing is, sometimes it works fine, and others it just freaks out.
Most of the time, all I see is a grey bar hanging above my character’s heads. Occasionally the code will somewhat work right and I’ll get red and grey health bar, but the text disappears behind the wait bar. The bar works fine when parented to render2d, but as I want it to follow my character around…
Anyone had this problem or a similar one and come up with a workaround?
And loaded more or less under the same conditions:
[/img]
The exact same code that runs the health bar in the upper left hand portion of the screen creates the health bar over the character. The one difference being the health bar over the character is parented to the character. I’ve tried bar.setHpr(180,0,0) but that didn’t seem to make a difference. I’ve also tried to mess with the scale and I can’t get a response.
K, I’ve turned the billboard effect off and from what I can tell it’s just some Z-Fighting. I can’t seem to scale the bar large enough to get it to stop though. Still working on the problem and still accepting solutions.
You’re getting what’s called Z-fighting, with two exactly coplanar polygons in 3-D space. This happens because neither polygon is in front of the other, so it’s random which one you see. It doesn’t happen in the 2-d scene, because we don’t need to perform depth testing there.
To solve it, try this:
bar.setBin('fixed', 0)
bar.setDepthWrite(False)
The first line moves the bar into the ‘fixed’ bin, so it is drawn last in the scene; the second line turns off depth writing, so it won’t interfere with itself. (We have to move it last in the scene when we turn off depth writing, or it might end up obscured by things that should be behind it.)
The text color is black by default for a DirectWaitBar. You can set it to the color you like with the text_fg keyword on the constructor, for instance text_fg = (0, 0, 1, 1) to make it blue.
Hmm, maybe that’s just the drop shadow behind the text rendering in the wrong order. Try replacing the setBin call with:
bar.setBin('unsorted', 0)
This puts the bar in the unsorted bin instead of the fixed bin; both bins are drawn at the end of the frame, but the unsorted bin preserves the same drawing order that is observed under render2d.
I’m telling you, for whatever reason, setLightOff isn’t reaching the TextNode. I’ll take a look into DirectWaitBar tomorrow, see if there are any clues.
You know what… I remember encountering this problem before. It has something to do with render.setShaderAuto()
If you have that on, for some reason all text nodes not in render2d render black when you have setLightOff() set on them. My previous workaround was just to tie a full on ambient light to it. But if you have a better suggestion, I’m all ears.
I’ve been in 1.6.2 for this project for over a year. I’ve decided to wait to upgrade to 1.7.0 until after I finish with it. Since I’m working alone, it was a hassle to switch.