Ejemplo n.º 1
0
  /** Process and setup the <code>TextureState</code> and texture UV buffer. */
  private void processTexture() {
    FloatBuffer textureBuffer = BufferUtils.createVector2Buffer(this.vertices.length);
    float maxU = 1;
    float maxV = 1;
    float minU = 0;
    float minV = 0;
    int index = 0;
    for (IVertex vertex : this.vertices) {
      BufferUtils.setInBuffer(vertex.getTextureCoords(), textureBuffer, index);
      if (vertex.getTextureCoords().x > maxU) maxU = vertex.getTextureCoords().x;
      else if (vertex.getTextureCoords().x < minU) minU = vertex.getTextureCoords().x;
      if (vertex.getTextureCoords().y > maxV) maxV = vertex.getTextureCoords().y;
      else if (vertex.getTextureCoords().y < minV) minV = vertex.getTextureCoords().y;
      index++;
    }
    this.setTextureCoords(new TexCoords(textureBuffer));

    // Get texture state.
    TextureState state = (TextureState) this.getRenderState(StateType.Texture);
    if (state == null) {
      state = DisplaySystem.getDisplaySystem().getRenderer().createTextureState();
      this.setRenderState(state);
    }
    // Set color map.
    if (this.color != null) state.setTexture(this.loadTexture(this.color, maxU, maxV), 0);
    // Set normal map.
    if (this.normal != null) state.setTexture(this.loadTexture(this.normal, maxU, maxV), 1);
    // Set specular map.
    if (this.specular != null) state.setTexture(this.loadTexture(this.specular, maxU, maxV), 2);
  }
Ejemplo n.º 2
0
 protected void duUpdateGeometryTextures() {
   if (getTextureCoords().get(0) == null) {
     getTextureCoords().set(0, new TexCoords(BufferUtils.createVector2Buffer(24)));
     FloatBuffer tex = getTextureCoords().get(0).coords;
     tex.put(1).put(0); // 0
     tex.put(0).put(0); // 1
     tex.put(0).put(1); // 2
     tex.put(1).put(1); // 3
     tex.put(1).put(0); // 4
     tex.put(0).put(0); // 5
     tex.put(1).put(1); // 6
     tex.put(0).put(1); // 7
   }
 }