示例#1
0
  /** paint the portal using gl. */
  public void paint(GL gl, GLDrawable glc) {

    if (fill != null) {
      setColor(gl, fill);
      gl.glDisable(GL.GL_TEXTURE_2D);
    }
    gl.glLineWidth(lineWidth());
    gl.glBegin(GL.GL_LINES); // draw each wall
    for (int i = 0; i < pts2d.size(); i++) {
      Point2D p = (Point2D) (pts2d.get(i));
      gl.glVertex2d(p.x, p.y);
    }
    gl.glEnd();

    if (pts2d.size() == 4) {
      /* Connect mid point of the two line segments with dotted line*/
      gl.glLineStipple(1, (short) 0x0F0F);
      gl.glEnable(GL.GL_LINE_STIPPLE);
      gl.glLineWidth(1);
      gl.glBegin(GL.GL_LINES);
      Point2D mid = pts2d.get(0).interp(pts2d.get(1), 0.5);
      gl.glVertex2d(mid.x, mid.y);
      mid = pts2d.get(2).interp(pts2d.get(3), 0.5);
      gl.glVertex2d(mid.x, mid.y);
      gl.glEnd();
      gl.glDisable(GL.GL_LINE_STIPPLE);
    }
  }
示例#2
0
 /** Creates a cube at 0,0 in the viewport. */
 void createCube() {
   GL.glNewList(cubeListIndexBase, GL.GL_COMPILE);
   GL.glBegin(GL.GL_QUADS);
   // front
   GL.glColor3f(0.0f, 1.0f, 0.0f);
   GL.glVertex3f(-0.5f, -0.5f, 0.5f); // bottom left
   GL.glColor3f(0.0f, 0.0f, 1.0f);
   GL.glVertex3f(0.5f, -0.5f, 0.5f); // bottom right
   GL.glColor3f(1.0f, 1.0f, 0.0f);
   GL.glVertex3f(0.5f, 0.5f, 0.5f); // top right
   GL.glColor3f(1.0f, 0.0f, 0.0f);
   GL.glVertex3f(-0.5f, 0.5f, 0.5f); // top left
   // back
   GL.glColor3f(0.0f, 0.0f, 1.0f);
   GL.glVertex3f(-0.5f, -0.5f, -0.5f); // bottom left
   GL.glColor3f(0.0f, 1.0f, 0.0f);
   GL.glVertex3f(0.5f, -0.5f, -0.5f); // bottom right
   GL.glColor3f(1.0f, 0.0f, 0.0f);
   GL.glVertex3f(0.5f, 0.5f, -0.5f); // top right
   GL.glColor3f(1.0f, 1.0f, 0.0f);
   GL.glVertex3f(-0.5f, 0.5f, -0.5f); // top left
   // left
   GL.glColor3f(0.0f, 0.0f, 1.0f);
   GL.glVertex3f(-0.5f, -0.5f, -0.5f); // bottom left
   GL.glColor3f(0.0f, 1.0f, 0.0f);
   GL.glVertex3f(-0.5f, -0.5f, 0.5f); // bottom right
   GL.glColor3f(1.0f, 0.0f, 0.0f);
   GL.glVertex3f(-0.5f, 0.5f, 0.5f); // top right
   GL.glColor3f(1.0f, 1.0f, 0.0f);
   GL.glVertex3f(-0.5f, 0.5f, -0.5f); // top left
   // right
   GL.glColor3f(0.0f, 0.0f, 1.0f);
   GL.glVertex3f(0.5f, -0.5f, 0.5f); // bottom left
   GL.glColor3f(0.0f, 1.0f, 0.0f);
   GL.glVertex3f(0.5f, -0.5f, -0.5f); // bottom right
   GL.glColor3f(1.0f, 0.0f, 0.0f);
   GL.glVertex3f(0.5f, 0.5f, -0.5f); // top right
   GL.glColor3f(1.0f, 1.0f, 0.0f);
   GL.glVertex3f(0.5f, 0.5f, 0.5f); // top left
   // top
   GL.glColor3f(1.0f, 0.0f, 0.0f);
   GL.glVertex3f(0.5f, 0.5f, -0.5f);
   GL.glColor3f(1.0f, 1.0f, 0.0f);
   GL.glVertex3f(-0.5f, 0.5f, -0.5f);
   GL.glColor3f(1.0f, 0.0f, 0.0f);
   GL.glVertex3f(-0.5f, 0.5f, 0.5f);
   GL.glColor3f(1.0f, 1.0f, 0.0f);
   GL.glVertex3f(0.5f, 0.5f, 0.5f);
   // bottom
   GL.glColor3f(0.0f, 0.0f, 1.0f);
   GL.glVertex3f(0.5f, -0.5f, 0.5f);
   GL.glColor3f(0.0f, 1.0f, 0.0f);
   GL.glVertex3f(-0.5f, -0.5f, 0.5f);
   GL.glColor3f(0.0f, 0.0f, 1.0f);
   GL.glVertex3f(-0.5f, -0.5f, -0.5f);
   GL.glColor3f(0.0f, 1.0f, 0.0f);
   GL.glVertex3f(0.5f, -0.5f, -0.5f);
   GL.glEnd();
   GL.glEndList();
 }
示例#3
0
  public void paintTex(int glid, int target, int w, int h, int color) {
    float r, g, b, a;
    int ir, ig, ib, ia;

    ia = (color >> 24) & 0xff;
    ir = (color >> 16) & 0xff;
    ig = (color >> 8) & 0xff;
    ib = color & 0xff;

    a = ia / 255.0f;
    r = ir / 255.0f;
    g = ig / 255.0f;
    b = ib / 255.0f;

    pushFramebuffer();
    setFramebuffer(FBO);
    FBO.setDrawBuffer(target, glid);

    saveView();
    setOrthographicView(w, h);
    gl.glColor4f(r, g, b, a);
    gl.glBegin(GL.GL_QUADS);
    gl.glVertex2f(0.0f, 0.0f);
    gl.glVertex2f(w, 0.0f);
    gl.glVertex2f(w, h);
    gl.glVertex2f(0.0f, h);
    gl.glEnd();
    restoreView();

    popFramebuffer();
  }
示例#4
0
文件: GOut.java 项目: krvd/hnh_union
 public void line(Coord c1, Coord c2, double w) {
   texsel(-1);
   gl.glLineWidth((float) w);
   gl.glBegin(GL.GL_LINES);
   glcolor();
   vertex(c1);
   vertex(c2);
   gl.glEnd();
   checkerr();
 }
示例#5
0
文件: GOut.java 项目: krvd/hnh_union
 public void frect(Coord c1, Coord c2, Coord c3, Coord c4) {
   glcolor();
   texsel(-1);
   gl.glBegin(GL.GL_QUADS);
   vertex(c1);
   vertex(c2);
   vertex(c3);
   vertex(c4);
   gl.glEnd();
   checkerr();
 }
示例#6
0
文件: GOut.java 项目: krvd/hnh_union
 public void frect(Coord ul, Coord sz) {
   glcolor();
   texsel(-1);
   gl.glBegin(GL.GL_QUADS);
   vertex(ul);
   vertex(ul.add(new Coord(sz.x, 0)));
   vertex(ul.add(sz));
   vertex(ul.add(new Coord(0, sz.y)));
   gl.glEnd();
   checkerr();
 }
示例#7
0
  public void copyTex(GLTexture srcTex, GLTexture destTex) {
    float uscale = srcTex.getMaxTextureCoordS();
    float vscale = srcTex.getMaxTextureCoordT();

    float cx = 0.0f;
    float sx = +1.0f;
    if (destTex.isFlippedX()) {
      cx = 1.0f;
      sx = -1.0f;
    }

    float cy = 0.0f;
    float sy = +1.0f;
    if (destTex.isFlippedY()) {
      cy = 1.0f;
      sy = -1.0f;
    }

    gl.glEnable(srcTex.getTextureTarget());

    gl.glActiveTexture(GL.GL_TEXTURE0);
    gl.glBindTexture(srcTex.getTextureTarget(), srcTex.getTextureID());

    pushFramebuffer();
    setFramebuffer(FBO);
    FBO.setDrawBuffer(destTex.getTextureTarget(), destTex.getTextureID());

    saveView();
    setOrthographicView(destTex.width, destTex.height);
    gl.glEnable(srcTex.getTextureTarget());
    gl.glActiveTexture(GL.GL_TEXTURE0);
    gl.glBindTexture(srcTex.getTextureTarget(), srcTex.getTextureID());
    gl.glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
    gl.glBegin(GL.GL_QUADS);
    gl.glTexCoord2f((cx + sx * 0.0f) * uscale, (cy + sy * 0.0f) * vscale);
    gl.glVertex2f(0.0f, 0.0f);

    gl.glTexCoord2f((cx + sx * 1.0f) * uscale, (cy + sy * 0.0f) * vscale);
    gl.glVertex2f(srcTex.width, 0.0f);

    gl.glTexCoord2f((cx + sx * 1.0f) * uscale, (cy + sy * 1.0f) * vscale);
    gl.glVertex2f(srcTex.width, srcTex.height);

    gl.glTexCoord2f((cx + sx * 0.0f) * uscale, (cy + sy * 1.0f) * vscale);
    gl.glVertex2f(0.0f, srcTex.height);
    gl.glEnd();
    gl.glBindTexture(srcTex.getTextureTarget(), 0);
    restoreView();

    popFramebuffer();
  }
示例#8
0
文件: GOut.java 项目: krvd/hnh_union
 public void fellipse(Coord c, Coord r, int a1, int a2) {
   glcolor();
   texsel(-1);
   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)));
   }
   double a = (a2 * Math.PI * 2) / 360.0;
   vertex(c.add((int) (Math.cos(a) * r.x), -(int) (Math.sin(a) * r.y)));
   gl.glEnd();
   checkerr();
 }
示例#9
0
文件: GOut.java 项目: krvd/hnh_union
 public void ftriangle(Coord center, int size) {
   if (size < 1) return;
   double sqrt3 = Math.sqrt(3);
   double Orad = (sqrt3 * size) / 3;
   double Irad = (sqrt3 * size) / 6;
   Coord c1, c2, c3;
   c1 = new Coord(center.x, center.y - (int) Orad);
   c2 = new Coord(center.x + (int) (size / 2) - 1, center.y + (int) Irad);
   c3 = new Coord(center.x - (int) (size / 2) + 1, center.y + (int) Irad);
   glcolor();
   texsel(-1);
   gl.glBegin(GL.GL_TRIANGLE_STRIP);
   vertex(c1);
   vertex(c2);
   vertex(c3);
   gl.glEnd();
   checkerr();
 }
示例#10
0
  private void renderOneside(Point2D a, Point2D b, GL gl, double d) {
    gl.glClear(0);
    Vector3D t = new Vector3D(b.x - a.x, 0, b.y - a.y);
    Vector3D n = new Vector3D(0, 1, 0);
    Vector3D cross = n.cross(t);
    gl.glNormal3d(cross.x, cross.y, cross.z);

    // Texture adjustment vars
    double length =
        scale * Math.sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y)) / 100 + 0.1;
    double height = scale;

    // draw the 4 points of it
    gl.glBegin(GL.GL_POLYGON);
    gl.glTexCoord2d(0, 0);
    gl.glVertex3d(a.x, d, a.y);
    gl.glTexCoord2d(0, height);
    gl.glVertex3d(a.x, d + 100, a.y);
    gl.glTexCoord2d(length, height);
    gl.glVertex3d(b.x, d + 100, b.y);
    gl.glTexCoord2d(length, 0);
    gl.glVertex3d(b.x, d, b.y);
    gl.glEnd();
  }