@Override
 public void display(GLAutoDrawable drawable) {
   GL2 gl = drawable.getGL().getGL2();
   gl.glClear(GL.GL_COLOR_BUFFER_BIT);
   // gl.glColor3f(1.0f, 0.0f, 0.0f); //ここは削除
   gl.glRotatef(25f, 0f, 1f, 0f);
   gl.glBegin(GL_POLYGON);
   gl.glColor3f(1.0f, 0.0f, 0.0f); // 赤
   gl.glVertex2f(-0.9f, -0.9f);
   gl.glColor3f(0.0f, 1.0f, 0.0f); // 緑
   gl.glVertex2f(0.9f, -0.9f);
   gl.glColor3f(0.0f, 0.0f, 1.0f); // 青
   gl.glVertex2f(0.9f, 0.9f);
   gl.glColor3f(1.0f, 1.0f, 0.0f); // 黄
   gl.glVertex2f(-0.9f, 0.9f);
   gl.glEnd();
 }
Esempio n. 2
0
 public void display(GLAutoDrawable drawable) {
   GL2 gl = drawable.getGL().getGL2();
   //
   gl.glClear(GL.GL_COLOR_BUFFER_BIT);
   gl.glColor3f(1.0f, 1.0f, 1.0f);
   gl.glCallList(startList);
   gl.glCallList(startList + 1);
   gl.glFlush();
 }
Esempio n. 3
0
  @Override
  public void draw(GLAutoDrawable drawable) {
    GL2 gl = drawable.getGL().getGL2();
    gl.glLineWidth(lineWidth); // call before glBegin

    gl.glBegin(GL.GL_LINES);
    gl.glColor3f(1.0f, 0.51f, 0.98f); // #FF83FA
    gl.glVertex2f(x1, y); // start point
    gl.glVertex2f(x2, y); // end point
    gl.glEnd();
  }
Esempio n. 4
0
  /**
   * //! Draw an x-y-z frame.
   *
   * @param aAxisLengthScale
   * @param aAxisThicknessScale
   * @param aModifyMaterialState
   */
  public static void jDrawFrame(
      final double aAxisLengthScale,
      final double aAxisThicknessScale,
      final boolean aModifyMaterialState) {
    // Triangle vertices:
    int nTriangles = 8;

    // Quad vertices:
    int nQuads = 16;

    GL2 gl = GLContext.getCurrent().getGL().getGL2();
    // set material properties
    float[] fnull = {0, 0, 0, 0};
    gl.glMaterialfv(GL2.GL_FRONT_AND_BACK, GL2.GL_SPECULAR, fnull, 0);
    gl.glMaterialfv(GL2.GL_FRONT_AND_BACK, GL2.GL_EMISSION, fnull, 0);
    gl.glColorMaterial(GL2.GL_FRONT_AND_BACK, GL2.GL_AMBIENT_AND_DIFFUSE);
    gl.glEnable(GL2.GL_COLOR_MATERIAL);
    gl.glPolygonMode(GL2.GL_FRONT_AND_BACK, GL2.GL_FILL);

    // enable vertex and normal arrays
    gl.glEnableClientState(GL2.GL_NORMAL_ARRAY);
    gl.glEnableClientState(GL2.GL_VERTEX_ARRAY);

    if (aModifyMaterialState) {
      gl.glEnable(GL2.GL_COLOR_MATERIAL);
      gl.glColorMaterial(GL2.GL_FRONT, GL2.GL_AMBIENT_AND_DIFFUSE);
      gl.glPolygonMode(gl.GL_FRONT_AND_BACK, gl.GL_FILL);
    }

    for (int k = 0; k < 3; k++) {
      gl.glPushMatrix();

      // Rotate to the appropriate axis
      if (k == 0) {
        gl.glRotatef(-90.0f, 0, 1, 0);
        gl.glColor3f(1.0f, 0.0f, 0.0f);
      } else if (k == 1) {
        gl.glRotatef(90.0f, 1, 0, 0);
        gl.glColor3f(0.0f, 1.0f, 0.0f);
      } else {
        gl.glRotatef(180.0f, 1, 0, 0);
        gl.glColor3f(0.0f, 0.0f, 1.0f);
      }

      // scaling
      gl.glScaled(aAxisThicknessScale, aAxisThicknessScale, aAxisLengthScale);

      // render frame object

      gl.glVertexPointer(3, GL2.GL_FLOAT, 0, triVerticesBuffer);
      gl.glNormalPointer(GL2.GL_FLOAT, 0, triNormalsBuffer);

      gl.glDrawArrays(GL2.GL_TRIANGLES, 0, nTriangles * 3);

      gl.glVertexPointer(3, GL2.GL_FLOAT, 0, quadVerticesBuffer);
      gl.glNormalPointer(GL2.GL_FLOAT, 0, quadNormalsBuffer);

      gl.glDrawArrays(GL2.GL_QUADS, 0, nQuads * 4);

      gl.glPopMatrix();
    }

    // disable vertex and normal arrays
    gl.glDisableClientState(GL2.GL_NORMAL_ARRAY);
    gl.glDisableClientState(GL2.GL_VERTEX_ARRAY);
  }
Esempio n. 5
0
  @Override
  public void display(GLAutoDrawable drawable) {
    GL2 gl2 = drawable.getGL().getGL2();
    GLU glu = GLU.createGLU();

    gl2.glClear(GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT);
    gl2.glEnable(GL2.GL_DEPTH_TEST);
    gl2.glDisable(GL2.GL_CULL_FACE);

    gl2.glMatrixMode(GL2.GL_PROJECTION);
    gl2.glLoadIdentity();
    glu.gluPerspective(60, drawable.getSurfaceWidth() / drawable.getSurfaceHeight(), 0.1f, 100);

    gl2.glMatrixMode(GL2.GL_MODELVIEW);
    gl2.glLoadIdentity();

    camera_.apply(gl2, glu);
    light_.apply(gl2, glu);

    terrain_.draw(gl2, glu);

    Runnable triangle =
        () -> {
          gl2.glBegin(GL2.GL_TRIANGLES);
          {
            gl2.glColor3f(1, 1, 1);
            gl2.glNormal3f(0, 0, 1);
            gl2.glVertex3f(0, 1, 0);
            gl2.glColor3f(1, 0, 0);
            gl2.glNormal3f(0, 0, 1);
            gl2.glVertex3f(-0.87f, -0.5f, 0);
            gl2.glColor3f(0, 0, 1);
            gl2.glNormal3f(0, 0, 1);
            gl2.glVertex3f(0.87f, -0.5f, 0);

            gl2.glColor3f(1, 1, 1);
            gl2.glNormal3f(0.71898836f, 0.4170133f, -0.5560177f);
            gl2.glVertex3f(0, 1, 0);
            gl2.glColor3f(0, 0, 1);
            gl2.glNormal3f(0.71898836f, 0.4170133f, -0.5560177f);
            gl2.glVertex3f(0.87f, -0.5f, 0);
            gl2.glColor3f(0, 1, 0);
            gl2.glNormal3f(0.71898836f, 0.4170133f, -0.5560177f);
            gl2.glVertex3f(0, 0, -0.75f);

            gl2.glColor3f(1, 0, 0);
            gl2.glNormal3f(-0.7189883f, 0.41701326f, -0.5560177f);
            gl2.glVertex3f(-0.87f, -0.5f, 0);
            gl2.glColor3f(1, 1, 1);
            gl2.glNormal3f(-0.7189883f, 0.41701326f, -0.5560177f);
            gl2.glVertex3f(0, 1, 0);
            gl2.glColor3f(0, 1, 0);
            gl2.glNormal3f(-0.7189883f, 0.41701326f, -0.5560177f);
            gl2.glVertex3f(0, 0, -0.75f);

            gl2.glColor3f(0, 0, 1);
            gl2.glNormal3f(0, -1.305f, -0.87f);
            gl2.glVertex3f(0.87f, -0.5f, 0);
            gl2.glColor3f(1, 0, 0);
            gl2.glNormal3f(0, -1.305f, -0.87f);
            gl2.glVertex3f(-0.87f, -0.5f, 0);
            gl2.glColor3f(0, 1, 0);
            gl2.glNormal3f(0, -1.305f, -0.87f);
            gl2.glVertex3f(0, 0, -0.75f);
          }
          gl2.glEnd();
        };

    gl2.glPushMatrix();
    {
      gl2.glPushMatrix();
      gl2.glTranslatef(0, 0, 0);
      gl2.glRotatef(angle__, 0, 1, 0);
      triangle.run();
      gl2.glPopMatrix();

      gl2.glPushMatrix();
      gl2.glTranslatef(0, 3.2f, 0);
      gl2.glRotatef(angle__ + 30, 0, 1, 0);
      triangle.run();
      gl2.glPopMatrix();

      gl2.glPushMatrix();
      gl2.glTranslatef(3.2f, 0, 0);
      gl2.glRotatef(angle__ + 60, 0, 1, 0);
      triangle.run();
      gl2.glPopMatrix();
    }
    gl2.glPopMatrix();
    angle__ += 1;

    gl2.glPushMatrix();
    gl2.glTranslatef(0.05f, -1.5f, 5);
    gl2.glScalef(0.05f, 0.05f, 0.05f);
    for (Face face : glock3__.faces) {
      gl2.glBegin(GL2.GL_POLYGON);
      for (FaceVertex vertex : face.vertices) {
        gl2.glColor3f(1, 1, 1);
        gl2.glNormal3f(vertex.n.x, vertex.n.y, vertex.n.z);
        gl2.glVertex3f(vertex.v.x, vertex.v.y, vertex.v.z);
      }
      gl2.glEnd();
    }
    gl2.glPopMatrix();
  }