Example #1
0
  public void renderImage(
      RenderImage image, int x, int y, int width, int height, Color color, float imageScale) {

    RenderImageJme jmeImage = (RenderImageJme) image;

    textureColorMaterial.setColor("Color", convertColor(color, tempColor));
    textureColorMaterial.setTexture("ColorMap", jmeImage.getTexture());

    quad.clearBuffer(Type.TexCoord);
    quad.setBuffer(quadDefaultTC);

    float x0 = x + 0.5f * width * (1f - imageScale);
    float y0 = y + 0.5f * height * (1f - imageScale);

    tempMat.loadIdentity();
    tempMat.setTranslation(x0, getHeight() - y0, 0);
    tempMat.setScale(width * imageScale, height * imageScale, 0);

    rm.setWorldMatrix(tempMat);
    rm.setForcedRenderState(renderState);
    textureColorMaterial.render(quadGeom, rm);

    // System.out.format("renderImage1(%s, %d, %d, %d, %d, %s, %f)\n",
    // jmeImage.getTexture().getKey().toString(), x, y, width, height, color.toString(),
    // imageScale);
  }
Example #2
0
  public RenderDeviceJme(NiftyJmeDisplay display) {
    this.display = display;

    quadColor = new VertexBuffer(Type.Color);
    quadColor.setNormalized(true);
    ByteBuffer bb = BufferUtils.createByteBuffer(4 * 4);
    quadColor.setupData(Usage.Stream, 4, Format.UnsignedByte, bb);
    quad.setBuffer(quadColor);

    quadModTC.setUsage(Usage.Stream);

    // Load the 3 material types separately to avoid
    // reloading the shader when the defines change.

    // Material with a single color (no texture or vertex color)
    colorMaterial = new Material(display.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");

    // Material with a texture and a color (no vertex color)
    textureColorMaterial =
        new Material(display.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");

    // Material with vertex color, used for gradients (no texture)
    vertexColorMaterial =
        new Material(display.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
    vertexColorMaterial.setBoolean("VertexColor", true);

    // Shared render state for all materials
    renderState.setDepthTest(false);
    renderState.setDepthWrite(false);
  }
Example #3
0
  public void renderImage(
      RenderImage image,
      int x,
      int y,
      int w,
      int h,
      int srcX,
      int srcY,
      int srcW,
      int srcH,
      Color color,
      float scale,
      int centerX,
      int centerY) {

    RenderImageJme jmeImage = (RenderImageJme) image;
    Texture2D texture = jmeImage.getTexture();

    textureColorMaterial.setColor("Color", convertColor(color, tempColor));
    textureColorMaterial.setTexture("ColorMap", texture);

    float imageWidth = jmeImage.getWidth();
    float imageHeight = jmeImage.getHeight();
    FloatBuffer texCoords = (FloatBuffer) quadModTC.getData();

    float startX = srcX / imageWidth;
    float startY = srcY / imageHeight;
    float endX = startX + (srcW / imageWidth);
    float endY = startY + (srcH / imageHeight);

    startY = 1f - startY;
    endY = 1f - endY;

    texCoords.rewind();
    texCoords.put(startX).put(startY);
    texCoords.put(endX).put(startY);
    texCoords.put(endX).put(endY);
    texCoords.put(startX).put(endY);
    texCoords.flip();
    quadModTC.updateData(texCoords);

    quad.clearBuffer(Type.TexCoord);
    quad.setBuffer(quadModTC);

    float x0 = centerX + (x - centerX) * scale;
    float y0 = centerY + (y - centerY) * scale;

    tempMat.loadIdentity();
    tempMat.setTranslation(x0, getHeight() - y0, 0);
    tempMat.setScale(w * scale, h * scale, 0);

    rm.setWorldMatrix(tempMat);
    rm.setForcedRenderState(renderState);
    textureColorMaterial.render(quadGeom, rm);

    // System.out.format("renderImage2(%s, %d, %d, %d, %d, %d, %d, %d, %d, %s, %f, %d, %d)\n",
    // texture.getKey().toString(),
    //                                                                                       x, y,
    // w, h, srcX, srcY, srcW, srcH,
    //
    // color.toString(), scale, centerX, centerY);
  }