I have an Absolute mouse and I’m making sure that it renders last. But it still ends up being under widgets. Any ideas?
We are going to be adding a fairly cool concept soon to handle these situations (seperate rendering for opaque, transparent and GUI). Until then, add a ZBufferState to the mouse that has it does no depth checking.
I though that’s the direction I needed to go. This is what I have now:
ZBufferState bs = Application._app.getDisplay().getRenderer().getZBufferState();
bs.setFunction( ZBufferState.CF_ALWAYS);
bs.setEnabled( true);
_mouse.setRenderState(bs);
If I cange it to CF_NEVER then my mouse doesn't show up at all :(.
Is that what you were meaning?
As a side note: This may not be the place, but could someone point me to a place with information so that I may understand the difference b/t culling, zbuffer, and stencil states?
CF_NEVER says the pixel willl never pass the depth test (never be rendered). CF_ALWAYS should work.
http://www.opengl.org/documentation/red_book_1.0/
has a free red book (old version) that has good discussion on the various states.
Ok, so always is what I have it set to but the widget and thing rendered after the mouse are still on top.
Under Text that’s renderered after the cursor.
Under an WidgetImageButton that’s rendered before the cursor.
(Thanks for the link.)
Hmm, it turns out that if I turn off the AlphaState the mouse is always on top just like it’s supposed to be. Just with the ‘nice’ black box around it. So, now I start playing with the Alpha state to just make the black background of the cursor be transparent.
Thanks!
Oh… Crap… Huh, back to the drawing board. I’m thinking that I can’t use widgets then.
At the link above:
glAlphaFunc ( GL_GREATER, 0.1 ) ;
glEnable ( GL_ALPHA_TEST ) ;
How is this done with jME?
The BlendState controls the AlphaFunc.
I find hide nor hair of ‘BlendState’ within any jME source :?
Right now I have:
as1.setBlendEnabled(true);
as1.setSrcFunction(AlphaState.SB_SRC_ALPHA);
as1.setDstFunction(AlphaState.DB_ONE);
as1.setTestEnabled(true);
as1.setReference( 0.1f);
as1.setTestFunction(AlphaState.TF_GREATER);
I've removed the zBuffer stuff since I really don't need it, since I'm rendering the cursor last. I think the 0.1 from the above example is used in the setReference.
Still not quite right. I am starting to think that the fonts used in all the examples are bright white for a reason :).
Is it possible the mouse image you are using uses colors with an alpha channel or something? Also, would it be possible to put together a simple example of this I could use to trouble shoot? If so, send me a copy via email (see my profile) and I’ll work it out and post the appropriate steps for everyone.
HA! I had a MAJOR brain fart… there is no BlendState. Wow…
anyways, you’d probably want blend disabled while leaving alpha enabled if you only want to do transparency based on alpha channel. Blending will blending opaque colors together (depending on the blend functions).
Thanks for emailing that. Here’s what I found out:
- The rendering of Mouse in LWJGLRenderer did not set a color and colors set to the Mouse class are ignored. In your example, it uses something other than white (black or gray perhaps) which is making the colors of the image on the mouse very muted. I’ve made a change to the renderer to set white as the color when drawing the mouse and now it’s nice and bright.
- I suggest putting the mouse in a seperate Node (let’s call it mouseNode) that is not attached to anything. Then in your render method, make a call to draw mouseNode after drawing your scene and everything else. Having it in a seperate node that is rendered seperately will also prevent it from inheriting unwanted render states.
- For your mouse image, I suggest using a format that supports transparency, PNG for example. Draw your mouse with a transparent background instead of just using black. Then use the following alpha state:
AlphaState as1 = display.getRenderer().getAlphaState();
as1.setBlendEnabled(true);
as1.setSrcFunction(AlphaState.SB_SRC_ALPHA);
as1.setDstFunction(AlphaState.DB_ONE_MINUS_DST_ALPHA);
as1.setTestEnabled(true);
as1.setTestFunction(AlphaState.TF_GREATER);
as1.setEnabled(true);
mouse.setRenderState(as1);
4. Don't forget to call updateRenderState() on the mouseNode.
Hope that helps.
You the Programmer renanse! Works like a charm!
Thanks!
Happy to help!