I have a box with a texture shaped like a crosshair. Most of it is transparent. Its color is that of the viewport color. However, as it passes over geometry, it shows just like a box. Its transparent area has the color of the viewport. The screenshot explains it better:
http://i44.tinypic.com/346mh6w.png
I am using the following code for transparency, and I use it only once during initialization:
crosshair.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);
What should I add?
Why is it colored in the first place?
Just make the crosshair itself the color you need it and the rest empty. What you seeing, from what I understand, it normal behavior.
Where you see red, it should be transparent. It’s a texture on a box.
I feel I’ll regret asking this, but why use a textured box as a crosshair?
If you don’t set up the alpha threshold and cutoff on the render state then even the invisible pixels will fill the z buffer and cause things behind it not to get drawn.
@memonick said:
no real reason. Guess I should use a spatial/node.
Why not use a simple quad? That would stop the behavior you're seeing; no need to split hair in 28 pieces. ;)
Same result. It’s still not transparent.
Of course if your crosshair texture is pink as the viewport color, as soon as it goes over something else of a different color, it’ll display pink. Nothing to do about that. Remove the pink color so it’s transparent. No color at all.
Maybe I’m misunderstanding what you’re trying to achieve with your crosshair.
Your spatial has to be in the transparent bucket (spatial.setRenderBucket(Bucket.Transparent)).
@madjack, apart from the blue, everything is transparent
@nehon, that did the trick. I think you had a mistake though. It’s setQueueBucket. I couldn’t find setRenderBucket.
Thanks
No one reads my posts except the original poster.
I will explain what’s happening for all involved.
There is a quad or box being drawn (which one doesn’t matter) at a certain depth. It is filling the Z buffer with EVERY pixel of the object even if they are transparent. This means that anything drawn after that, farther away, will not be drawn.
I can’t comment on why the scene is setup that way (maybe everything is in the transparent bucket) but that’s what I’m pretty sure is happening.
@memonick, sorry I wasn’t clearer. I thought be mentioning “render state” that you might associate that with the things you are already setting on render state, ie: getAdditionalRenderState().setBlendMode(). But I’m going to stop short of writing your code for you and make you actually look at the javadocs for RenderState.
edit: @nehon, or that too.
Yeah well, that’s close enough from memory :p.
You know this is pretty basic and entirely covered in the tutorials. Maybe you should go through them once again.
Note: you may still want to set the alpha threshold and cutoff or you may have problems over-clipping other transparent objects.
@nehon said:
Yeah well, that's close enough from memory :p.
You know this is pretty basic and entirely covered in the tutorials. Maybe you should go through them once again.
Yeah. My mistake was assuming it was something not covered in the tutorials. Silly me.
Thanks pspeed. I did try them, but I couldn’t find the cutoff.
In fact, I already had this code: crosshair.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);
@memonick said:
Thanks pspeed. I did try them, but I couldn't find the cutoff.
In fact, I already had this code: crosshair.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);
I KNOW you already had that code. The other settings are on the exact same render state object. If you'd looked you might have seen... but I will provide the links anyway:
http://hub.jmonkeyengine.org/javadoc/com/jme3/material/RenderState.html
That's the javadoc for RenderState. If this is your first time looking at it then scroll down until you see something related to alpha.
http://hub.jmonkeyengine.org/javadoc/com/jme3/material/RenderState.html#setAlphaTest(boolean)
http://hub.jmonkeyengine.org/javadoc/com/jme3/material/RenderState.html#setAlphaFallOff(float)
I know I had the names slightly wrong but they are close. Java software development will be a constant struggle for you if you don't learn to drill into the javadocs a little more deeply.
@pspeed lol I was talking to memonick, i wouldn’t dare RTFM you
@nehon said:
@pspeed lol I was talking to memonick, i wouldn't dare RTFM you ;)
I know. I was explaining myself. :)
I over deduced the situation incorrectly assuming that all avenues of "regular person" investigation had already been done by the original poster. So I offered the advanced advice. Sometimes I forget that new developers don't avail themselves of the help that is already available.