Question about huds

hey,

I have followed the Tutorial for Huds, and I want to show an image of the player's gun in the top corner of the player's view, but nohing appears, can anyone explain why the image does not appear, below is the code i am using:






public void paintGun()
   {
      
      hudNode2 = new Node("hudNode");
        Quad hudQuad = new Quad("hud", 40f, 40f);
        hudNode2.setLocalTranslation(new Vector3f(950, 700, 0));
        hudNode2.setRenderQueueMode(Renderer.QUEUE_ORTHO); 
       
        TextureState ts = display.getRenderer().createTextureState();
        ts.setTexture(TextureManager.loadTexture(getClass().getClassLoader()
             .getResource("models/guns/MP52.PNG"), Texture.MM_LINEAR,
             Texture.FM_LINEAR, 1.0f, true));
        textureWidth = ts.getTexture().getImage().getWidth();
        textureHeight = ts.getTexture().getImage().getHeight();
        ts.setEnabled(true);
       
        FloatBuffer texCoords = BufferUtils.createVector2Buffer(4);
        texCoords.put(getUForPixel(0)).put(getVForPixel(0));
        texCoords.put(getUForPixel(0)).put(getVForPixel(40));
        texCoords.put(getUForPixel(40)).put(getVForPixel(40));
        texCoords.put(getUForPixel(40)).put(getVForPixel(0));
        hudQuad.setTextureBuffer(0, texCoords);
        hudQuad.setRenderState(ts);

      
        //hudQuad.setRenderState(ts);
        AlphaState as = display.getRenderer().createAlphaState();
        as.setBlendEnabled(true);
 
        as.setSrcFunction(AlphaState.SB_SRC_ALPHA);
        as.setDstFunction(AlphaState.DB_ONE_MINUS_SRC_ALPHA);
        as.setTestEnabled(true);
        as.setEnabled(true);         

       // hudQuad.setLocalTranslation(new Vector3f(display.getWidth()/2 ,display.getHeight()/2,0));
      
        hudNode2.setLightCombineMode(LightState.OFF);       
        hudNode2.updateRenderState();
       
        hudNode2.attachChild(hudQuad);
      
        hudNode2.setRenderState(ts);
        hudNode2.setRenderState(as);
        hudNode2.updateRenderState();
        fpsNode.attachChild(hudNode2);
        //fpsNode.attachChild(hudNode);
      gameRootNode.attachChild(hudNode2);
      
      
      
   }




i'm not sure i can help because i don't know how the rest of your app looks like but:

  1. i noticed your method is called 'paintGun'. i hope it's not a method you call every frame but only once to set up your HUD.
  2. if your texture is a 40x40 image you don't need all that texture buffer stuff. if you use a bigger texture for with uv mapping, then ignore this comment.
  3. if hudNode2 is a HUD element only, then you shouldn't attach it to the fps node and to the game root node. (the fps node is a bad idea anyway)
  4. you don't need to call updateRenderState after each change. do it only once after you made all changes

    5 don't forget to call updateGeometricState on your root node.

Thnax for ur help, i got it working, i dont suppose u know where i can find out how to create a mini map for my hud?

there are several ways to do that. from posts in this forum it seems that some people do it by rendering the scene from above in ortho mode. you'll have to play around a bit and figure out what's best for you.