Exemple #1
0
  public static void render(GL2ES1 gl, int width, int height) {
    gl.glClear(GL.GL_COLOR_BUFFER_BIT);

    // draw a triangle filling the window
    gl.glLoadIdentity();

    ImmModeSink immModeSink =
        ImmModeSink.createFixed(
            3 * 3,
            3,
            GL.GL_FLOAT, // vertex
            3,
            GL.GL_FLOAT, // color
            0,
            GL.GL_FLOAT, // normal
            0,
            GL.GL_FLOAT, // texCoords
            GL.GL_STATIC_DRAW);
    immModeSink.glBegin(GL.GL_TRIANGLES);
    immModeSink.glColor3f(1, 0, 0);
    immModeSink.glVertex2f(0, 0);
    immModeSink.glColor3f(0, 1, 0);
    immModeSink.glVertex2f(width, 0);
    immModeSink.glColor3f(0, 0, 1);
    immModeSink.glVertex2f(width / 2, height);
    immModeSink.glEnd(gl, true);
  }
Exemple #2
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();
    }
  }