How to generate a Texture

Well I simply try for the beginning to create a texture that is half white and half black, however the box stays exactly identical as before.


   @Override
   protected void simpleInitGame() {
      SceneMonitor.getMonitor().registerNode(this.rootNode);
      SceneMonitor.getMonitor().showViewer(true);
      Texture2D texture = new Texture2D();
      Image image = new Image();
      image.setWidth(2);
      image.setHeight(2);
      image.setFormat(Image.Format.Alpha8);
      image.setMipMapSizes(null);
      ByteBuffer data = ByteBuffer.allocate(4);
      data.put((byte) 0);
      data.put((byte) 0);
      data.put((byte) 255);
      data.put((byte) 255);
      image.setData(data);
      texture.setImage(image);
      
      Box box = new Box("Keks",new Vector3f(0,0,0),1,1,1);
      TextureState texturestate = DisplaySystem.getDisplaySystem().getRenderer().createTextureState();
      texturestate.setTexture(texture);
      box.setRenderState(texturestate);
      this.rootNode.attachChild(box);
      this.rootNode.updateRenderState();
      
      
   }

A few things:

  1. The format Alpha8 probably won't work for that purpose, use Luminance8
  2. Allocate bytebuffers using BufferUtils.createByteBuffer() instead. It makes sure the buffer could be properly sent to OpenGL without copying.
  3. Put a data.clear() to reset the position index, after all the data.put() calls. Otherwise it will be sent from position 4 which would yield 0 elements.

Yep works now, with alpha i should be able to get a half transparent texture or?

hi,



wouldn

nope, it's for a lightmap compiler

Empire Phoenix said:

Yep works now, with alpha i should be able to get a half transparent texture or?

If you use Alpha8, where you put 255 these pixels will be fully opaque, where you put 0 it will be fully transparent. 128 would give you half-transparency.
Note that alpha will be ignored unless you have a BlendState set on the model.

ARe there any knows problems if i just set a blendstate at the rootnode?