Example #1
0
 public void poly(Coord... c) {
   st.set(cur2d);
   apply();
   gl.glBegin(GL2.GL_POLYGON);
   for (Coord vc : c) vertex(vc);
   gl.glEnd();
   checkerr();
 }
Example #2
0
 private void create(GOut g) {
   BGL gl = g.gl;
   t = new TexOb(g);
   gl.glBindTexture(GL.GL_TEXTURE_CUBE_MAP, t);
   gl.glTexParameteri(GL.GL_TEXTURE_CUBE_MAP, GL.GL_TEXTURE_MIN_FILTER, GL.GL_NEAREST);
   gl.glTexParameteri(GL.GL_TEXTURE_CUBE_MAP, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST);
   fill(g);
   checkerr(gl);
 }
Example #3
0
 public void line(Coord c1, Coord c2, double w) {
   st.set(cur2d);
   apply();
   gl.glLineWidth((float) w);
   gl.glBegin(GL.GL_LINES);
   vertex(c1);
   vertex(c2);
   gl.glEnd();
   checkerr();
 }
Example #4
0
 public void frect(Coord c1, Coord c2, Coord c3, Coord c4) {
   st.set(cur2d);
   apply();
   gl.glBegin(GL2.GL_QUADS);
   vertex(c1);
   vertex(c2);
   vertex(c3);
   vertex(c4);
   gl.glEnd();
   checkerr();
 }
Example #5
0
 public void rect(Coord ul, Coord sz) {
   st.set(cur2d);
   apply();
   gl.glLineWidth(1);
   gl.glBegin(GL.GL_LINE_LOOP);
   vertex(ul.x + 0.5f, ul.y + 0.5f);
   vertex(ul.x + sz.x - 0.5f, ul.y + 0.5f);
   vertex(ul.x + sz.x - 0.5f, ul.y + sz.y - 0.5f);
   vertex(ul.x + 0.5f, ul.y + sz.y - 0.5f);
   gl.glEnd();
   checkerr();
 }
Example #6
0
 public void fellipse(Coord c, Coord r, int a1, int a2) {
   st.set(cur2d);
   apply();
   gl.glBegin(GL.GL_TRIANGLE_FAN);
   vertex(c);
   for (int i = a1; i <= a2; i += 5) {
     double a = (i * Math.PI * 2) / 360.0;
     vertex(c.add((int) (Math.cos(a) * r.x), -(int) (Math.sin(a) * r.y)));
   }
   gl.glEnd();
   checkerr();
 }
Example #7
0
  public void prect(Coord c, Coord ul, Coord br, double a) {
    st.set(cur2d);
    apply();
    gl.glEnable(GL2.GL_POLYGON_SMOOTH);
    gl.glBegin(GL.GL_TRIANGLE_FAN);
    vertex(c);
    vertex(c.add(0, ul.y));
    double p2 = Math.PI / 2;
    all:
    {
      float tc;

      tc = (float) (Math.tan(a) * -ul.y);
      if ((a > p2) || (tc > br.x)) {
        vertex(c.x + br.x, c.y + ul.y);
      } else {
        vertex(c.x + tc, c.y + ul.y);
        break all;
      }

      tc = (float) (Math.tan(a - (Math.PI / 2)) * br.x);
      if ((a > p2 * 2) || (tc > br.y)) {
        vertex(c.x + br.x, c.y + br.y);
      } else {
        vertex(c.x + br.x, c.y + tc);
        break all;
      }

      tc = (float) (-Math.tan(a - Math.PI) * br.y);
      if ((a > p2 * 3) || (tc < ul.x)) {
        vertex(c.x + ul.x, c.y + br.y);
      } else {
        vertex(c.x + tc, c.y + br.y);
        break all;
      }

      tc = (float) (-Math.tan(a - (3 * Math.PI / 2)) * -ul.x);
      if ((a > p2 * 4) || (tc < ul.y)) {
        vertex(c.x + ul.x, c.y + ul.y);
      } else {
        vertex(c.x + ul.x, c.y + tc);
        break all;
      }

      tc = (float) (Math.tan(a) * -ul.y);
      vertex(c.x + tc, c.y + ul.y);
    }
    gl.glEnd();
    gl.glDisable(GL2.GL_POLYGON_SMOOTH);
    checkerr();
  }
Example #8
0
 public void getimage(final Coord ul, final Coord sz, final Callback<BufferedImage> cb) {
   gl.bglSubmit(
       new BGL.Request() {
         public void run(GL2 gl) {
           byte[] buf = new byte[sz.x * sz.y * 4];
           gl.glReadPixels(
               ul.x + tx.x,
               root.sz.y - ul.y - sz.y - tx.y,
               sz.x,
               sz.y,
               GL.GL_RGBA,
               GL2.GL_UNSIGNED_BYTE,
               ByteBuffer.wrap(buf));
           checkerr();
           for (int y = 0; y < sz.y / 2; y++) {
             int to = y * sz.x * 4, bo = (sz.y - y - 1) * sz.x * 4;
             for (int o = 0; o < sz.x * 4; o++, to++, bo++) {
               byte t = buf[to];
               buf[to] = buf[bo];
               buf[bo] = t;
             }
           }
           WritableRaster raster =
               Raster.createInterleavedRaster(
                   new DataBufferByte(buf, buf.length),
                   sz.x,
                   sz.y,
                   4 * sz.x,
                   4,
                   new int[] {0, 1, 2, 3},
                   null);
           cb.done(new BufferedImage(TexI.glcm, raster, false, null));
         }
       });
 }
Example #9
0
 public void frect(Coord ul, Coord sz) {
   ul = tx.add(ul);
   Coord br = ul.add(sz);
   if (ul.x < this.ul.x) ul.x = this.ul.x;
   if (ul.y < this.ul.y) ul.y = this.ul.y;
   if (br.x > this.ul.x + this.sz.x) br.x = this.ul.x + this.sz.x;
   if (br.y > this.ul.y + this.sz.y) br.y = this.ul.y + this.sz.y;
   if ((ul.x >= br.x) || (ul.y >= br.y)) return;
   st.set(cur2d);
   apply();
   gl.glBegin(GL2.GL_QUADS);
   gl.glVertex2i(ul.x, ul.y);
   gl.glVertex2i(br.x, ul.y);
   gl.glVertex2i(br.x, br.y);
   gl.glVertex2i(ul.x, br.y);
   gl.glEnd();
   checkerr();
 }
Example #10
0
 public void poly2(Object... c) {
   st.set(cur2d);
   st.put(States.color, States.vertexcolor);
   apply();
   gl.glBegin(GL2.GL_POLYGON);
   for (int i = 0; i < c.length; i += 2) {
     Coord vc = (Coord) c[i];
     Color col = (Color) c[i + 1];
     gl.glColor4f(
         (col.getRed() / 255.0f),
         (col.getGreen() / 255.0f),
         (col.getBlue() / 255.0f),
         (col.getAlpha() / 255.0f));
     vertex(vc);
   }
   gl.glEnd();
   checkerr();
 }
Example #11
0
  public void ftexrect(Coord ul, Coord sz, GLState s, float tl, float tt, float tr, float tb) {
    ul = tx.add(ul);
    Coord br = ul.add(sz);
    Coord ult = new Coord(0, 0);
    Coord brt = new Coord(sz);
    if (ul.x < this.ul.x) {
      ult.x += this.ul.x - ul.x;
      ul.x = this.ul.x;
    }
    if (ul.y < this.ul.y) {
      ult.y += this.ul.y - ul.y;
      ul.y = this.ul.y;
    }
    if (br.x > this.ul.x + this.sz.x) {
      brt.x -= br.x - (this.ul.x + this.sz.x);
      br.x = this.ul.x + this.sz.x;
    }
    if (br.y > this.ul.y + this.sz.y) {
      brt.y -= br.y - (this.ul.y + this.sz.y);
      br.y = this.ul.y + this.sz.y;
    }
    if ((ul.x >= br.x) || (ul.y >= br.y)) return;

    st.set(cur2d);
    state(s);
    apply();

    float l = tl + ((tr - tl) * ((float) ult.x) / ((float) sz.x));
    float t = tt + ((tb - tt) * ((float) ult.y) / ((float) sz.y));
    float r = tl + ((tr - tl) * ((float) brt.x) / ((float) sz.x));
    float b = tt + ((tb - tt) * ((float) brt.y) / ((float) sz.y));
    gl.glBegin(GL2.GL_QUADS);
    gl.glTexCoord2f(l, b);
    gl.glVertex2i(ul.x, ul.y);
    gl.glTexCoord2f(r, b);
    gl.glVertex2i(br.x, ul.y);
    gl.glTexCoord2f(r, t);
    gl.glVertex2i(br.x, br.y);
    gl.glTexCoord2f(l, t);
    gl.glVertex2i(ul.x, br.y);
    gl.glEnd();
    checkerr();
  }
Example #12
0
 protected void fill(GOut g) {
   BGL gl = g.gl;
   Coord dim = new Coord(tdim, tdim);
   for (int i = 0; i < order.length; i++) {
     ByteBuffer data =
         ByteBuffer.wrap(
             TexI.convert(back, dim, new Coord(order[i][0] * tdim, order[i][1] * tdim), dim));
     gl.glTexImage2D(
         GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X + i,
         0,
         GL.GL_RGBA,
         tdim,
         tdim,
         0,
         GL.GL_RGBA,
         GL.GL_UNSIGNED_BYTE,
         data);
   }
 }
Example #13
0
 public void apply(GOut g) {
   BGL gl = g.gl;
   gl.glFogi(GL2.GL_FOG_MODE, GL2.GL_LINEAR);
   gl.glFogf(GL2.GL_FOG_START, s);
   gl.glFogf(GL2.GL_FOG_END, e);
   gl.glFogfv(GL2.GL_FOG_COLOR, ca, 0);
   gl.glEnable(GL2.GL_FOG);
 }
Example #14
0
 public void getpixel(final Coord c, final Callback<Color> cb) {
   gl.bglSubmit(
       new BGL.Request() {
         public void run(GL2 gl) {
           byte[] buf = new byte[4];
           gl.glReadPixels(
               c.x + tx.x,
               root.sz.y - c.y - tx.y,
               1,
               1,
               GL.GL_RGBA,
               GL2.GL_UNSIGNED_BYTE,
               ByteBuffer.wrap(buf));
           checkerr();
           cb.done(new Color(((int) buf[0]) & 0xff, ((int) buf[1]) & 0xff, ((int) buf[2]) & 0xff));
         }
       });
 }
Example #15
0
 public void unapply(GOut g) {
   BGL gl = g.gl;
   gl.glColor3f(1, 1, 1);
 }
Example #16
0
 public void apply(GOut g) {
   BGL gl = g.gl;
   gl.glColor4fv(ca, 0);
 }
Example #17
0
 public void unapply(GOut g) {
   BGL gl = g.gl;
   gl.glDisable(mode);
 }
Example #18
0
 public void apply(GOut g) {
   BGL gl = g.gl;
   gl.glPolygonOffset(factor, units);
   gl.glEnable(mode);
 }
Example #19
0
 public void unapply(GOut g) {
   BGL gl = g.gl;
   gl.glDisable(GL2.GL_FOG);
 }
Example #20
0
 public void unapply(GOut g) {
   BGL gl = g.gl;
   gl.glSampleCoverage(1.0f, false);
   gl.glDisable(GL.GL_SAMPLE_COVERAGE);
 }
Example #21
0
 public void apply(GOut g) {
   BGL gl = g.gl;
   gl.glEnable(GL.GL_SAMPLE_COVERAGE);
   gl.glSampleCoverage(cov, inv);
 }
Example #22
0
 public void vertex(float x, float y) {
   gl.glVertex2f(x + tx.x, y + tx.y);
 }
Example #23
0
 public void vertex(Coord c) {
   gl.glVertex2i(c.x + tx.x, c.y + tx.y);
 }
Example #24
0
  void rootdraw(GLState.Applier state, UI ui, BGL gl) {
    GLState.Buffer ibuf = new GLState.Buffer(state.cfg);
    gstate.prep(ibuf);
    ostate.prep(ibuf);
    GOut g = new GOut(gl, state.cgl, state.cfg, state, ibuf, new Coord(w, h));
    state.set(ibuf);

    g.state(ostate);
    g.apply();
    gl.glClearColor(0, 0, 0, 1);
    gl.glClear(GL.GL_COLOR_BUFFER_BIT);
    synchronized (ui) {
      ui.draw(g);
    }

    if (Config.dbtext) {
      int y = h - 150;
      FastText.aprintf(
          g,
          new Coord(10, y -= 15),
          0,
          1,
          "FPS: %d (%d%%, %d%% idle)",
          fps,
          (int) (uidle * 100.0),
          (int) (ridle * 100.0));
      Runtime rt = Runtime.getRuntime();
      long free = rt.freeMemory(), total = rt.totalMemory();
      FastText.aprintf(
          g,
          new Coord(10, y -= 15),
          0,
          1,
          "Mem: %,011d/%,011d/%,011d/%,011d",
          free,
          total - free,
          total,
          rt.maxMemory());
      FastText.aprintf(g, new Coord(10, y -= 15), 0, 1, "Tex-current: %d", TexGL.num());
      FastText.aprintf(g, new Coord(10, y -= 15), 0, 1, "GL progs: %d", g.st.numprogs());
      GameUI gi = ui.root.findchild(GameUI.class);
      if ((gi != null) && (gi.map != null)) {
        try {
          FastText.aprintf(
              g, new Coord(10, y -= 15), 0, 1, "MV pos: %s (%s)", gi.map.getcc(), gi.map.camera);
        } catch (Loading e) {
        }
        if (gi.map.rls != null)
          FastText.aprintf(
              g,
              new Coord(10, y -= 15),
              0,
              1,
              "Rendered: %,d+%,d(%,d)",
              gi.map.rls.drawn,
              gi.map.rls.instanced,
              gi.map.rls.instancified);
      }
      if (Resource.remote().qdepth() > 0)
        FastText.aprintf(
            g,
            new Coord(10, y -= 15),
            0,
            1,
            "RQ depth: %d (%d)",
            Resource.remote().qdepth(),
            Resource.remote().numloaded());
    }
    Object tooltip;
    try {
      synchronized (ui) {
        tooltip = ui.root.tooltip(mousepos, ui.root);
      }
    } catch (Loading e) {
      tooltip = "...";
    }
    Tex tt = null;
    if (tooltip != null) {
      if (tooltip instanceof Text) {
        tt = ((Text) tooltip).tex();
      } else if (tooltip instanceof Tex) {
        tt = (Tex) tooltip;
      } else if (tooltip instanceof Indir<?>) {
        Indir<?> t = (Indir<?>) tooltip;
        Object o = t.get();
        if (o instanceof Tex) tt = (Tex) o;
      } else if (tooltip instanceof String) {
        if (((String) tooltip).length() > 0) tt = (Text.render((String) tooltip)).tex();
      }
    }
    if (tt != null) {
      Coord sz = tt.sz();
      Coord pos = mousepos.add(sz.inv());
      if (pos.x < 0) pos.x = 0;
      if (pos.y < 0) pos.y = 0;
      g.chcolor(244, 247, 21, 192);
      g.rect(pos.add(-3, -3), sz.add(6, 6));
      g.chcolor(35, 35, 35, 192);
      g.frect(pos.add(-2, -2), sz.add(4, 4));
      g.chcolor();
      g.image(tt, pos);
    }
    ui.lasttip = tooltip;
    Resource curs = ui.root.getcurs(mousepos);
    if (curs != null) {
      if (cursmode == "awt") {
        if (curs != lastcursor) {
          try {
            setCursor(makeawtcurs(curs.layer(Resource.imgc).img, curs.layer(Resource.negc).cc));
            lastcursor = curs;
          } catch (Exception e) {
            cursmode = "tex";
          }
        }
      } else if (cursmode == "tex") {
        Coord dc = mousepos.add(curs.layer(Resource.negc).cc.inv());
        g.image(curs.layer(Resource.imgc), dc);
      }
    }
    state.clean();
    GLObject.disposeall(state.cgl, gl);
  }
Example #25
0
 public static void checkerr(BGL gl) {
   gl.bglCheckErr();
 }