PointLight won't stay still

I’m just starting to learn jME, and if I missed this being discussed somewhere on the forums, sorry for the repetition.



I made a PointLight with a LensFlare, sort of like the one in jmetest. But although I tried to set the position of the PointLight, it seems to always show up on the opposite side of my boxes. And whereever I move, the light kind of runs away from (or circles away from me) as if we’re two opponents trying to catch/avoid each other while running around the box. Fine if you’re trying to a light-avoidance AI, but I just want a light to sit still in space.



Is this a result of using SimpleGame or something else? Wrong camera setup? Wrong way to make a PointLight or LensFlare?



Second question: I’m using two .jpg textures on the boxes. They each come out with a grid of black squares on them that isn’t in the .jpg image. Not all the images I’ve used have done this square grid thing though. Does that sound normal/any reason you know of for it?



Here’s my code:


import com.jme.app.SimpleGame;
import com.jme.bounding.BoundingSphere;
import com.jme.math.Vector3f;
import com.jme.scene.shape.Box;
import com.jme.scene.state.TextureState;
import com.jme.util.TextureManager;
import com.jme.image.Texture;
import com.jme.scene.Node;
import com.jme.scene.TriMesh;
import com.jme.scene.state.CullState;
import com.jme.scene.state.MaterialState;
import com.jme.renderer.ColorRGBA;
import com.jme.scene.state.LightState;
import com.jme.input.NodeHandler;
import com.jme.light.LightNode;
import com.jme.light.PointLight;
import com.jme.effects.LensFlare;

public class TestSimpleGame extends SimpleGame
{
  private Node scene;
  private Vector3f currentPos;
  private LightNode lightNode;
  private float moveDirection = 1;

  public static void main(String[] args) {
    TestSimpleGame app = new TestSimpleGame();
    app.setDialogBehaviour(ALWAYS_SHOW_PROPS_DIALOG);
    app.start();
  }


  protected void simpleInitGame() {
    display.setTitle("A Simple Test");

   scene = new Node("3D Scene Root");

    Box box = new Box("my box", new Vector3f(0, 0, 0), 2, 2, 2);
    box.setModelBound(new BoundingSphere());
    box.updateModelBound();
    scene.attachChild(box);
   
    TextureState ts = display.getRenderer().getTextureState();
    ts.setEnabled(true);

    ts.setTexture(
        TextureManager.loadTexture(
        TestSimpleGame.class.getClassLoader().getResource(
        "tri2.jpg"),
        Texture.MM_LINEAR,
        Texture.FM_LINEAR,
        true));
   
   box.setRenderState(ts);
      

   Box box2 = new Box("MY box", new Vector3f(0,0,4), 1, 1, 1);
   box2.setModelBound(new BoundingSphere());
   box2.updateModelBound();
   scene.attachChild(box2);

    TextureState ts2 = display.getRenderer().getTextureState();
    ts2.setEnabled(true);

    ts2.setTexture(
        TextureManager.loadTexture(
        TestSimpleGame.class.getClassLoader().getResource(
        "tri3.jpg"),
        Texture.MM_LINEAR,
        Texture.FM_LINEAR,
        true));
   
   box2.setRenderState(ts2);

   
    currentPos = new Vector3f(30,30,30);
    PointLight dr = new PointLight();
    dr.setLocation(currentPos);
    dr.setDiffuse(new ColorRGBA(1.0f, 1.0f, 1.0f, 1.0f));
    dr.setAmbient(new ColorRGBA(0.5f, 0.5f, 0.5f, 1.0f));
    dr.setEnabled(true);

    lightState.setTwoSidedLighting(true);

    lightNode = new LightNode("light", lightState);
    lightNode.setLight(dr);
    lightNode.setTarget(rootNode);

    LensFlare flare = new LensFlare("flare");
    lightNode.attachChild(flare);
    rootNode.attachChild(lightNode);

    
    //scene.setRenderState(ts);
    rootNode.attachChild(scene);
   
   CullState cs = display.getRenderer().getCullState();
   cs.setCullMode(CullState.CS_BACK);
   cs.setEnabled(true);
   rootNode.setRenderState(cs);
  }
}

Ok, I just ran your test (cut and pasted your posted code).



First problem. Point light moving. Never saw that. The point light always stayed with the box. The lens flare adjusts to the lights screen space. If you are talking about catching the lens flare, you can’t because it’s an artifact of a camera lens. It’d be like trying to catch a rainbow.



Second problem: since I don’t have your texture images to test I couldn’t try it. However, that sounds like it could be a power of 2 problem. Make sure your texture images are power of two dimensions (128,256,512, etc). Most video cards only support power of 2, and I believe those that support non-power of two you need to use an OpenGL extension, which we haven’t implemented yet.



If you are using power of two, let me know and we can delve deeper.