Exemplo n.º 1
0
 public void render(GL gl) {
   // gl.glLoadIdentity();
   gl.glRasterPos2f(-0.25f + 0.10f * ((float) (Math.cos(0.1))), 0.35f * ((float) (Math.sin(0.1))));
   //	Take a string and make it a bitmap, put it in the 'gl' passed over and pick
   // the GLUT font, then provide the string to show
   glut.glutBitmapString(
       GLUT.BITMAP_HELVETICA_18, "Active OpenGL, in JoGL, Text With NeHe - " + 0.1);
 }
Exemplo n.º 2
0
  public void display(GLAutoDrawable glDrawable) {
    GL gl = glDrawable.getGL();

    // Store old matrices
    gl.glMatrixMode(GL.GL_MODELVIEW);
    gl.glPushMatrix();
    gl.glLoadIdentity();
    gl.glMatrixMode(GL.GL_PROJECTION);
    gl.glPushMatrix();
    gl.glLoadIdentity();

    gl.glViewport(0, 0, glDrawable.getWidth(), glDrawable.getHeight());

    // Store enabled state and disable lighting, texture mapping and the depth buffer
    gl.glPushAttrib(GL.GL_ENABLE_BIT);
    gl.glDisable(GL.GL_BLEND);
    gl.glDisable(GL.GL_LIGHTING);
    gl.glDisable(GL.GL_TEXTURE_2D);
    gl.glDisable(GL.GL_DEPTH_TEST);

    // Retrieve the current viewport and switch to orthographic mode
    IntBuffer viewPort = BufferUtil.newIntBuffer(4);
    gl.glGetIntegerv(GL.GL_VIEWPORT, viewPort);
    glu.gluOrtho2D(0, viewPort.get(2), viewPort.get(3), 0);

    // Render the text
    gl.glColor3f(1, 1, 1);

    int x = OFFSET;
    int maxx = 0;
    int y = OFFSET + CHAR_HEIGHT;

    if (keyboardEntries.size() > 0) {
      gl.glRasterPos2i(x, y);
      glut.glutBitmapString(GLUT.BITMAP_HELVETICA_12, KEYBOARD_CONTROLS);
      maxx =
          Math.max(
              maxx, OFFSET + glut.glutBitmapLength(GLUT.BITMAP_HELVETICA_12, KEYBOARD_CONTROLS));

      y += OFFSET;
      x += INDENT;
      for (int i = 0; i < keyboardEntries.size(); i++) {
        gl.glRasterPos2f(x, y);
        String text = (String) keyboardEntries.get(i);
        glut.glutBitmapString(GLUT.BITMAP_HELVETICA_12, text);
        maxx = Math.max(maxx, OFFSET + glut.glutBitmapLength(GLUT.BITMAP_HELVETICA_12, text));
        y += OFFSET;
      }
    }

    if (mouseEntries.size() > 0) {
      x = maxx + OFFSET;
      y = OFFSET + CHAR_HEIGHT;
      gl.glRasterPos2i(x, y);
      glut.glutBitmapString(GLUT.BITMAP_HELVETICA_12, MOUSE_CONTROLS);

      y += OFFSET;
      x += INDENT;
      for (int i = 0; i < mouseEntries.size(); i++) {
        gl.glRasterPos2f(x, y);
        glut.glutBitmapString(GLUT.BITMAP_HELVETICA_12, (String) mouseEntries.get(i));
        y += OFFSET;
      }
    }

    // Restore enabled state
    gl.glPopAttrib();

    // Restore old matrices
    gl.glPopMatrix();
    gl.glMatrixMode(GL.GL_MODELVIEW);
    gl.glPopMatrix();
  }