示例#1
0
  public static void setup(GL2ES1 gl, int width, int height) {
    gl.glMatrixMode(GL2ES1.GL_PROJECTION);
    gl.glLoadIdentity();

    // coordinate system origin at lower left with width and height same as the window
    GLU glu = new GLUgl2es1();
    glu.gluOrtho2D(0.0f, width, 0.0f, height);

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

    gl.glViewport(0, 0, width, height);
  }
  /**
   * Setup the viewport correctly in case it was changed.
   *
   * @param drawable the GLAutoDrawable object to access openGL
   */
  @SuppressWarnings("nls")
  private void setupViewport(final GLAutoDrawable drawable) {

    if (drawable.getContext() == null) {
      return;
    }

    boolean releaseContext = false;
    if (GLContext.getCurrent() == null) {
      drawable.getContext().makeCurrent();
      releaseContext = true;
    }
    GL2ES1 gl = null;

    if (drawable.getGLProfile().hasGLSL()) {
      gl = FixedFuncUtil.getFixedFuncImpl(drawable.getGL());
    } else if (drawable.getGLProfile().isGL2ES1()) {
      gl = drawable.getGL().getGL2ES1();
    } else {
      if (releaseContext) {
        drawable.getContext().release();
      }
      throw new GraphicsJOGLException(
          "Invalid GL profile. Failed to setup Viewport.", drawable.getGLProfile());
    }

    gl.glViewport(0, 0, drawable.getWidth(), drawable.getHeight());
    gl.glMatrixMode(GLMatrixFunc.GL_PROJECTION);
    gl.glLoadIdentity();
    gl.glOrtho(0, drawable.getWidth(), drawable.getHeight(), 0, -9999, 9999);
    //        GLU.createGLU().gluOrtho2D(0, drawable.getWidth(), 0,
    //            drawable.getHeight());
    gl.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
    gl.glLoadIdentity();

    if (releaseContext) {
      drawable.getContext().release();
    }
  }