Ejemplo n.º 1
0
  public void init(GLAutoDrawable drawable) {
    drawable.setAutoSwapBufferMode(false);

    GL2ES2 gl = drawable.getGL().getGL2ES2();
    System.err.println("Entering initialization");
    System.err.println("GL_VERSION=" + gl.glGetString(gl.GL_VERSION));
    System.err.println("GL_EXTENSIONS:");
    System.err.println("  " + gl.glGetString(gl.GL_EXTENSIONS));

    pmvMatrix = new PMVMatrix();

    pmod.initShaderState(gl);
    st = ShaderState.getCurrent();

    // Push the 1st uniform down the path
    st.glUseProgram(gl, true);

    pmvMatrix.glMatrixMode(pmvMatrix.GL_PROJECTION);
    pmvMatrix.glLoadIdentity();
    pmvMatrix.glMatrixMode(pmvMatrix.GL_MODELVIEW);
    pmvMatrix.glLoadIdentity();

    if (!st.glUniform(gl, new GLUniformData("mgl_PMVMatrix", 4, 4, pmvMatrix.glGetPMvMatrixf()))) {
      throw new GLException("Error setting PMVMatrix in shader: " + st);
    }

    // OpenGL Render Settings
    gl.glClearColor(0, 0, 0, 1);
    gl.glEnable(GL2ES2.GL_DEPTH_TEST);

    st.glUseProgram(gl, false);

    // Let's show the completed shader state ..
    System.out.println(st);
  }
Ejemplo n.º 2
0
  public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
    GL2ES2 gl = drawable.getGL().getGL2ES2();

    st.glUseProgram(gl, true);

    // Set location in front of camera
    pmvMatrix.glMatrixMode(pmvMatrix.GL_PROJECTION);
    pmvMatrix.glLoadIdentity();
    pmvMatrix.glOrthof(0f, 1.0f, 0.0f, 1.0f, 1.0f, 100.0f);

    pmvMatrix.glMatrixMode(pmvMatrix.GL_MODELVIEW);
    pmvMatrix.glLoadIdentity();
    pmvMatrix.glTranslatef(0, 0, -10);

    GLUniformData ud = st.getUniform("mgl_PMVMatrix");
    if (null != ud) {
      // same data object
      st.glUniform(gl, ud);
    }

    st.glUseProgram(gl, false);
  }