Example #1
0
 public void flush(boolean deactivate) {
   if (curShader != null) {
     checkGLError("flush()");
     curShader.flush();
     if (deactivate) {
       curShader.deactivate();
       curShader = null;
     }
   }
 }
  @Override
  public Surface fillTriangles(float[] xys, float[] sxys, int[] indices) {
    bindFramebuffer();

    if (fillPattern == null) throw new IllegalStateException("No fill pattern currently set");
    int tex = fillPattern.ensureTexture();
    if (tex > 0) {
      GLShader shader = ctx.trisShader(this.shader).prepareTexture(tex, tint);
      shader.addTriangles(topTransform(), xys, sxys, indices);
    }
    return this;
  }
Example #3
0
 protected GLShader createQuadShader() {
   if (shouldTryQuadShader()) {
     try {
       GLShader quadShader = new QuadShader(this);
       quadShader.createCore(); // force core creation to test whether it fails
       return quadShader;
     } catch (Throwable t) {
       platform.reportError("Failed to create QuadShader", t);
     }
   }
   return new IndexedTrisShader(this);
 }
  @Override
  public Surface drawLine(float x0, float y0, float x1, float y1, float width) {
    bindFramebuffer();

    // swap the line end points if x1 is less than x0
    if (x1 < x0) {
      float temp = x0;
      x0 = x1;
      x1 = temp;
      temp = y0;
      y0 = y1;
      y1 = temp;
    }

    float dx = x1 - x0, dy = y1 - y0;
    float length = FloatMath.sqrt(dx * dx + dy * dy);
    float wx = dx * (width / 2) / length;
    float wy = dy * (width / 2) / length;

    InternalTransform l = ctx.createTransform();
    l.setRotation(FloatMath.atan2(dy, dx));
    l.setTranslation(x0 + wy, y0 - wx);
    l.preConcatenate(topTransform());

    GLShader shader = ctx.quadShader(this.shader);
    if (fillPattern != null) {
      int tex = fillPattern.ensureTexture();
      if (tex > 0) {
        shader.prepareTexture(tex, tint);
        shader.addQuad(
            l,
            0,
            0,
            length,
            width,
            0,
            0,
            length / fillPattern.width(),
            width / fillPattern.height());
      }
    } else {
      int tex = ctx.fillImage().ensureTexture();
      shader.prepareTexture(tex, Tint.combine(fillColor, tint));
      shader.addQuad(l, 0, 0, length, width, 0, 0, 1, 1);
    }
    return this;
  }
Example #5
0
  @Override
  public Surface fillTriangles(float[] xys, int[] indices) {
    bindFramebuffer();

    GLShader shader = ctx.trisShader(this.shader);
    if (fillPattern != null) {
      int tex = fillPattern.ensureTexture(true, true);
      if (tex > 0) {
        shader.prepareTexture(tex, tint);
        shader.addTriangles(
            topTransform(), xys, fillPattern.width(), fillPattern.height(), indices);
      }
    } else {
      shader.prepareColor(Tint.combine(fillColor, tint));
      shader.addTriangles(topTransform(), xys, 1, 1, indices);
    }
    return this;
  }
Example #6
0
  @Override
  public Surface fillRect(float x, float y, float width, float height) {
    bindFramebuffer();

    GLShader shader = ctx.quadShader(this.shader);
    if (fillPattern != null) {
      int tex = fillPattern.ensureTexture(true, true);
      if (tex > 0) {
        shader.prepareTexture(tex, tint);
        float tw = fillPattern.width(), th = fillPattern.height(), r = x + width, b = y + height;
        shader.addQuad(topTransform(), x, y, x + width, y + height, x / tw, y / th, r / tw, b / th);
      }
    } else {
      shader.prepareColor(Tint.combine(fillColor, tint));
      shader.addQuad(topTransform(), x, y, x + width, y + height, 0, 0, 1, 1);
    }
    return this;
  }
  /**
   * This constructor is called by {@link GLRenderPanel}.
   *
   * @param drawable the OpenGL rendering context. All OpenGL calls are directed to this object.
   */
  public GLRenderContext(GLAutoDrawable drawable) {

    // Some OpenGL initialization
    gl = drawable.getGL().getGL3();
    gl.glEnable(GL3.GL_DEPTH_TEST);
    gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);

    // Load and use the default shader
    defaultShader = (GLShader) makeShader();
    try {
      defaultShader.load("../jrtr/shaders/default.vert", "../jrtr/shaders/default.frag");
    } catch (Exception e) {
      System.out.print("Problem with shader:\n");
      System.out.print(e.getMessage());
    }
    useDefaultShader();
  }