Hi,
I'm using FengGUI and I'd like to use the scenegraph inside a FengGUI ViewPort.
do you need to also call update on the rootNode before draw ??
yes, calling updateGeometricState fixes the controllers, thanks!
the renderstates however still don't work
You have to take into account that the rootNode in SimpleGame already has some lightState associated with it, and that a node cannot have two states of the same type. Perhaps try removing all light states from the rootNode and then add yours, and after that, call updateRenderState
well, I'm not using any predefined node. The root node used in the viewport is created in the constructor and shouldn't have any renderstate applied.
public FengJMEViewPort()
{
setViewPortPaintListener(this);
rootNode = new Node("root");
renderer = DisplaySystem.getDisplaySystem().getRenderer();
}
I'm also not using SimpleGame but StandardGame with GameStates (which shouldn't make any difference imho).
here's the whole code
import org.fenggui.Display;
import org.fenggui.composites.Window;
import org.fenggui.render.lwjgl.LWJGLBinding;
import com.jme.input.KeyBindingManager;
import com.jme.input.KeyInput;
import com.jme.input.MouseInput;
import com.jme.light.PointLight;
import com.jme.math.FastMath;
import com.jme.math.Quaternion;
import com.jme.math.Vector3f;
import com.jme.renderer.Camera;
import com.jme.renderer.ColorRGBA;
import com.jme.renderer.Renderer;
import com.jme.scene.Controller;
import com.jme.scene.shape.Box;
import com.jme.scene.shape.Teapot;
import com.jme.scene.state.LightState;
import com.jme.system.DisplaySystem;
import com.jmex.editors.swing.settings.GameSettingsPanel;
import com.jmex.game.StandardGame;
import com.jmex.game.state.BasicGameState;
import com.jmex.game.state.GameStateManager;
public class TestViewPort extends BasicGameState
{
public static void main(String[] args)
{
try
{
StandardGame game = new StandardGame("ViewPortTest");
if (!GameSettingsPanel.prompt(game.getSettings()))
System.exit(0);
game.start();
TestViewPort test = new TestViewPort();
GameStateManager.getInstance().attachChild(test);
test.setActive(true);
}
catch (Throwable t)
{
t.printStackTrace();
System.exit(1);
}
}
private DisplaySystem display;
private Renderer renderer;
private Camera cam;
private FengJMEInputHandler fengInput;
private Display fengDesk;
private KeyBindingManager kbm;
private Box box;
public TestViewPort()
{
super("testViewPort");
display = DisplaySystem.getDisplaySystem();
renderer = display.getRenderer();
cam = renderer.getCamera();
//fenggui
fengDesk = new Display(new LWJGLBinding());
fengInput = new FengJMEInputHandler(fengDesk);
//input
kbm = KeyBindingManager.getKeyBindingManager();
kbm.add("exit", KeyInput.KEY_ESCAPE);
MouseInput.get().setCursorVisible(true);
//cam
cam.setLocation(new Vector3f(10,10,10));
cam.lookAt(new Vector3f(), new Vector3f(0,1,0));
//dummy box
box = new Box("box", new Vector3f(), 5, 5, 5);
rootNode.attachChild(box);
//viewport
Window win = new Window(true, false, false, true);
fengDesk.addWidget(win);
win.setSize(300,200);
win.setXY(100, 100);
final Teapot teapot = new Teapot("teapot");
teapot.addController(new Controller() {
@Override
public void update(float time)
{
teapot.getLocalRotation().multLocal(new Quaternion().fromAngleAxis(
1f * FastMath.DEG_TO_RAD, new Vector3f(0,1,0)));
}
});
FengJMEViewPort vp = new FengJMEViewPort();
vp.getRootNode().attachChild(teapot);
vp.getRootNode().updateRenderState();
win.getContentContainer().addWidget(vp);
fengDesk.layout();
//light
PointLight pl = new PointLight();
pl.setAmbient(ColorRGBA.white);
pl.setDiffuse(ColorRGBA.white);
pl.setSpecular(ColorRGBA.white);
pl.setEnabled(true);
pl.setLocation(new Vector3f(50, 100, 50));
LightState ls = renderer.createLightState();
ls.setEnabled(true);
ls.attach(pl);
rootNode.setRenderState(ls);
rootNode.updateRenderState();
}
public void update(float tpf)
{
super.update(tpf);
if (kbm.isValidCommand("exit", false))
{
cleanup();
System.exit(0);
}
box.getLocalRotation().multLocal(new Quaternion().fromAngleAxis(
0.01f * FastMath.DEG_TO_RAD, new Vector3f(0,1,0)));
}
public void render(float tpf)
{
super.render(tpf);
fengDesk.display();
}
}
import org.fenggui.ViewPort;
import org.fenggui.event.IViewPortPaintListener;
import org.fenggui.render.Graphics;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.glu.GLU;
import com.jme.light.PointLight;
import com.jme.math.Vector3f;
import com.jme.renderer.ColorRGBA;
import com.jme.renderer.Renderer;
import com.jme.scene.Node;
import com.jme.scene.state.LightState;
import com.jme.system.DisplaySystem;
import com.jme.util.Timer;
public class FengJMEViewPort extends ViewPort implements IViewPortPaintListener
{
private Node rootNode;
private LightState lightState;
private Renderer renderer;
public FengJMEViewPort()
{
super();
setViewPortPaintListener(this);
rootNode = new Node("root");
renderer = DisplaySystem.getDisplaySystem().getRenderer();
PointLight pl = new PointLight();
pl.setDiffuse(ColorRGBA.white);
pl.setAmbient(ColorRGBA.white);
pl.setSpecular(ColorRGBA.white);
pl.setLocation(new Vector3f(0,20,0));
pl.setEnabled(true);
lightState = renderer.createLightState();
lightState.attach(pl);
lightState.setEnabled(true);
rootNode.setRenderState(lightState);
}
@Override
public void paint(Graphics g, int viewPortWidth, int viewPortHeight)
{
GL11.glDisable(GL11.GL_DEPTH_TEST);
GL11.glMatrixMode(GL11.GL_PROJECTION);
GL11.glLoadIdentity();
GLU.gluPerspective(45, (float)viewPortWidth/(float)viewPortHeight, 4, 100);
GL11.glMatrixMode(GL11.GL_MODELVIEW);
GL11.glLoadIdentity();
GLU.gluLookAt(10, 6, 8, 0, 0, 0, 0, 1, 0);
renderer.draw(rootNode);
rootNode.updateGeometricState(Timer.getTimer().getTimePerFrame(), true);
GL11.glFlush();
}
public Node getRootNode()
{
return rootNode;
}
public void setRootNode(Node rootNode)
{
this.rootNode = rootNode;
}
public Renderer getRenderer()
{
return renderer;
}
public void setRenderer(Renderer renderer)
{
this.renderer = renderer;
}
}
lights and textures combine down the scenegraph, (depending on the settings).
That aside, your code has the lights with full white ambient… try turning that down to a dim grey.
renanse said:
your code has the lights with full white ambient...
You are seeking out brave new worlds, going where no man ( errm person ) has gone before.
Can you get by with having the rootnode updated as normal outside of fenggui, but rendering the scene to a spatial from a camera view and having this in the viewport ??
theprism said:
Can you get by with having the rootnode updated as normal outside of fenggui, but rendering the scene to a spatial from a camera view and having this in the viewport ??
I'm not sure what you mean?
I've tried to render everything to a texture and to only draw a quad with that texture in the viewport but this has the same effect: http://img246.imageshack.us/my.php?image=bildschirmfotoei7.png
I've read that there is a component in BUI which allows to do exactly that?! Shouldn't this be possible with FengGUI as well then?
hi
you dont disabled GL_DEPTH_TEST
erase this line
GL11.glDisable(GL11.GL_DEPTH_TEST);
i have trying you code for my small game
and it's great
before this line
GL11.glMatrixMode(GL11.GL_PROJECTION);
place this line
GL11.glClear( GL11.GL_DEPTH_BUFFER_BIT);//clear a Depth buff
GL11.glEnable (GL11.GL_DEPTH_TEST);//activate for a depth Quad
and thank for this code