Exemple #1
0
  public void display(GLAutoDrawable drawable) {
    GL2 gl = drawable.getGL().getGL2();
    //
    int jitter;
    int viewport[] = new int[4];

    gl.glGetIntegerv(GL.GL_VIEWPORT, viewport, 0);
    gl.glClear(GL2.GL_ACCUM_BUFFER_BIT);

    for (jitter = 0; jitter < 8; jitter++) {
      gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
      accPerspective(
          gl,
          45.0,
          (double) viewport[2] / (double) viewport[3],
          1.0,
          15.0,
          0.0,
          0.0,
          0.33 * j8[jitter].x,
          0.33 * j8[jitter].y,
          5.0);

      /* ruby, gold, silver, emerald, and cyan teapots */
      renderTeapot(
          gl, -1.1f, -0.5f, -4.5f, 0.1745f, 0.01175f, 0.01175f, 0.61424f, 0.04136f, 0.04136f,
          0.727811f, 0.626959f, 0.626959f, 0.6f);
      renderTeapot(
          gl, -0.5f, -0.5f, -5.0f, 0.24725f, 0.1995f, 0.0745f, 0.75164f, 0.60648f, 0.22648f,
          0.628281f, 0.555802f, 0.366065f, 0.4f);
      renderTeapot(
          gl, 0.2f, -0.5f, -5.5f, 0.19225f, 0.19225f, 0.19225f, 0.50754f, 0.50754f, 0.50754f,
          0.508273f, 0.508273f, 0.508273f, 0.4f);
      renderTeapot(
          gl, 1.0f, -0.5f, -6.0f, 0.0215f, 0.1745f, 0.0215f, 0.07568f, 0.61424f, 0.07568f, 0.633f,
          0.727811f, 0.633f, 0.6f);
      renderTeapot(
          gl,
          1.8f,
          -0.5f,
          -6.5f,
          0.0f,
          0.1f,
          0.06f,
          0.0f,
          0.50980392f,
          0.50980392f,
          0.50196078f,
          0.50196078f,
          0.50196078f,
          .25f);
      gl.glAccum(GL2.GL_ACCUM, 0.125f);
    }
    gl.glAccum(GL2.GL_RETURN, 1.0f);
    gl.glFlush();
  }
  @Override
  public void display(GLAutoDrawable drawable) {
    GL2 gl = drawable.getGL().getGL2();

    // Clearing the buffers
    gl.glClear(GL.GL_COLOR_BUFFER_BIT);
    gl.glClear(GL_DEPTH_BUFFER_BIT);

    // Drawing the figures
    // This easily allows for drawing additional figures of the same types as implemented, just copy
    // the line and change the translation values
    drawPyramid(gl, drawable, -3.0f, 0.0f, -8.0f);
    drawSquare(gl, drawable, 0.0f, 0.0f, -10.0f);
    drawStar(gl, drawable, 3.0f, 0.0f, -8.0f);
  }
Exemple #3
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();
  }
Exemple #4
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();
  }
Exemple #5
0
  public void display(GLAutoDrawable drawable) {
    GL2 gl = drawable.getGL().getGL2();
    //
    gl.glClear(GL.GL_COLOR_BUFFER_BIT);

    if (derefMethod == DRAWARRAY) {
      gl.glDrawArrays(GL2.GL_TRIANGLES, 0, 6);
    } else if (derefMethod == ARRAYELEMENT) {
      gl.glBegin(GL2.GL_TRIANGLES);
      gl.glArrayElement(2);
      gl.glArrayElement(3);
      gl.glArrayElement(5);
      gl.glEnd();
    } else if (derefMethod == DRAWELEMENTS) {
      int indices[] = new int[] {0, 1, 3, 4};
      if (indicesBuf == null) {
        indicesBuf = GLBuffers.newDirectIntBuffer(indices.length);
        indicesBuf.put(indices);
      }
      indicesBuf.rewind();
      gl.glDrawElements(GL2.GL_POLYGON, 4, GL2.GL_UNSIGNED_INT, indicesBuf);
    }
    gl.glFlush();

    // gl calls from C example's mouse routine are moved here
    if (setupMethod == INTERLEAVED) setupInterleave(gl);
    else if (setupMethod == POINTER) setupPointers(gl);
  }
Exemple #6
0
  public void init(GLAutoDrawable drawable) {
    drawable.setGL(new DebugGL2(drawable.getGL().getGL2()));
    final GL2 gl = drawable.getGL().getGL2();
    // drawable.getGL().getGL2();
    gl.glViewport(0, 0, SCREENW, SCREENH);

    // Clear color buffer with black
    // gl.glClearColor(1.0f, 0.5f, 1.0f, 1.0f);
    gl.glClearColor(.0f, .0f, .0f, 1.0f);
    gl.glClearDepth(1.0f);
    gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
    gl.glEnable(GL2.GL_DEPTH_TEST);
    gl.glPixelStorei(GL.GL_UNPACK_ALIGNMENT, 1);

    gl.glCreateShader(GL2GL3.GL_VERTEX_SHADER);
    shader.init(gl);
    int programName = shader.getID();
    gl.glBindAttribLocation(programName, Object3D.VERTEXPOSITION, "inposition");
    gl.glBindAttribLocation(programName, Object3D.VERTEXCOLOR, "incolor");
    gl.glBindAttribLocation(programName, Object3D.VERTEXNORMAL, "innormal");
    gl.glBindAttribLocation(programName, Object3D.VERTEXTEXCOORD0, "intexcoord0");
    shader.link(gl);
    uniformMat = gl.glGetUniformLocation(programName, "mat");
    uniformLight = gl.glGetUniformLocation(programName, "lightdir");
    gl.glUseProgram(programName);
    gl.glUniform3f(uniformLight, 0f, 10f, -10f);
    obj.init(gl, mats, programName);
    gl.glUseProgram(0);
  }
  /** Called back by the animator to perform rendering. */
  @Override
  public void display(GLAutoDrawable drawable) {
    GL2 gl = drawable.getGL().getGL2(); // get the OpenGL 2 graphics context
    gl.glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // clear color and depth buffers
    gl.glLoadIdentity(); // reset the model-view matrix

    gl.glTranslatef(0.0f, 0.0f, -12.0f);
    gl.glRotatef(rotateAnleX, 1.0f, 0.0f, 0.0f);
    gl.glRotatef(rotateAnleY, 0.0f, 1.0f, 0.0f);
    gl.glRotatef(rotateAngleZ, 0.0f, 0.0f, 1.0f);

    // need to flip the image
    float textureHeight = textureTop - textureBottom;

    float x1, y1, x2, y2; // used to break the flag into tiny quads

    gl.glBegin(GL_QUADS);
    for (int x = 0; x < numPoints - 1; x++) {
      for (int y = 0; y < numPoints - 1; y++) {
        x1 = (float) x / 44.0f;
        y1 = (float) y / 44.0f;
        x2 = (float) (x + 1) / 44.0f;
        y2 = (float) (y + 1) / 44.0f;

        // Texture need to flip vertically
        gl.glTexCoord2f(x1, y1 * textureHeight + textureBottom);
        gl.glVertex3f(points[x][y][0], points[x][y][1], points[x][y][2]);

        gl.glTexCoord2f(x1, y2 * textureHeight + textureBottom);
        gl.glVertex3f(points[x][y + 1][0], points[x][y + 1][1], points[x][y + 1][2]);

        gl.glTexCoord2f(x2, y2 * textureHeight + textureBottom);
        gl.glVertex3f(points[x + 1][y + 1][0], points[x + 1][y + 1][1], points[x + 1][y + 1][2]);

        gl.glTexCoord2f(x2, y1 * textureHeight + textureBottom);
        gl.glVertex3f(points[x + 1][y][0], points[x + 1][y][1], points[x + 1][y][2]);
      }
    }
    gl.glEnd();

    if (wiggleCount == 2) { // Used To Slow Down The Wave (Every 2nd Frame Only)
      for (int y = 0; y < 45; y++) {
        float tempHold = points[0][y][2]; // Store current value One Left Side Of
        // Wave
        for (int x = 0; x < 44; x++) {
          // Current Wave Value Equals Value To The Right
          points[x][y][2] = points[x + 1][y][2];
        }
        points[44][y][2] = tempHold; // Last Value Becomes The Far Left Stored
        // Value
      }
      wiggleCount = 0; // Set Counter Back To Zero
    }
    wiggleCount++;

    // update the rotational position after each refresh
    rotateAnleX += roateSpeedX;
    rotateAnleY += rotateSpeedY;
    rotateAngleZ += rotateSpeedZ;
  }
  public boolean bind() {
    GL2 gl = getGL();
    // if first time, generate FBO
    if (fboId < 0) {
      System.out.println("GENERATE...");
      if (!generateFBO(gl)) {
        System.err.println("couldn't generate FBO!");
        return false;
      }
    }

    writeAttachment = GL_COLOR_ATTACHMENT0; // _EXT;
    readAttachment = GL_COLOR_ATTACHMENT1; // _EXT;

    readTextureId = texture2.getTextureObject();
    writeTextureId = texture1.getTextureObject();

    // bind fbo
    // gl.glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fboId);
    gl.glBindFramebuffer(GL_FRAMEBUFFER, fboId);
    gl.glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
    gl.glViewport(0, 0, fboWidth, fboHeight);

    return true;
  }
  /**
   * Puts the input texture through the Program chain, returning the processed output Texture which
   * can then be placed on a Geom, etc.
   *
   * @param gl
   * @return A Texture that's been processed by the attached shader Programs
   */
  public Texture apply() {
    GL2 gl = getGL();
    // sanity check
    if (programs.size() == 0) {
      return inputTexture;
    }

    // if first time, generate FBO
    if (fboId < 0) {
      System.out.println("GENERATE...");
      if (!generateFBO(gl)) {
        System.err.println("couldn't generate FBO!");
        return null;
      }
    }

    // if first time, install shaders
    for (Program program : this.programs) {
      if (program.programId <= 0) {
        program.install();
      }
    }

    writeAttachment = GL_COLOR_ATTACHMENT0;
    readAttachment = GL_COLOR_ATTACHMENT1;

    readTextureId = texture2.getTextureObject();
    writeTextureId = texture1.getTextureObject();
    // readTexture = texture2;
    // writeTexture = texture1;

    // bind fbo
    gl.glBindFramebuffer(GL_FRAMEBUFFER, fboId);
    gl.glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
    gl.glViewport(0, 0, fboWidth, fboHeight);

    // use first program to process inputTexture into texture2
    drawTextureToOffScreenTextureUsingShader(
        inputTexture.getTextureObject(), writeAttachment, programs.get(0));

    swapPingPong(); // make the write texture our new *read* texture

    // loop through the rest of our shaders
    for (int i = 1; i < programs.size(); i++) {
      drawTextureToOffScreenTextureUsingShader(readTextureId, writeAttachment, programs.get(i));
      swapPingPong();
    }

    gl.glBindFramebuffer(GL_FRAMEBUFFER, 0);
    int www = RenderUtils.getViewport()[2];
    int hhh = RenderUtils.getViewport()[3];

    gl.glViewport(0, 0, www, hhh);

    if (readTextureId == texture1.getTextureObject()) {
      return texture1;
    } else {
      return texture2;
    }
  }
  public void display(GLAutoDrawable drawable) {

    GL2 gl = drawable.getGL().getGL2();

    // Clear the drawing area
    gl.glClear(GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT);
    // Reset the current matrix to the "identity"
    gl.glLoadIdentity();

    // Move the "drawing cursor" around
    gl.glTranslatef(-1.5f, 0.0f, -6.0f);

    // Drawing Using Triangles
    gl.glBegin(GL2.GL_TRIANGLES);
    gl.glColor3f(1.0f, 0.0f, 0.0f); // Set the current drawing color to red
    gl.glVertex3f(0.0f, 1.0f, 0.0f); // Top
    gl.glColor3f(0.0f, 1.0f, 0.0f); // Set the current drawing color to green
    gl.glVertex3f(-1.0f, -1.0f, 0.0f); // Bottom Left
    gl.glColor3f(0.0f, 0.0f, 1.0f); // Set the current drawing color to blue
    gl.glVertex3f(1.0f, -1.0f, 0.0f); // Bottom Right
    // Finished Drawing The Triangle
    gl.glEnd();

    // Move the "drawing cursor" to another position
    gl.glTranslatef(3.0f, 0.0f, 0.0f);
    // Draw A Quad
    gl.glBegin(GL2.GL_QUADS);
    gl.glColor3f(0.5f, 0.5f, 1.0f); // Set the current drawing color to light blue
    gl.glVertex3f(-1.0f, 1.0f, 0.0f); // Top Left
    gl.glVertex3f(1.0f, 1.0f, 0.0f); // Top Right
    gl.glVertex3f(1.0f, -1.0f, 0.0f); // Bottom Right
    gl.glVertex3f(-1.0f, -1.0f, 0.0f); // Bottom Left
    // Done Drawing The Quad
    gl.glEnd();
  }
Exemple #11
0
  @Override
  public void display(GLAutoDrawable gLDrawable) {
    final GL2 gl = gLDrawable.getGL().getGL2();
    gl.glClear(GL.GL_COLOR_BUFFER_BIT);
    gl.glClear(GL.GL_DEPTH_BUFFER_BIT);
    gl.glLoadIdentity();
    gl.glTranslatef(0.0f, 0.0f, -5.0f);

    // rotate about the three axes
    gl.glRotatef(rotateT, 1.0f, 0.0f, 0.0f);
    gl.glRotatef(rotateT, 0.0f, 1.0f, 0.0f);
    gl.glRotatef(rotateT, 0.0f, 0.0f, 1.0f);

    // Draw A Quad
    gl.glBegin(GL2.GL_QUADS);
    gl.glColor3f(0.0f, 1.0f, 1.0f); // set the color of the quad
    gl.glVertex3f(-1.0f, 1.0f, 0.0f); // Top Left
    gl.glVertex3f(1.0f, 1.0f, 0.0f); // Top Right
    gl.glVertex3f(1.0f, -1.0f, 0.0f); // Bottom Right
    gl.glVertex3f(-1.0f, -1.0f, 0.0f); // Bottom Left
    // Done Drawing The Quad
    gl.glEnd();

    // increasing rotation for the next iteration
    rotateT += 0.2f;
  }
Exemple #12
0
 public void display(GLAutoDrawable drawable) {
   GL2 gl = drawable.getGL().getGL2();
   //
   gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
   pickRects(gl);
   drawRects(gl, GL2.GL_RENDER);
   gl.glFlush();
 }
Exemple #13
0
  public void display(GLAutoDrawable drawable) {
    GL2 gl = drawable.getGL().getGL2();

    gl.glClear(GL2.GL_COLOR_BUFFER_BIT);
    if (pickPoint != null) {
      pickSquares(gl);
    }

    drawSquares(gl, GL2.GL_RENDER);

    gl.glFlush();
  }
Exemple #14
0
  @Override
  public void display(GLAutoDrawable dr) {
    GL2 gl = dr.getGL().getGL2();
    // Очиска экрана
    gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
    // Загрузка единичной матрицы
    gl.glLoadIdentity();
    // Определение точки и направления взгляда
    glu.gluLookAt(0f, 0f, 2f, 0f, 0f, -100f, 0f, 1f, 0f);

    renderer.render(gl, model);
  }
Exemple #15
0
  @Override
  public void display(GLAutoDrawable drawable) {
    final int deltaTimeMs = local.getDeltaTimeMs();
    eventListeners.processEvents();

    GL2 gl = drawable.getGL().getGL2();
    final GLGraphics g = new GLGraphics(gl, local, true, deltaTimeMs);

    gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
    gl.glLoadIdentity();
    gl.glTranslatef(0.375f, 0.375f, 0);

    float paddedWidth = getWidth() - padding.left - padding.right;
    float paddedHeight = getHeight() - padding.top - padding.bottom;
    g.move(padding.left, padding.right);

    if (dirty) {
      root.setBounds(0, 0, paddedWidth, paddedHeight);
      root.relayout();
      dirty = false;
    }

    // 1 pass: picking
    Runnable toRender =
        new Runnable() {
          @Override
          public void run() {
            root.renderPick(g);
          }
        };

    Vec2f mousePos = pickingManager.getCurrentMousePos();
    if (mousePos != null) {
      root.getMouseLayer()
          .setBounds(
              mousePos.x() - padding.left,
              mousePos.y() - padding.top,
              getWidth() - mousePos.x(),
              getHeight() - mousePos.y());
      root.getMouseLayer().relayout();
    }
    pickingManager.doPicking(g.gl, toRender);

    // 2. pass: layout
    root.layout(deltaTimeMs);

    // 3. pass: rendering
    if (renderPick) root.renderPick(g);
    else root.render(g);

    g.move(-padding.left, -padding.right);
  }
  @Override
  public void display(GLAutoDrawable glAutoDrawable) {
    gl = glAutoDrawable.getGL().getGL2();
    gl.glClear(GL.GL_COLOR_BUFFER_BIT);

    // Fonts draw selves at the current raster position
    gl.glRasterPos2f(right - (right + 2.0f), bottom + 1);
    caption = "Please wait... drawing frames";
    glut.glutBitmapString(GLUT.BITMAP_HELVETICA_18, caption);

    drawByLevel();

    gl.glFlush();
  }
Exemple #17
0
 /** Called back by the animator to perform rendering. */
 public void display(GLAutoDrawable drawable) {
   GL2 gl = drawable.getGL().getGL2(); // get the OpenGL 2 graphics context
   gl.glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // clear color
   // and depth
   // buffers
   gl.glLoadIdentity(); // reset the model-view matrix
   update();
   graphicsManager.setGraphics(gl);
   draw();
   graphicsManager.flush();
   if (debugEnabled) {
     debugRenderer.renderDebugInfo();
   }
 }
  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);
  }
Exemple #19
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();
  }
Exemple #20
0
  private void draw(GLAutoDrawable drawable) {
    if (modeFlag) {
      modeFlag = false;
      reshape(drawable, 0, 0, width, height);
    }

    //		GL gl = drawable.getGL();
    gl.glClear(GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT);

    loadDefaults(gl);

    for (Iterator<GLBrush> it = displayList.iterator(); it.hasNext(); ) {
      GLBrush brush = it.next();
      brush.draw(gl, glu, glut);
    }
  }
Exemple #21
0
  public void display(GLAutoDrawable drawable) {
    GL2 gl = drawable.getGL().getGL2();
    gl.glClearColor(0, 0, 0, 0);
    gl.glClear(GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT);

    gl.glMatrixMode(GL2.GL_PROJECTION);
    gl.glLoadIdentity();
    // new GLU().gluPerspective(45f, (float)width/(float)height, 0.1f, 1000f);
    gl.glOrtho(0.0, 800, 0.0, 800, -100.0, 100.0);
    gl.glMatrixMode(GL2.GL_MODELVIEW);
    gl.glLoadIdentity();

    tr.beginRendering(800, 800);
    tr.draw("die Marktwirtschaft. Da regelt sich � angeblich", 16, 32);
    tr.draw("Hello World! This text is scrambled", 16, 16);
    tr.endRendering();
  }
Exemple #22
0
 @Override
 public void display(GLAutoDrawable dr) {
   GL2 gl = dr.getGL().getGL2();
   // Очиска экрана
   gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
   // Загрузка единичной матрицы
   gl.glLoadIdentity();
   // Определение точки и направления взгляда
   glu.gluLookAt(0f, 0f, 10f, 0f, 0f, -100f, 0f, 1f, 0f);
   // Загрузка текстуры в графическую память
   this.texture.bind(gl);
   GLUquadric ground = glu.gluNewQuadric();
   // enabling texturing on the quadric
   glu.gluQuadricTexture(ground, true);
   glu.gluSphere(ground, 1, 64, 64);
   glu.gluDeleteQuadric(ground);
 }
  @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 display(GLAutoDrawable drawable) {
    GL2 gl = drawable.getGL().getGL2();

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

    // to position the camera.

    gl.glTranslated(0, 0, -1);

    // Forgetting to clear the depth buffer can cause problems
    // such as empty black screens.
    gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT);
    float matAmbAndDifR[] = {0.9f, 0.0f, 0.0f, 0.75f};
    float matAmbAndDifG[] = {0.0f, 0.5f, 0.0f, 1.0f};

    gl.glBegin(GL2.GL_TRIANGLES);
    {

      // One in drawn first and in front has alpha
      // gl.glColor4f(1f,0f,0f,1f);
      // CCW ordering of vertices
      double p0[] = {1, 0, -1};
      double p1[] = {0, 1, -1};
      double p2[] = {-1, 0, -1};

      gl.glMaterialfv(GL2.GL_FRONT, GL2.GL_AMBIENT_AND_DIFFUSE, matAmbAndDifG, 0);

      // gl.glColor4f(0,1,0,1f);
      gl.glVertex3d(2, 0, -2);
      gl.glVertex3d(1, 1, -2);
      gl.glVertex3d(0, 0, -2);

      gl.glMaterialfv(GL2.GL_FRONT_AND_BACK, GL2.GL_AMBIENT_AND_DIFFUSE, matAmbAndDifR, 0);
      gl.glVertex3dv(p0, 0);
      gl.glVertex3dv(p1, 0);
      gl.glVertex3dv(p2, 0);
    }
    gl.glEnd();

    gl.glPolygonMode(GL2.GL_FRONT_AND_BACK, GL2.GL_FILL);
  }
Exemple #25
0
  public void display(GLAutoDrawable drawable) {
    final GL2 gl = drawable.getGL().getGL2();
    gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
    mats.glMatrixMode(GL2.GL_MODELVIEW);
    mats.glLoadIdentity();
    mats.glTranslatef(0f, 0f, -2.0f);
    // t = t+0.5f;
    t = 40f;
    mats.glRotatef(t, 0f, 1f, 0f);
    mats.glMatrixMode(GL2.GL_PROJECTION);
    mats.glLoadIdentity();
    mats.glFrustumf(-1f, 1f, -1f, 1f, 1f, 100f);
    mats.update();
    gl.glUseProgram(shader.getID());
    gl.glUniformMatrix4fv(uniformMat, 3, false, mats.glGetPMvMviMatrixf());

    obj.display(gl, mats);
    gl.glFlush();
    gl.glUseProgram(0);
  }
  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);
  }
  /*
   * display() draws a triangle at an angle.
   */
  public void display(GLAutoDrawable drawable) {
    GL2 gl = drawable.getGL().getGL2();
    //
    gl.glClear(GL.GL_COLOR_BUFFER_BIT);

    if (key != null)
      switch (key.getKeyChar()) {
        case 'c':
          gl.glFogi(GL2.GL_FOG_COORDINATE_SOURCE, GL2.GL_FRAGMENT_DEPTH);
          break;
        case 'C':
          gl.glFogi(GL2.GL_FOG_COORDINATE_SOURCE, GL2.GL_FOG_COORDINATE);
          break;

        case 'b':
          gl.glMatrixMode(GL2.GL_MODELVIEW);
          gl.glTranslatef(0.0f, 0.0f, -0.25f);
          break;
        case 'f':
          gl.glMatrixMode(GL2.GL_MODELVIEW);
          gl.glTranslatef(0.0f, 0.0f, 0.25f);
          break;
        default:
          break;
      }

    gl.glColor3f(1.0f, 0.75f, 0.0f);
    gl.glBegin(GL2.GL_TRIANGLES);
    gl.glFogCoordf(f1);
    gl.glVertex3f(2.0f, -2.0f, 0.0f);
    gl.glFogCoordf(f2);
    gl.glVertex3f(-2.0f, 0.0f, -5.0f);
    gl.glFogCoordf(f3);
    gl.glVertex3f(0.0f, 2.0f, -10.0f);
    gl.glEnd();

    gl.glFlush();
  }
  @Override
  public void display(GLAutoDrawable drawable) {
    GL2 gl = drawable.getGL().getGL2();

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

    // Move camera back a little
    gl.glTranslated(0, 0, -1);

    // Forgetting to clear the depth buffer can cause problems
    // such as empty black screens.
    gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT);

    gl.glBegin(GL2.GL_TRIANGLES);
    {

      // Need to draw transparent one last
      gl.glColor4f(1f, 0f, 0f, 0.75f); // try with 0.25
      // CCW ordering of vertices
      double p0[] = {1, 0, -1};
      double p1[] = {0, 1, -1};
      double p2[] = {-1, 0, -1};

      // Can pass in an array and an offset into the array
      gl.glVertex3dv(p0, 0);
      gl.glVertex3dv(p1, 0);
      gl.glVertex3dv(p2, 0);

      // Opaque one (at back) must be drawn before
      // transparent one in front
      gl.glColor4f(0, 1, 0, 1f);
      gl.glVertex3d(2, 0, -2);
      gl.glVertex3d(1, 1, -2);
      gl.glVertex3d(0, 0, -2);
    }
    gl.glEnd();
  }
Exemple #29
0
  @Override
  public void display(GLAutoDrawable drawable) {

    gl = drawable.getGL().getGL2();
    gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
    gl.glMatrixMode(GL2.GL_MODELVIEW);
    gl.glLoadIdentity();

    // desenha ou nao a bounding sphere de cada objeto
    if (InputHandler.getInstance().isKeyPressed(KeyEvent.VK_B)) { // tecla B
      BoundingVolume.isVisible = !BoundingVolume.isVisible;
    }
    // habilita ou nao fog
    if (InputHandler.getInstance().isKeyPressed(KeyEvent.VK_F)) { // tecla F
      fogEnabled = !fogEnabled;
      if (fogEnabled) gl.glEnable(GL2.GL_FOG);
      else gl.glDisable(GL2.GL_FOG);
    }

    // atualiza camera
    camera.update();
    // atualiza objetos
    {
      Iterator<SceneObject> it = Scene.getInstance().getSceneObjectsIterator();
      while (it.hasNext()) {
        SceneObject so = it.next();
        // animacao da porta
        if (so.getName().contains("door")) {
          if (Collision.collide(
              camera.getSceneObject().getBoundingSphere(), so.getBoundingSphere()))
            so.setAnimating(true);
          else so.setAnimating(false);
        }

        so.update();
      }
    }

    glu.gluLookAt(
        FPCamera.position.x,
        FPCamera.position.y,
        FPCamera.position.z,
        FPCamera.position.x + FPCamera.look.x,
        FPCamera.position.y + FPCamera.look.y,
        FPCamera.position.z + FPCamera.look.z,
        FPCamera.up.x,
        FPCamera.up.y,
        FPCamera.up.z);

    if (FPCamera.changed) { // se direcao da camera mudar
      FPCamera.changed = false;

      frustum.generate(drawable); // gera o frustum

      Scene.getInstance().clearVisibleObjectsList();

      Iterator<SceneObject> it = Scene.getInstance().getSceneObjectsIterator();
      while (it.hasNext()) {
        SceneObject so = it.next();
        if (frustum.sphereInFrustum(so.getBoundingSphere()))
          Scene.getInstance().addVisibleObject(so);
      }

      //            System.out.println("Renderable objects: "+ Scene.getInstance().getSize());
      //            System.out.println(FPCamera.position);
    }

    // desenha objetos
    {
      Iterator<SceneObject> it = Scene.getInstance().getVisibleObjectsIterator();
      SceneObject so;
      while (it.hasNext()) {
        so = it.next();

        if (so.getName().contains("lake")) {
          gl.glPushAttrib(GL2.GL_ENABLE_BIT);
          gl.glEnable(GL.GL_BLEND);
          gl.glBlendFunc(GL.GL_ONE, GL.GL_ONE);
          so.draw(drawable);
          gl.glPopAttrib();
          continue;
        }
        so.draw(drawable);
      }
    }

    //        int e = gl.glGetError();
    //        if(e != GL.GL_NO_ERROR) {
    //            System.err.println("Erro: "+ gl.glGetString(e));
    //        }
    // calculo do fps
    ++frame;
    long time = System.currentTimeMillis();
    elapsed = time - timebase;
    if (elapsed > 1000) {
      long fps = frame * 1000 / (time - timebase);
      timebase = time;
      frame = 0;

      String str = "FPS: " + fps;
      mainFrame.setTitle(str);
    }

    // gl.glFlush();
  }
Exemple #30
0
  public void display(GLAutoDrawable drawable) {
    update();

    GL2 gl = drawable.getGL().getGL2();
    // Clear Color Buffer, Depth Buffer
    gl.glClear(GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT);

    Matrix TmpMatrix = new Matrix(); // Temporary MATRIX Structure ( NEW )
    Vector TmpVector = new Vector(), TmpNormal = new Vector(); // Temporary
    // VECTOR
    // Structures
    // ( NEW )

    gl.glLoadIdentity(); // Reset The Matrix

    if (outlineSmooth) { // Check To See If We Want Anti-Aliased Lines ( NEW
      // )
      gl.glHint(GL2.GL_LINE_SMOOTH_HINT, GL2.GL_NICEST); // Use The Good
      // Calculations
      // ( NEW )
      gl.glEnable(GL2.GL_LINE_SMOOTH); // Enable Anti-Aliasing ( NEW )
    } else
      // We Don't Want Smooth Lines ( NEW )
      gl.glDisable(GL2.GL_LINE_SMOOTH); // Disable Anti-Aliasing ( NEW )

    gl.glTranslatef(0.0f, 0.0f, -2.0f); // Move 2 Units Away From The Screen
    // ( NEW )
    gl.glRotatef(modelAngle, 0.0f, 1.0f, 0.0f); // Rotate The Model On It's
    // Y-Axis ( NEW )

    gl.glGetFloatv(GLMatrixFunc.GL_MODELVIEW_MATRIX, TmpMatrix.Data, 0); // Get
    // The
    // Generated
    // Matrix
    // (
    // NEW
    // )

    // Cel-Shading Code //
    gl.glEnable(GL2.GL_TEXTURE_1D); // Enable 1D Texturing ( NEW )
    gl.glBindTexture(GL2.GL_TEXTURE_1D, shaderTexture[0]); // Bind Our
    // Texture ( NEW
    // )
    gl.glColor3f(1.0f, 1.0f, 1.0f); // Set The Color Of The Model ( NEW )

    gl.glBegin(GL2.GL_TRIANGLES); // Tell OpenGL That We're Drawing
    // Triangles
    // Loop Through Each Polygon
    for (int i = 0; i < polyNum; i++)
      // Loop Through Each Vertex
      for (int j = 0; j < 3; j++) {

        // Fill Up The TmpNormal Structure With
        TmpNormal.X = polyData[i].Verts[j].Nor.X;
        // The Current Vertices' Normal Values
        TmpNormal.Y = polyData[i].Verts[j].Nor.Y;
        TmpNormal.Z = polyData[i].Verts[j].Nor.Z;
        // Rotate This By The Matrix
        TmpMatrix.rotateVector(TmpNormal, TmpVector);
        // Normalize The New Normal
        TmpVector.normalize();

        // Calculate The Shade Value
        float TmpShade = Vector.dotProduct(TmpVector, lightAngle);

        // Clamp The Value to 0 If Negative ( NEW )
        if (TmpShade < 0.0f) {
          TmpShade = 0.0f;
        }
        // Set The Texture Co-ordinate As The Shade Value
        gl.glTexCoord1f(TmpShade);
        // Send The Vertex Position
        gl.glVertex3f(
            polyData[i].Verts[j].Pos.X, polyData[i].Verts[j].Pos.Y, polyData[i].Verts[j].Pos.Z);
      }

    gl.glEnd(); // Tell OpenGL To Finish Drawing
    gl.glDisable(GL2.GL_TEXTURE_1D); // Disable 1D Textures ( NEW )

    // Outline Code
    // Check To See If We Want To Draw The Outline
    if (outlineDraw) {
      // Enable Blending
      gl.glEnable(GL2.GL_BLEND);
      // Set The Blend Mode
      gl.glBlendFunc(GL2.GL_SRC_ALPHA, GL2.GL_ONE_MINUS_SRC_ALPHA);

      // Draw Backfacing Polygons As Wireframes
      gl.glPolygonMode(GL2.GL_BACK, GL2.GL_LINE);
      // Set The Line Width
      gl.glLineWidth(outlineWidth);
      // Don't Draw Any Front-Facing Polygons
      gl.glCullFace(GL2.GL_FRONT);

      // Change The Depth Mode
      gl.glDepthFunc(GL2.GL_LEQUAL);
      // Set The Outline Color
      gl.glColor3fv(outlineColor, 0);

      // Tell OpenGL What We Want To Draw
      gl.glBegin(GL2.GL_TRIANGLES);

      // Loop Through Each Polygon
      for (int i = 0; i < polyNum; i++) {

        // Loop Through Each Vertex
        for (int j = 0; j < 3; j++) {

          // Send The Vertex Position
          gl.glVertex3f(
              polyData[i].Verts[j].Pos.X, polyData[i].Verts[j].Pos.Y, polyData[i].Verts[j].Pos.Z);
        }
      }
      gl.glEnd(); // Tell OpenGL We've Finished
      // Reset The Depth-Testing Mode
      gl.glDepthFunc(GL2.GL_LESS);
      // Reset The Face To Be Culled
      gl.glCullFace(GL2.GL_BACK);
      // Reset Back-Facing Polygon Drawing Mode
      gl.glPolygonMode(GL2.GL_BACK, GL2.GL_FILL);

      // Disable Blending
      gl.glDisable(GL2.GL_BLEND);
    }

    // Check To See If Rotation Is Enabled
    if (modelRotate) {
      // Update Angle Based On The Clock
      modelAngle += .2f;
    }
  }