Example #1
0
  public void display(GLAutoDrawable drawable) {
    GL2 gl = drawable.getGL().getGL2();
    //
    gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
    gl.glPushMatrix();
    gl.glRotatef(20.0f, 1.0f, 0.0f, 0.0f);

    gl.glPushMatrix();
    gl.glTranslatef(-0.75f, 0.5f, 0.0f);
    gl.glRotatef(90.0f, 1.0f, 0.0f, 0.0f);

    glut.glutSolidTorus(0.275f, 0.85f, 20, 20);
    gl.glPopMatrix();

    gl.glPushMatrix();
    gl.glTranslatef(-0.75f, -0.5f, 0.0f);
    gl.glRotatef(270.0f, 1.0f, 0.0f, 0.0f);
    glut.glutSolidCone(1.0f, 2.0f, 20, 20);
    gl.glPopMatrix();

    gl.glPushMatrix();
    gl.glTranslatef(0.75f, 0.0f, -1.0f);
    glut.glutSolidSphere(1.0f, 20, 20);
    gl.glPopMatrix();

    gl.glPopMatrix();
    gl.glFlush();
  }
Example #2
0
  public void drawTextureToOffScreenTexture(int texId, int attachment)
        // public void drawTextureToOffScreenTextureUsingShader(Texture tex, int attachment, Program
        // program)
      {
    GL2 gl = getGL();

    // program.bind(gl);

    gl.glBindTexture(GL_TEXTURE_2D, texId);
    // gl.glBindTexture(GL_TEXTURE_2D, tex.getTextureObject());
    // gl.glDrawBuffer(attachment);
    gl.glBindFramebuffer(GL_FRAMEBUFFER, attachment); // think this is the new way...

    gl.glEnable(GL_TEXTURE_2D);
    // gl.glActiveTexture(GL_TEXTURE0);
    gl.glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);

    gl.glViewport(0, 0, fboWidth, fboHeight);

    // gl.glUniform1i(program.uniform("theTexture"), 0);
    // set projection to ortho
    gl.glMatrixMode(GL_PROJECTION);
    gl.glTranslatef(1f, 1f, 1f);

    gl.glPushMatrix();
    {
      gl.glLoadIdentity();
      RenderUtils.getGLU().gluOrtho2D(0, fboWidth, fboHeight, 0);

      gl.glMatrixMode(gl.GL_MODELVIEW);

      gl.glPushMatrix();
      {
        gl.glLoadIdentity();

        gl.glColor4f(1f, 1f, 1f, 1f);
        drawSquare(gl, 0, 0, fboWidth, fboHeight);
      }
      gl.glPopMatrix();

      gl.glMatrixMode(gl.GL_PROJECTION);
    }
    gl.glPopMatrix();

    gl.glMatrixMode(gl.GL_MODELVIEW);

    gl.glDisable(GL_TEXTURE_2D);
    // program.unbind(gl);
  }
  private void renderBlast(GL2 gl) {
    GLU glu = new GLU();

    Shader shader = Shader.get("dissolve");
    if (shader != null) {
      shader.enable(gl);

      shader.setSampler(gl, "cloudSampler", 0);
      shader.setUniform(gl, "dissolveFactor", 1.0f - ((float) blastDuration / 60.0f));
    }

    gl.glEnable(GL2.GL_TEXTURE_2D);

    GLUquadric sphere = glu.gluNewQuadric();

    glu.gluQuadricDrawStyle(sphere, GLU.GLU_FILL);
    glu.gluQuadricTexture(sphere, true);

    gl.glPushMatrix();
    {
      noiseSampler.bind(gl);
      noiseSampler.setTexParameterf(gl, GL2.GL_TEXTURE_MAX_ANISOTROPY_EXT, 16);

      gl.glTranslatef(bound.c.x, bound.c.y, bound.c.z);

      glu.gluSphere(sphere, blastRadius, 24, 24);
    }
    gl.glPopMatrix();
  }
  private void drawStar(GL2 gl, GLAutoDrawable drawable, Float x, Float y, Float z) {
    // Pushing to matrix stack
    gl.glPushMatrix();

    // STAR
    // Moves the figure in the (x, y, z)-axis
    gl.glTranslatef(x, y, z);

    // BEGIN Star
    gl.glBegin(GL_LINE_LOOP);

    // Pushing to attribute stack
    gl.glPushAttrib(GL_ALL_ATTRIB_BITS);

    // Set color to GREEN
    gl.glColor3f(0.0f, 1.0f, 0.0f);

    // Draw the sides
    gl.glVertex3f(0.0f, 1.0f, 0.0f);
    gl.glVertex3f(0.2f, 0.2f, 0.0f);
    gl.glVertex3f(1.0f, 0.0f, 0.0f);
    gl.glVertex3f(0.2f, -0.2f, 0.0f);
    gl.glVertex3f(0.0f, -1.0f, 0.0f);
    gl.glVertex3f(-0.2f, -0.2f, 0.0f);
    gl.glVertex3f(-1.0f, 0.0f, 0.0f);
    gl.glVertex3f(-0.2f, 0.2f, 0.0f);

    // END Star
    gl.glEnd();

    // Popping state
    gl.glPopAttrib();
    gl.glPopMatrix();
  }
Example #5
0
 public void render2d(GL2 g) {
   for (Entry<EntityData, TileEntity> e : entities.entrySet()) {
     EntityData key = e.getKey();
     TileEntity entity = e.getValue();
     g.glPushMatrix();
     switch (key.getType()) {
       case VBORDER:
         g.glRotatef(90, 0, 0, 1);
         BorderData vBorder = (BorderData) entity;
         if (Globals.upCamera) {
           vBorder.render(g, this);
         }
         g.glColor3f(1, 1, 1);
         break;
       case HBORDER:
         BorderData hBorder = (BorderData) entity;
         if (Globals.upCamera) {
           hBorder.render(g, this);
         }
         g.glColor3f(1, 1, 1);
         break;
     }
     g.glPopMatrix();
     g.glColor3f(1, 1, 1);
   }
 }
Example #6
0
  /*
   * sets up selection mode, name stack, and projection matrix for picking.
   * Then the objects are drawn.
   */
  private void pickRects(GL2 gl) {
    int[] selectBuf = new int[BUFSIZE];
    IntBuffer selectBuffer = GLBuffers.newDirectIntBuffer(BUFSIZE);
    int hits;
    int viewport[] = new int[4];
    // int x, y;

    gl.glGetIntegerv(GL.GL_VIEWPORT, viewport, 0);

    gl.glSelectBuffer(BUFSIZE, selectBuffer);
    gl.glRenderMode(GL2.GL_SELECT);

    gl.glInitNames();
    gl.glPushName(-1);

    gl.glMatrixMode(GL2.GL_PROJECTION);
    gl.glPushMatrix();
    gl.glLoadIdentity();
    /* create 5x5 pixel picking region near cursor location */
    glu.gluPickMatrix(
        (double) pickPoint.x,
        (double) (viewport[3] - pickPoint.y), //
        5.0,
        5.0,
        viewport,
        0);
    gl.glOrtho(0.0, 8.0, 0.0, 8.0, -0.5, 2.5);
    drawRects(gl, GL2.GL_SELECT);
    gl.glPopMatrix();
    gl.glFlush();

    hits = gl.glRenderMode(GL2.GL_RENDER);
    selectBuffer.get(selectBuf);
    processHits(hits, selectBuf);
  }
Example #7
0
  // private void pickSquares(GL gl, int button, int state, int x, int y)
  private void pickSquares(GL2 gl) {
    int selectBuf[] = new int[BUFSIZE];
    IntBuffer selectBuffer = IntBuffer.wrap(selectBuf);
    int hits;
    int viewport[] = new int[4];

    // if (button != GLUT_LEFT_BUTTON || state != GLUT_DOWN) return;

    gl.glGetIntegerv(GL2.GL_VIEWPORT, viewport, 0);

    gl.glSelectBuffer(BUFSIZE, selectBuffer);
    gl.glRenderMode(GL2.GL_SELECT);

    gl.glInitNames();
    gl.glPushName(0);

    gl.glMatrixMode(GL2.GL_PROJECTION);
    gl.glPushMatrix();
    gl.glLoadIdentity();
    /* create 5x5 pixel picking region near cursor location */
    glu.gluPickMatrix(
        (double) pickPoint.x, (double) (viewport[3] - pickPoint.y), 5.0, 5.0, viewport, 0);
    glu.gluOrtho2D(0.0, 3.0, 0.0, 3.0);
    drawSquares(gl, GL2.GL_SELECT);

    gl.glMatrixMode(GL2.GL_PROJECTION);
    gl.glPopMatrix();
    gl.glFlush();

    hits = gl.glRenderMode(GL2.GL_RENDER);
    selectBuffer.get(selectBuf);
    processHits(hits, selectBuf);
  }
Example #8
0
  public void display(GLAutoDrawable drawable) {
    GL2 gl = drawable.getGL().getGL2();
    //
    double eqn[] = {0.0, 1.0, 0.0, 0.0};
    double eqn2[] = {1.0, 0.0, 0.0, 0.0};

    gl.glClear(GL.GL_COLOR_BUFFER_BIT);

    gl.glColor3f(1.0f, 1.0f, 1.0f);
    gl.glPushMatrix();
    gl.glTranslatef(0.0f, 0.0f, -5.0f);

    /* clip lower half -- y < 0 */
    gl.glClipPlane(GL2.GL_CLIP_PLANE0, eqn, 0);
    gl.glEnable(GL2.GL_CLIP_PLANE0);
    /* clip left half -- x < 0 */
    gl.glClipPlane(GL2.GL_CLIP_PLANE1, eqn2, 0);
    gl.glEnable(GL2.GL_CLIP_PLANE1);

    gl.glRotatef(90.0f, 1.0f, 0.0f, 0.0f);
    glut.glutWireSphere(1.0, 20, 16);
    gl.glPopMatrix();

    gl.glFlush();
  }
  /**
   * Draw the object and all of its descendants recursively.
   *
   * <p>TODO: Complete this method
   *
   * @param gl
   */
  public void draw(GL2 gl) {

    // don't draw if it is not showing
    if (!amShowing) {
      return;
    }

    // TODO: draw the object and all its children recursively
    // setting the model transform appropriately

    // Call drawSelf() to draw the object itself
    gl.glMatrixMode(GL2.GL_MODELVIEW);
    {
      gl.glPushMatrix();
      {
        gl.glTranslated(myTranslation[0], myTranslation[1], 0);
        gl.glScaled(myScale, myScale, 1);
        gl.glRotated(myRotation, 0, 0, 1);
        drawSelf(gl);
        for (GameObject child : myChildren) {
          child.draw(gl);
        }
      }
      gl.glPopMatrix();
    }
  }
  /* (non-Javadoc)
   * @see org.sam.jogl.Dibujable#draw(javax.media.opengl.GL2)
   */
  @Override
  public void draw(GL2 gl) {
    gl.glPushMatrix();

    mt_array[0] = transformMatrix.m00;
    mt_array[1] = transformMatrix.m10;
    mt_array[2] = transformMatrix.m20;
    mt_array[3] = transformMatrix.m30;
    mt_array[4] = transformMatrix.m01;
    mt_array[5] = transformMatrix.m11;
    mt_array[6] = transformMatrix.m21;
    mt_array[7] = transformMatrix.m31;
    mt_array[8] = transformMatrix.m02;
    mt_array[9] = transformMatrix.m12;
    mt_array[10] = transformMatrix.m22;
    mt_array[11] = transformMatrix.m32;
    mt_array[12] = transformMatrix.m03;
    mt_array[13] = transformMatrix.m13;
    mt_array[14] = transformMatrix.m23;
    mt_array[15] = transformMatrix.m33;

    gl.glMultMatrixf(mt_array, 0);
    // drawBox(gl);
    child.draw(gl);
    gl.glPopMatrix();
  }
  private void drawSquare(GL2 gl, GLAutoDrawable drawable, Float x, Float y, Float z) {
    // Pushing to matrix stack
    gl.glPushMatrix();

    // SQUARE
    // Moves the figure in the (x, y, z)-axis
    gl.glTranslatef(x, y, z);

    // Makes so that square is filled in
    gl.glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);

    // BEGIN Square
    gl.glBegin(GL_QUADS);

    // Pushing to attribute stack
    gl.glPushAttrib(GL_ALL_ATTRIB_BITS);

    // Set color to BLUE
    gl.glColor3f(0.0f, 0.0f, 1.0f);

    // The Quad
    gl.glVertex3f(1.0f, 1.0f, 1.0f);
    gl.glVertex3f(-1.0f, 1.0f, 1.0f);
    gl.glVertex3f(-1.0f, -1.0f, 1.0f);
    gl.glVertex3f(1.0f, -1.0f, 1.0f);

    // END Square
    gl.glEnd();

    // Popping state
    gl.glPopAttrib();
    gl.glPopMatrix();
  }
Example #12
0
  public void draw(GL2 gl, GLU glu) {
    gl.glColor3f(1f, 0f, .25f);

    // Lamp Stem, cylindrical, a little smaller at the top.
    gl.glPushMatrix();
    gl.glRotatef(-90f, 1f, 0f, 0f); // stand upright (Y)
    glu.gluCylinder(quadric, 1., 1, 3., 10, 1);
    gl.glPopMatrix();

    // Table Top
    gl.glPushMatrix();
    gl.glTranslated(0, 3, 0);
    gl.glRotatef(-90f, 100f, 0f, 0f); // stand upright (Y)
    glu.gluDisk(quadric, 0, 4., 15, 5); // also to be flipped
    gl.glPopMatrix();
  }
  public void display(GLAutoDrawable drawable) {
    GL2 gl = drawable.getGL().getGL2();

    gl.glMaterialfv(GL.GL_FRONT_AND_BACK, GL2.GL_AMBIENT_AND_DIFFUSE, color, 0);
    gl.glRotated(rotateX.getValue(), 1, 0, 0);
    gl.glRotated(rotateY.getValue(), 0, 1, 0);
    gl.glRotated(rotateZ.getValue(), 0, 0, 1);
    gl.glPushMatrix();
    gl.glTranslated(translateX.getValue(), translateY.getValue(), translateZ.getValue());
    gl.glPushMatrix();
    gl.glRotated(90, 1, 0, 0);
    gl.glTranslated(0, 0, -height / 2);
    glut.glutSolidCylinder(radius, height, 32, 2);
    gl.glPopMatrix();
    super.display(drawable);
    gl.glPopMatrix();
  }
  @Override
  public void display(GLAutoDrawable drawable) {
    GL2 gl = drawable.getGL().getGL2();
    GLUT glut = new GLUT();
    // limpa o buer
    gl.glClear(GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT);
    // dene que a matrix é a de modelo
    gl.glMatrixMode(GL2.GL_MODELVIEW);
    gl.glLoadIdentity();
    gl.glScalef(delta, delta, delta); // faça a escala de todos objetos

    gl.glPushMatrix(); // armazena a matriz corrente
    gl.glTranslatef(-3, 0, 0);
    gl.glRotatef(beta, 0, 1, 0);
    gl.glRotatef(alpha, 1, 0, 0);
    gl.glColor3f(1, 1, 0);
    glut.glutWireSphere(1, 20, 20);

    // desenha um piso sob a esfera
    gl.glTranslatef(0, -1, 0);
    gl.glScalef(4, 0.1f, 4);
    gl.glColor3f(0, 0, 1);
    glut.glutSolidCube(1.0f);

    gl.glPopMatrix(); // restaura a matriz anterior

    gl.glPushMatrix(); // armazena a matriz corrente
    gl.glTranslatef(3, 0, 0);
    gl.glRotatef(beta, 0, 1, 0);
    gl.glRotatef(alpha, 1, 0, 0);
    gl.glColor3f(1, 0, 0);
    glut.glutWireSphere(1, 20, 20);

    // desenha um piso sob a esfera
    gl.glTranslatef(0, -1, 0);
    gl.glScalef(4, 0.1f, 4);
    gl.glColor3f(0, 1, 0);
    glut.glutSolidCube(1.0f);

    gl.glPopMatrix(); // restaura a matriz anterior
    // força o desenho das primitivas
    gl.glFlush();
  }
 @Override
 public void draw(int depth) {
   // only render the sphere if this node is at the given depth
   if (((depth < 0) && (Math.abs(depth) >= this.depth)) || depth == this.depth) {
     GL2 gl = GLContext.getCurrent().getGL().getGL2();
     gl.glPushMatrix();
     gl.glTranslated(center.x, center.y, center.z);
     JDraw3D.jDrawSphere(radius, 10, 10);
     gl.glPopMatrix();
   }
 }
Example #16
0
 public void render(GLAutoDrawable drawable) {
   GL2 gl = drawable.getGL().getGL2();
   gl.glPushMatrix();
   gl.glTranslated(
       body.getPosition().get0(), body.getPosition().get1(), body.getPosition().get2());
   GLUquadric bulletGeom = glu.gluNewQuadric();
   glu.gluQuadricDrawStyle(bulletGeom, GLU.GLU_FILL);
   glu.gluQuadricNormals(bulletGeom, GLU.GLU_SMOOTH);
   glu.gluDisk(bulletGeom, 0.3, 0.4, 5, 5);
   gl.glPopMatrix();
 }
  @Override
  public void beginPoly(int windingRule) {
    /*
     * pen hangs down and to the right. See java.awt.Graphics
     */
    gl.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
    gl.glPushMatrix();
    gl.glTranslatef(0.5f, 0.5f, 0);

    super.beginPoly(windingRule);
  }
  public void selfDraw(GL2 gl) {

    texture.enable(gl);
    texture.bind(gl);

    gl.glTranslatef(8.65f, -0.8f, 8.8f);

    gl.glPushMatrix();
    gl.glScalef(3f, 3f, 3f);
    gl.glCallList(startList);
    gl.glPopMatrix();
  }
Example #19
0
  /**
   * Render the arrow as a line and a _head.
   *
   * @param gl OpenGL Context
   */
  public void render(GL2 gl) {
    // save Light Attributes and remove lighting to get "full" RGB colors
    // gl.glPushAttrib( GL2.GL_LIGHTING_BIT );
    gl.glPushAttrib(GL2.GL_ENABLE_BIT);
    gl.glDisable(GL2.GL_LIGHTING);

    if (_fg_verb) {
      System.out.println(
          "Arrow pos="
              + _pos.toString()
              + "  angZ1="
              + _angZ1
              + "  angY2="
              + _angY2
              + "  length="
              + _length);
      _fg_verb = false;
    }

    // save transformation matrix, then translate and scale.
    gl.glPushMatrix();
    gl.glTranslatef(_pos.x, _pos.y, _pos.z);
    gl.glRotatef(Matrix.rad2Deg(_angZ1), 0, 0, 1); // rotation around 0z
    gl.glRotatef(Matrix.rad2Deg(_angY2), 0, 1, 0); // rotation around 0y

    // draw line
    gl.glColor4f(_color_fg.x, _color_fg.y, _color_fg.z, _color_fg.w);
    gl.glLineWidth(1.0f);
    gl.glBegin(GL.GL_LINES);
    {
      gl.glVertex3f(0, 0, 0);
      gl.glVertex3f(_length, 0, 0);
    }
    gl.glEnd();

    // draw head
    gl.glPolygonMode(GL.GL_FRONT_AND_BACK, GL2GL3.GL_FILL);
    gl.glTranslatef(_length, 0, 0);
    gl.glBegin(GL.GL_TRIANGLES);
    {
      for (float[] face : _head_faces) {
        gl.glVertex3f(face[0], face[1], face[2]);
        gl.glVertex3f(face[3], face[4], face[5]);
        gl.glVertex3f(face[6], face[7], face[8]);
      }
    }
    gl.glEnd();

    // restore transformation matrix
    gl.glPopMatrix();
    // restore attributes
    gl.glPopAttrib();
  }
  void drawPart(Part part, double x, double y, double z, double r) {
    gl.glPushMatrix();
    gl.glTranslated(x, y, z);

    // TODO
    gl.glTranslated(0, part.h - part.w / 2, 0);
    gl.glRotated(r, 1, 0, 0);
    gl.glTranslated(0, part.w / 2 - part.h, 0);

    drawCuboid(part);
    gl.glPopMatrix();
  }
  public void draw() {
    // Clear GL state
    gl.glDisable(GL_LIGHTING);
    gl.glDisable(GL_DEPTH);
    gl.glMatrixMode(GL_MODELVIEW);
    gl.glPushMatrix();
    gl.glLoadIdentity();
    gl.glMatrixMode(GL_PROJECTION);
    gl.glPushMatrix();
    gl.glLoadIdentity();

    gl.glClearColor(0.8f, 0.2f, 0.2f, 1.0f);

    gl.glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);

    gl.glPointSize(1.0f);

    // Set the viewport
    glu.gluOrtho2D(xMin, xMax, yMin, yMax);

    gl.glBegin(GL_POINTS);

    for (int x = (int) (xMin); x < xMax; x++)
      for (int y = (int) (yMin); y < yMax; y++) {
        gl.glColor3d(viewPort[x][y].r, viewPort[x][y].g, viewPort[x][y].b);
        gl.glVertex2d(x + 0.5, y + 0.5);
      }

    gl.glEnd();

    // Restore state
    gl.glMatrixMode(GL_MODELVIEW);
    gl.glPopMatrix();
    gl.glMatrixMode(GL_PROJECTION);
    gl.glPopMatrix();

    gl.glEnable(GL_LIGHTING);
    gl.glEnable(GL_DEPTH);
  }
  @Override
  public void render(GL2 gl, float trajectory) {
    //		flat = true;

    gl.glPushMatrix();
    {
      gl.glTranslatef(c.x, c.y, c.z);
      gl.glRotatef(trajectory, 0, -1, 0);
      gl.glRotatef((flat) ? -90 : 0, 1, 0, 0);
      gl.glRotatef(rotation, 0, 0, 1);

      Vec3 scale = new Vec3(0.75f, 2.0f, 0);
      if (miniature) scale = scale.multiply(0.5f);
      scale = scale.multiply(0.8f);

      gl.glScalef(scale.x, scale.y, scale.z);
      gl.glTranslatef(0, 0.2f, 0);

      gl.glDepthMask(false);
      gl.glDisable(GL_LIGHTING);
      gl.glEnable(GL_BLEND);
      gl.glEnable(GL_TEXTURE_2D);

      gl.glBlendFunc(GL2.GL_SRC_ALPHA, GL2.GL_ONE);

      whiteSpark.bind(gl);

      gl.glColor3f(colors[color][0], colors[color][1], colors[color][2]);

      gl.glBegin(GL_QUADS);
      {
        gl.glTexCoord2f(1.0f, 1.0f);
        gl.glVertex3f(-0.5f, -0.5f, 0.0f);
        gl.glTexCoord2f(1.0f, 0.0f);
        gl.glVertex3f(-0.5f, 0.5f, 0.0f);
        gl.glTexCoord2f(0.0f, 0.0f);
        gl.glVertex3f(0.5f, 0.5f, 0.0f);
        gl.glTexCoord2f(0.0f, 1.0f);
        gl.glVertex3f(0.5f, -0.5f, 0.0f);
      }
      gl.glEnd();

      gl.glDisable(GL_BLEND);
      gl.glEnable(GL_LIGHTING);
      gl.glDepthMask(true);

      gl.glColor3f(1, 1, 1);
    }
    gl.glPopMatrix();
  }
Example #23
0
  public void make(FloatBuffer whiteMaterial, FloatBuffer blackMaterial) {
    this.whiteMaterial = whiteMaterial;
    this.blackMaterial = blackMaterial;

    drawSheet();
    for (int i = -2; i <= 2; i++) {
      gl.glPushMatrix();
      // gl.glLoadIdentity();
      gl.glTranslatef(2.f * i, 2.f * i, 0.f);
      drawCube();
      setText("Object");
      gl.glPopMatrix();
    }
  }
  // Support Methods
  private void drawPyramid(GL2 gl, GLAutoDrawable drawable, Float x, Float y, Float z) {
    // Pushing to matrix stack
    gl.glPushMatrix();

    // PYRAMID
    // Moves the figure in the (x, y, z)-axis
    gl.glTranslatef(x, y, z);

    // Rotates the pyramid, just for "fun"
    gl.glRotatef(-55.0f, 0.0f, 1.0f, 0.0f);

    // Makes only the outlines
    gl.glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);

    // BEGIN Pyramid
    gl.glBegin(GL_TRIANGLES);

    // Pushing current color to stack
    gl.glPushAttrib(GL_ALL_ATTRIB_BITS);

    // Set color to RED
    gl.glColor3f(1.0f, 0.0f, 0.0f);

    // Front triangle
    gl.glVertex3f(0.0f, 1.0f, 0.0f);
    gl.glVertex3f(-1.0f, -1.0f, 1.0f);
    gl.glVertex3f(1.0f, -1.0f, 1.0f);

    // Right triangle
    gl.glVertex3f(0.0f, 1.0f, 0.0f);
    gl.glVertex3f(1.0f, -1.0f, 1.0f);
    gl.glVertex3f(1.0f, -1.0f, -1.0f);

    // Left triangle
    gl.glVertex3f(0.0f, 1.0f, 0.0f);
    gl.glVertex3f(-1.0f, -1.0f, -1.0f);
    gl.glVertex3f(-1.0f, -1.0f, 1.0f);

    // Back triangle
    gl.glVertex3f(0.0f, 1.0f, 0.0f);
    gl.glVertex3f(1.0f, -1.0f, -1.0f);
    gl.glVertex3f(-1.0f, -1.0f, -1.0f);

    // END Pyramid
    gl.glEnd();

    // Popping state
    gl.glPopAttrib();
    gl.glPopMatrix();
  }
Example #25
0
  public void display(GLAutoDrawable drawable) {
    GL2 gl = drawable.getGL().getGL2();
    //
    gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
    gl.glPushMatrix();
    gl.glRotatef(45.0f, 0.0f, 0.0f, 1.0f);

    gl.glTexGeni(GL2.GL_S, GL2.GL_TEXTURE_GEN_MODE, currentGenMode);
    gl.glTexGendv(GL2.GL_S, currentPlane, currentCoeff, 0);

    gl.glBindTexture(GL2.GL_TEXTURE_1D, texName[0]);
    glut.glutSolidTeapot(2.0f);
    gl.glPopMatrix();
    gl.glFlush();
  }
Example #26
0
  @Override
  public void render(GL2 gl, GLU glu, GLUT glut) {

    // camera.prepare(gl, glu, glut);

    // preRendering(gl, glu, glut);

    gl.glLoadIdentity();

    camera.prepare(gl, glu, glut);

    setupWorld(gl, glu, glut);

    for (Renderable r : this) {
      gl.glPushMatrix();

      r.render(gl, glu, glut);

      gl.glPopMatrix();
    }
  }
  public void renderScene(GL2 gl, KNode branch) {
    // enter model view matrix
    gl.glMatrixMode(GL2.GL_MODELVIEW);

    if (branch.isVisible() == false) return;

    if (updateNeeded) {
      // collect nodes
      visuals.clear();
      collectNodes(branch);
    }

    // TODO: sort nodes, when transformations changed
    // TODO: split in transparent / opaque

    // render nodes
    for (VisualNode n : visuals) {
      gl.glPushMatrix();
      renderVisualNode(gl, n);
      gl.glPopMatrix();
    }
  }
Example #28
0
 /**
  * Draws this robot on the screen.
  *
  * @param gl The instance of GL2 responsible for drawing the robot on the screen.
  * @param glut An instance of GLUT to optionally aid in drawing the robot body.
  * @param stickFigure If true, the robot must draw itself as a stick figure rather than a solid
  *     body.
  * @param tAnim Time since the start of the animation in seconds.
  * @param lighting The Lighting instance responsible for calculating the lighting in this scene.
  *     Can be used to set the color of bodies before drawing them.
  */
 public void draw(GL2 gl, GLUT glut, boolean stickFigure, float tAnim, Lighting lighting) {
   lighting.setMaterial(gl, getMaterial());
   gl.glPushMatrix();
   {
     gl.glTranslated(position.x(), position.y(), position.z());
     final double rotationDotY =
         direction.dot(Vector.Y) / (direction.length() * Vector.Y.length());
     final double rotationDotX =
         direction.dot(Vector.X) / (direction.length() * Vector.X.length());
     final double rotationAngle = Math.toDegrees(Math.acos(rotationDotY));
     gl.glRotated(
         (rotationDotX > 0d) ? (-rotationAngle) : (rotationAngle),
         Vector.Z.x(),
         Vector.Z.y(),
         Vector.Z.z());
     final double elevationDot =
         direction.dot(Vector.Z) / (direction.length() * Vector.Z.length());
     final double elevationAngle = Math.toDegrees(Math.asin(elevationDot));
     gl.glRotated(elevationAngle, Vector.X.x(), Vector.X.y(), Vector.X.z());
     robotBody.draw(gl, glut, stickFigure, tAnim);
   }
   gl.glPopMatrix();
 }
Example #29
0
  protected void applyBackground(
      DrawContext dc,
      WWIcon icon,
      Vec4 screenPoint,
      double width,
      double height,
      double pedestalSpacing,
      double pedestalScale) {
    GL2 gl = dc.getGL().getGL2(); // GL initialization checks for GL2 compatibility.

    double backgroundScale;
    backgroundScale = icon.getBackgroundScale();

    if (icon.getBackgroundTexture() != null) {
      if (icon.getBackgroundTexture().bind(dc)) {
        TextureCoords texCoords = icon.getBackgroundTexture().getTexCoords();
        gl.glPushMatrix();
        gl.glLoadIdentity();
        double bgwidth = backgroundScale * width;
        double bgheight = backgroundScale * height;
        // Offset the background for the highlighted scale.
        // if (icon.isHighlighted())
        // {
        //    gl.glTranslated(0d, height * (icon.getHighlightScale() - 1) / 2, 0d);
        // }
        // Offset the background for the pedestal height.
        gl.glTranslated(0d, (pedestalScale * height) + pedestalSpacing, 0d);
        // Place the background centered behind the icon.
        gl.glTranslated(screenPoint.x - bgwidth / 2, screenPoint.y - (bgheight - height) / 2, 0d);
        // Scale to the background image dimension.
        gl.glScaled(bgwidth, bgheight, 1d);
        dc.drawUnitQuad(texCoords);
        gl.glPopMatrix();
      }
    }
  }
Example #30
0
  private void renderTeapot(
      GL2 gl,
      float x,
      float y,
      float z,
      float ambr,
      float ambg,
      float ambb,
      float difr,
      float difg,
      float difb,
      float specr,
      float specg,
      float specb,
      float shine) {
    float mat[] = new float[4];

    gl.glPushMatrix();
    gl.glTranslatef(x, y, z);
    mat[0] = ambr;
    mat[1] = ambg;
    mat[2] = ambb;
    mat[3] = 1.0f;
    gl.glMaterialfv(GL.GL_FRONT, GL2.GL_SPECULAR, mat, 0);
    mat[0] = difr;
    mat[1] = difg;
    mat[2] = difb;
    gl.glMaterialfv(GL.GL_FRONT, GL2.GL_DIFFUSE, mat, 0);
    mat[0] = specr;
    mat[1] = specg;
    mat[2] = specb;
    gl.glMaterialfv(GL.GL_FRONT, GL2.GL_SPECULAR, mat, 0);
    gl.glMaterialf(GL.GL_FRONT, GL2.GL_SHININESS, shine * 128.0f);
    gl.glCallList(teapotList);
    gl.glPopMatrix();
  }