here is my code in its entirety - I cant figure out why its not drawing the mouse - transparency is set on my temp. hub and other images show through it. Sorry about the ugliness - first attempt at jME
/*
* Copyright (c) 2003-2009 jMonkeyEngine
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* * Neither the name of 'jMonkeyEngine' nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package windows;
import jmetest.renderer.*;
import com.jme.app.SimpleGame;
import com.jme.bounding.BoundingBox;
import com.jme.image.Texture;
import com.jme.input.AbsoluteMouse;
import com.jme.input.FirstPersonHandler;
import com.jme.input.KeyBindingManager;
import com.jme.input.KeyInput;
import com.jme.input.MouseInput;
import com.jme.intersection.BoundingPickResults;
import com.jme.intersection.PickResults;
import com.jme.light.DirectionalLight;
import com.jme.math.Ray;
import com.jme.math.Vector2f;
import com.jme.math.Vector3f;
import com.jme.renderer.ColorRGBA;
import com.jme.renderer.Renderer;
import com.jme.scene.Node;
import com.jme.scene.Spatial;
import com.jme.scene.Spatial.LightCombineMode;
import com.jme.scene.shape.Box;
import com.jme.scene.shape.Quad;
import com.jme.scene.shape.Torus;
import com.jme.scene.state.BlendState;
import com.jme.scene.state.BlendState.DestinationFunction;
import com.jme.scene.state.BlendState.SourceFunction;
import com.jme.scene.state.LightState;
import com.jme.scene.state.MaterialState;
import com.jme.scene.state.RenderState;
import com.jme.scene.state.TextureState;
import com.jme.scene.state.ZBufferState;
import com.jme.system.DisplaySystem;
import com.jme.util.TextureManager;
import java.net.URL;
import java.util.logging.Logger;
/**
* <code>TestRenderQueue</code> demonstrates the usage and implications of the
* RenderQueue (including 2-sided transparency) and Spatial's
* renderQueueMode field.
*
* @author Joshua Slack
* @version $Id: TestRenderQueue.java 4130 2009-03-19 20:04:51Z blaine.dev $
*/
public class MyTestRenderQueue extends SimpleGame {
// START MOUSE ADDITION
private static final Logger logger = Logger.getLogger(MyTestRenderQueue.class
.getName());
// This will be my mouse
AbsoluteMouse am;
PickResults pr;
// END MOUSE ADDITION
private boolean useQueue = false;
protected Node opaques, transps, orthos;
/**
* Entry point for the test,
*
* @param args
*/
public static void main(String[] args) {
MyTestRenderQueue app = new MyTestRenderQueue();
app.setConfigShowMode(ConfigShowMode.AlwaysShow);
app.start();
}
protected void simpleUpdate() {
// Get the mouse input device from the jME mouse
// Is button 0 down? Button 0 is left click
if (MouseInput.get().isButtonDown(0)) {
Vector2f screenPos = new Vector2f();
// Get the position that the mouse is pointing to
screenPos.set(am.getHotSpotPosition().x, am.getHotSpotPosition().y);
// Get the world location of that X,Y value
Vector3f worldCoords = display.getWorldCoordinates(screenPos, 0);
Vector3f worldCoords2 = display.getWorldCoordinates(screenPos, 1);
logger.info( worldCoords.toString() );
// Create a ray starting from the camera, and going in the direction
// of the mouse's location
Ray mouseRay = new Ray(worldCoords, worldCoords2
.subtractLocal(worldCoords).normalizeLocal());
// Does the mouse's ray intersect the box's world bounds?
pr.clear();
rootNode.findPick(mouseRay, pr);
for (int i = 0; i < pr.getNumber(); i++) {
pr.getPickData(i).getTargetMesh().setRandomColors();
}
}
boolean updateTitle = false;
if (KeyBindingManager.getKeyBindingManager().isValidCommand("queue",
false)) {
if (useQueue) {
transps.setRenderQueueMode(Renderer.QUEUE_SKIP);
opaques.setRenderQueueMode(Renderer.QUEUE_SKIP);
orthos.setRenderQueueMode(Renderer.QUEUE_SKIP);
} else {
transps.setRenderQueueMode(Renderer.QUEUE_TRANSPARENT);
opaques.setRenderQueueMode(Renderer.QUEUE_OPAQUE);
orthos.setRenderQueueMode(Renderer.QUEUE_ORTHO);
}
useQueue = !useQueue;
updateTitle = true;
}
if (KeyBindingManager.getKeyBindingManager().isValidCommand("trans",
false)) {
display.getRenderer().getQueue().setTwoPassTransparency(
!display.getRenderer().getQueue().isTwoPassTransparency());
updateTitle = true;
}
if (updateTitle) {
display.setTitle("Test Render Queue - " + useQueue
+ " - hit 'M' to toggle Queue Mode - '2' Two Pass: - "
+ display.getRenderer().getQueue().isTwoPassTransparency());
}
}
protected void simpleRender() {
/*Renderer r = display.getRenderer();
if (!useQueue) {
r.setOrtho();
r.draw(orthos);
r.unsetOrtho();
} else {
r.draw(orthos);
}
r.draw(transps);
r.draw(opaques);*/
Renderer r = display.getRenderer();
r.setOrtho();
r.draw(orthos);
r.unsetOrtho();
r.draw(transps);
r.draw(opaques);
}
protected void simpleInitGame() {
display
.setTitle("Test Render Queue - false - hit 'M' to toggle Queue Mode - '2' Two Pass: - true");
KeyBindingManager.getKeyBindingManager().set("queue", KeyInput.KEY_M);
KeyBindingManager.getKeyBindingManager().set("trans", KeyInput.KEY_2);
cam.setLocation(new Vector3f(10, 0, 50));
cam.update();
Vector3f max = new Vector3f(5, 5, 5);
Vector3f min = new Vector3f(-5, -5, -5);
opaques = new Node("Opaques");
transps = new Node("Transps");
orthos = new Node("Orthos");
transps.setRenderQueueMode(Renderer.QUEUE_SKIP);
opaques.setRenderQueueMode(Renderer.QUEUE_SKIP);
orthos.setRenderQueueMode(Renderer.QUEUE_SKIP);
rootNode.attachChild(orthos);
rootNode.attachChild(transps);
rootNode.attachChild(opaques);
// CONFIGURE WALLPAPER
int border = 0;
Quad wallpaper = new Quad("Background", display.getWidth()-border, display.getHeight()-border);
wallpaper.setLocalTranslation(new Vector3f(display.getWidth() / 2, display.getHeight() / 2, -1.0f));
wallpaper.setRenderQueueMode(Renderer.QUEUE_ORTHO);
wallpaper.setLightCombineMode(LightCombineMode.Off);
URL url_wallpaper = BlendStateTest.class.getClassLoader().getResource("jmetest/data/texture/bkg2.png");
Texture tex = TextureManager.loadTexture(url_wallpaper,
Texture.MinificationFilter.Trilinear,
Texture.MagnificationFilter.Bilinear);
TextureState ts = display.getRenderer().createTextureState();
ts.setEnabled(true);
ts.setTexture(tex);
wallpaper.setRenderState(ts);
wallpaper.updateRenderState();
wallpaper.setModelBound(new BoundingBox());
wallpaper.updateModelBound();
orthos.attachChild(wallpaper);
Vector3f min1 = new Vector3f(-4, -3, -2);
Vector3f max1 = new Vector3f(4, 3, 2);
Box box = new Box("box1", min1, max1);
MaterialState boxMS = display.getRenderer().createMaterialState();
boxMS.setDiffuse(new ColorRGBA(0, 0, 100, 0.5f));
boxMS.setAmbient(new ColorRGBA(0, 50, 100, 0.5f));
box.setRenderState(boxMS);
BlendState blend = display.getRenderer().createBlendState();
blend.setSourceFunctionAlpha(SourceFunction.SourceAlpha);
blend.setDestinationFunctionAlpha(DestinationFunction.One);
blend.setEnabled(true);
blend.setBlendEnabled(true);
blend.setTestEnabled(true);
blend.setTestFunction(BlendState.TestFunction.GreaterThan);
box.setRenderState(blend);
box.updateRenderState();
opaques.attachChild(box);
// START MOUSE ADDITION
// Create a new mouse. Restrict its movements to the display screen.
am = new AbsoluteMouse("The Mouse", display.getWidth(), display
.getHeight());
// Get a picture for my mouse.
TextureState tsmouse = display.getRenderer().createTextureState();
URL cursorLoc = MyTestRenderQueue.class.getClassLoader().getResource(
"jmetest/data/cursor/cursor1.png" );
Texture tmouse = TextureManager.loadTexture(cursorLoc, Texture.MinificationFilter.NearestNeighborNoMipMaps,
Texture.MagnificationFilter.Bilinear);
tsmouse.setTexture(tmouse);
am.setRenderState(tsmouse);
// Make the mouse's background blend with what's already there
BlendState as = display.getRenderer().createBlendState();
as.setBlendEnabled(true);
as.setSourceFunction(BlendState.SourceFunction.SourceAlpha);
as.setDestinationFunction(BlendState.DestinationFunction.OneMinusSourceAlpha);
as.setTestEnabled(true);
as.setTestFunction(BlendState.TestFunction.GreaterThan);
am.setRenderState(as);
// Get the mouse input device and assign it to the AbsoluteMouse
// Move the mouse to the middle of the screen to start with
am.setLocalTranslation(new Vector3f(display.getWidth() / 2, display
.getHeight() / 2, 0));
// Assign the mouse to an input handler
am.registerWithInputHandler( input );
// Attach Children
rootNode.attachChild(am);
// Remove all the lightstates so we can see the per-vertex colors
lightState.detachAll();
pr = new BoundingPickResults();
(( FirstPersonHandler ) input ).getMouseLookHandler().setEnabled( false );
//STOP MOUSE ADDITION
LightState ls = display.getRenderer().createLightState();
ls.setEnabled(true);
DirectionalLight dLight = new DirectionalLight();
dLight.setEnabled(true);
dLight.setDiffuse(new ColorRGBA(1, 1, 1, 1));
dLight.setDirection(new Vector3f(-1, -1, -1));
ls.attach(dLight);
DirectionalLight dLight2 = new DirectionalLight();
dLight2.setEnabled(true);
dLight2.setDiffuse(new ColorRGBA(1, 1, 1, 1));
dLight2.setDirection(new Vector3f(1, 1, 1));
ls.attach(dLight2);
ls.setTwoSidedLighting(true);
transps.setRenderState(ls);
transps.setLightCombineMode(Spatial.LightCombineMode.Replace);
BlendState alphaState = DisplaySystem.getDisplaySystem().getRenderer().createBlendState();
alphaState.setSourceFunction(BlendState.SourceFunction.SourceAlpha);
alphaState.setDestinationFunction(BlendState.DestinationFunction.OneMinusSourceAlpha);
alphaState.setTestEnabled(true);
alphaState.setTestFunction(BlendState.TestFunction.GreaterThan);
alphaState.setEnabled(true);
orthos.setRenderState(alphaState);
ZBufferState zstate = display.getRenderer().createZBufferState();
zstate.setWritable(false);
zstate.setEnabled(false);
orthos.setRenderState(zstate);
orthos.setRenderState(Renderer.defaultStateList[RenderState.StateType.Light.ordinal()]);
// XXX: This is CullHint.Always because we want to explicity control how it's children are drawn for purposes of this demonstration.
rootNode.setCullHint(Spatial.CullHint.Always);
// XXX: Set these to CullHint.Never so that when we explicitly call draw on them, they will draw.
// XXX: otherwise, due to their parent being drawn with CullHint.Always, they will skip draw.
opaques.setCullHint(Spatial.CullHint.Never);
transps.setCullHint(Spatial.CullHint.Never);
orthos.setCullHint(Spatial.CullHint.Never);
}
}