Textures not loading depending on image width and height

Hello to all. I am dealing with a strange issue.



In the example below there are 4 cubes with an image as texture. From the 4 cubes only the 2 show the texture correctly.

The only difference between the textures images is their hight and width.



The first(from the left) cubes image size is 512x512 (texture is loaded correctly)

The second cubes image size is 700x512 (No texture is shown)

The third cubes image size is 500x512 (No texture is shown)

The fourth cubes image size is 512x256 (texture is loaded correctly)



And from other images that i created i found that only images whose size was a power of 2 are displayed correctly.

Example 1024x512 , 256x256, 512x128 all are displayed correctly. Any other size appears black.

Also i tried different formats (jpg, gif) but there was no difference. It appears that only the size matters.





Here is the code i used:


package hello;

import com.jme3.app.SimpleBulletApplication;
import com.jme3.asset.TextureKey;
import com.jme3.bullet.collision.shapes.MeshCollisionShape;
import com.jme3.bullet.nodes.PhysicsNode;
import com.jme3.light.DirectionalLight;
import com.jme3.material.Material;
import com.jme3.material.RenderState.BlendMode;
import com.jme3.math.Vector3f;
import com.jme3.scene.Geometry;
import com.jme3.scene.Node;
import com.jme3.scene.Spatial;
import com.jme3.scene.shape.Box;
import com.jme3.texture.Texture;

public class Problem extends SimpleBulletApplication {

   @Override
   public void simpleInitApp() {
      setuplight();
      setupFloor();
      load_models();
      
   }
   
   /**
    * This loads the models we want on our scene from the Models folder.
    *
    * @param model The name of the model to load
    */
   private void load_models() {
      //This shows the path where the folder Models is located
      assetManager.registerLocator("assets/", "com.jme3.asset.plugins.ClasspathLocator");
         
       Material mat1 = new Material(assetManager, "Common/MatDefs/Misc/SimpleTextured.j3md");
       TextureKey key1 = new TextureKey("Materials/tmp/as.png", true);
       key1.setGenerateMips(true);
       Texture tex1 = assetManager.loadTexture(key1);
       tex1.setMinFilter(Texture.MinFilter.Trilinear);
       mat1.setTexture("m_ColorMap", tex1);
   
       Material mat2 = new Material(assetManager, "Common/MatDefs/Misc/SimpleTextured.j3md");
       TextureKey key2 = new TextureKey("Materials/tmp/as1.png", true);
       key2.setGenerateMips(true);
       Texture tex2 = assetManager.loadTexture(key2);
       tex2.setMinFilter(Texture.MinFilter.Trilinear);
       mat2.setTexture("m_ColorMap", tex2);
       
       Material mat3 = new Material(assetManager, "Common/MatDefs/Misc/SimpleTextured.j3md");
       TextureKey key3 = new TextureKey("Materials/tmp/as2.png", true);
       key3.setGenerateMips(true);
       Texture tex3 = assetManager.loadTexture(key3);
       tex3.setMinFilter(Texture.MinFilter.Trilinear);
       mat3.setTexture("m_ColorMap", tex3);
       
       Material mat4 = new Material(assetManager, "Common/MatDefs/Misc/SimpleTextured.j3md");
       TextureKey key4 = new TextureKey("Materials/tmp/as3.png", true);
       key4.setGenerateMips(true);
       Texture tex4 = assetManager.loadTexture(key4);
       tex4.setMinFilter(Texture.MinFilter.Trilinear);
       mat4.setTexture("m_ColorMap", tex4);
   
       
       Box b1 = new Box(Vector3f.ZERO, 1, 1, 1);
       Geometry geom1 = new Geometry("cube", b1);
       geom1.setMaterial(mat1);
       geom1.setLocalTranslation(-5,0,0);
       rootNode.attachChild(geom1);
       
       Box b2 = new Box(Vector3f.ZERO, 1, 1, 1);
       Geometry geom2 = new Geometry("cube", b2);
       geom2.setMaterial(mat2);
       geom2.setLocalTranslation(-2.5f,0,0);
       rootNode.attachChild(geom2);
       
       Box b3 = new Box(Vector3f.ZERO, 1, 1, 1);
       Geometry geom3 = new Geometry("cube", b3);
       geom3.setMaterial(mat3);
       geom3.setLocalTranslation(0,0,0);
       rootNode.attachChild(geom3);
       
       Box b4 = new Box(Vector3f.ZERO, 1, 1, 1);
       Geometry geom4 = new Geometry("cube", b4);
       geom4.setMaterial(mat4);
       geom4.setLocalTranslation(2.5f,0,0);
       rootNode.attachChild(geom4);
       
   }
   
   public void setuplight() {
       DirectionalLight dl = new DirectionalLight();
       dl.setDirection(new Vector3f(-0.5f, -1f, -0.3f).normalizeLocal());
       rootNode.addLight(dl);
   
       dl = new DirectionalLight();
       dl.setDirection(new Vector3f(0.5f, -0.1f, 0.3f).normalizeLocal());
       rootNode.addLight(dl);
   }

/**
 * Setup a floor for our scene
 */
   public void setupFloor() {
       Material mat = new Material(assetManager, "Common/MatDefs/Misc/SimpleTextured.j3md");
       TextureKey key = new TextureKey("Interface/Logo/Monkey.jpg", true);
       key.setGenerateMips(true);
       Texture tex = assetManager.loadTexture(key);
       tex.setMinFilter(Texture.MinFilter.Trilinear);
       mat.setTexture("m_ColorMap", tex);
       
       Box floor = new Box(Vector3f.ZERO, 100, 1f, 100);
       Geometry floorGeom = new Geometry("Floor", floor);
       floorGeom.setMaterial(mat);
       floorGeom.updateModelBound();
   
       PhysicsNode tb=new PhysicsNode(floorGeom,new MeshCollisionShape(floorGeom.getMesh()),0);
       rootNode.attachChild(tb);
       tb.setLocalTranslation(0f,-2,0f);
       tb.updateModelBound();
       tb.updateGeometricState();
       getPhysicsSpace().add(tb);
   }

/**
 * @param args
 */
   public static void main(String[] args) {
      Problem app = new Problem();
      app.start();
   }

}



I also attach the files that are used as textures(the three of them)

Some drivers/hardware do not support textures with other sizes than power of 2.

Cheers,

Normen

So the only solution is to resize the images that i use as textures so that their size is a power of 2.

Thank you very much!  :slight_smile: