PNG files on HUD

Hey Folks!



Currently having some problems getting a HUD together for a SimpleGame. I'm attempting to put a PNG graphic on the HUD to represent the background.



I'm using the following code (as per the HUD tutorial):



package gameComponents.hud.components;

import java.io.File;
import java.net.URL;
import java.nio.FloatBuffer;

import com.jme.image.Texture;
import com.jme.scene.shape.Quad;
import com.jme.scene.state.AlphaState;
import com.jme.scene.state.LightState;
import com.jme.scene.state.TextureState;
import com.jme.system.DisplaySystem;
import com.jme.util.TextureManager;
import com.jme.util.geom.BufferUtils;

public class EnemyBackground extends Quad {

   private int textureWidth;

   private int textureHeight;

   // --- Statics
   private static final long serialVersionUID = 2118927990559627147L;

   public EnemyBackground() {
      super("hud", 120f, 120f);

      URL backgroundURL = null;

      try {

         backgroundURL = new File("data/images/grassb.png").toURL();
      } catch (Exception e) {

      }

      Quad hudQuad = this;

      TextureState ts = DisplaySystem.getDisplaySystem().getRenderer().createTextureState();
      ts.setTexture(TextureManager.loadTexture(backgroundURL, 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(286));
      texCoords.put(getUForPixel(139)).put(getVForPixel(286));
      texCoords.put(getUForPixel(139)).put(getVForPixel(0));
      hudQuad.setTextureBuffer(0, texCoords);
      hudQuad.setRenderState(ts);

      AlphaState as = DisplaySystem.getDisplaySystem().getRenderer().createAlphaState();
      as.setBlendEnabled(true);

      as.setSrcFunction(AlphaState.SB_SRC_ALPHA);
      as.setDstFunction(AlphaState.DB_ONE_MINUS_SRC_ALPHA);
      as.setTestEnabled(false);
      as.setEnabled(true);
      hudQuad.setRenderState(as);

      hudQuad.setLightCombineMode(LightState.OFF);
      hudQuad.updateRenderState();
   }

   private float getUForPixel(int xPixel) {
      return (float) xPixel / textureWidth;
   }

   private float getVForPixel(int yPixel) {
      return 1f - (float) yPixel / textureHeight;
   }

}



If I attempt to use the PNG file downloaded from the Tutorial, it works fine! However if i substitute this file with any other that I make using Fireworks of Photoshop, they do not show up correctly. Instead a random set of pixels seem to appear.

Any help or guidance would be greatly appreciated!

If it has any significance I'm a Mac user!

photoshop has several options when you save a png file, make sure its not interlaced and check for other settings

theprism said:

photoshop has several options when you save a png file, make sure its not interlaced and check for other settings


Checked the interlaced property, still is not working!!!!

The PNG file I'm using (as-is):


How it appears (3 instances on HUD):


Any other ideas?

If you use the same png but saved from Paint, he works?

Don't know, i don't have paint

the image shown looks suprisingly like the missing texture image, confirm it loads the image - put it in same directory as grassb

I have put it in the same directory as grassb, and still no joy. However, grassb itself works fine!



It just appears to be PNG graphics I am creating locally…?

Got it!!! The PNG file I was using did not have dimensions that are powers of 2!!! I can't believe it was something as stupid as that d'oh!!!



Cheers guys!!