Beispiel #1
0
 @Override
 public void dispose(final GLAutoDrawable glad) {
   System.err.println(
       Thread.currentThread() + " RedSquareES2.dispose: tileRendererInUse " + tileRendererInUse);
   final GL2ES2 gl = glad.getGL().getGL2ES2();
   if (!gl.hasGLSL()) {
     return;
   }
   st.destroy(gl);
   st = null;
   pmvMatrix = null;
   System.err.println(Thread.currentThread() + " RedSquareES2.dispose FIN");
 }
Beispiel #2
0
  @Override
  public void display(final GLAutoDrawable glad) {
    final long t1 = System.currentTimeMillis();

    final GL2ES2 gl = glad.getGL().getGL2ES2();
    if (clearBuffers) {
      if (null != tileRendererInUse) {
        gl.glClearColor(1.0f, 1.0f, 1.0f, 0.0f);
      } else {
        gl.glClearColor(0, 0, 0, 0);
      }
      gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
    }
    if (!gl.hasGLSL()) {
      return;
    }
    st.useProgram(gl, true);
    // One rotation every four seconds
    pmvMatrix.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
    pmvMatrix.glLoadIdentity();
    pmvMatrix.glTranslatef(0, 0, -10);
    if (doRotate) {
      final float ang = ((t1 - t0) * 360.0F) / 4000.0F;
      pmvMatrix.glRotatef(ang, 0, 0, 1);
      pmvMatrix.glRotatef(ang, 0, 1, 0);
    }
    st.uniform(gl, pmvMatrixUniform);

    // Draw a square
    vertices.enableBuffer(gl, true);
    colors.enableBuffer(gl, true);
    gl.glDrawArrays(GL.GL_TRIANGLE_STRIP, 0, 4);
    vertices.enableBuffer(gl, false);
    colors.enableBuffer(gl, false);
    st.useProgram(gl, false);
  }
Beispiel #3
0
  void reshapeImpl(
      final GL2ES2 gl,
      final int tileX,
      final int tileY,
      final int tileWidth,
      final int tileHeight,
      final int imageWidth,
      final int imageHeight) {
    System.err.println(
        Thread.currentThread()
            + " RedSquareES2.reshape "
            + tileX
            + "/"
            + tileY
            + " "
            + tileWidth
            + "x"
            + tileHeight
            + " of "
            + imageWidth
            + "x"
            + imageHeight
            + ", swapInterval "
            + swapInterval
            + ", drawable 0x"
            + Long.toHexString(gl.getContext().getGLDrawable().getHandle())
            + ", tileRendererInUse "
            + tileRendererInUse);
    // Thread.dumpStack();
    if (!gl.hasGLSL()) {
      return;
    }

    st.useProgram(gl, true);
    // Set location in front of camera
    pmvMatrix.glMatrixMode(GLMatrixFunc.GL_PROJECTION);
    pmvMatrix.glLoadIdentity();

    // compute projection parameters 'normal' perspective
    final float fovy = 45f;
    final float aspect2 = ((float) imageWidth / (float) imageHeight) / aspect;
    final float zNear = 1f;
    final float zFar = 100f;

    // compute projection parameters 'normal' frustum
    final float top = (float) Math.tan(fovy * ((float) Math.PI) / 360.0f) * zNear;
    final float bottom = -1.0f * top;
    final float left = aspect2 * bottom;
    final float right = aspect2 * top;
    final float w = right - left;
    final float h = top - bottom;

    // compute projection parameters 'tiled'
    final float l = left + tileX * w / imageWidth;
    final float r = l + tileWidth * w / imageWidth;
    final float b = bottom + tileY * h / imageHeight;
    final float t = b + tileHeight * h / imageHeight;

    pmvMatrix.glFrustumf(l, r, b, t, zNear, zFar);
    // pmvMatrix.glOrthof(-4.0f, 4.0f, -4.0f, 4.0f, 1.0f, 100.0f);
    st.uniform(gl, pmvMatrixUniform);
    st.useProgram(gl, false);

    System.err.println(Thread.currentThread() + " RedSquareES2.reshape FIN");
  }
Beispiel #4
0
  @Override
  public void init(final GLAutoDrawable glad) {
    System.err.println(
        Thread.currentThread() + " RedSquareES2.init: tileRendererInUse " + tileRendererInUse);
    final GL2ES2 gl = glad.getGL().getGL2ES2();

    System.err.println("RedSquareES2 init on " + Thread.currentThread());
    System.err.println("Chosen GLCapabilities: " + glad.getChosenGLCapabilities());
    System.err.println("INIT GL IS: " + gl.getClass().getName());
    System.err.println(JoglVersion.getGLStrings(gl, null, false).toString());
    if (!gl.hasGLSL()) {
      System.err.println("No GLSL available, no rendering.");
      return;
    }
    st = new ShaderState();
    st.setVerbose(true);
    final ShaderCode vp0 =
        ShaderCode.create(
            gl,
            GL2ES2.GL_VERTEX_SHADER,
            this.getClass(),
            "shader",
            "shader/bin",
            "RedSquareShader",
            true);
    final ShaderCode fp0 =
        ShaderCode.create(
            gl,
            GL2ES2.GL_FRAGMENT_SHADER,
            this.getClass(),
            "shader",
            "shader/bin",
            "RedSquareShader",
            true);
    vp0.defaultShaderCustomization(gl, true, true);
    fp0.defaultShaderCustomization(gl, true, true);
    final ShaderProgram sp0 = new ShaderProgram();
    sp0.add(gl, vp0, System.err);
    sp0.add(gl, fp0, System.err);
    st.attachShaderProgram(gl, sp0, true);

    // setup mgl_PMVMatrix
    pmvMatrix = new PMVMatrix();
    pmvMatrix.glMatrixMode(GLMatrixFunc.GL_PROJECTION);
    pmvMatrix.glLoadIdentity();
    pmvMatrix.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
    pmvMatrix.glLoadIdentity();
    pmvMatrixUniform =
        new GLUniformData("mgl_PMVMatrix", 4, 4, pmvMatrix.glGetPMvMatrixf()); // P, Mv
    st.ownUniform(pmvMatrixUniform);
    st.uniform(gl, pmvMatrixUniform);

    // Allocate Vertex Array
    vertices =
        GLArrayDataServer.createGLSL("mgl_Vertex", 3, GL.GL_FLOAT, false, 4, GL.GL_STATIC_DRAW);
    vertices.putf(-2);
    vertices.putf(2);
    vertices.putf(0);
    vertices.putf(2);
    vertices.putf(2);
    vertices.putf(0);
    vertices.putf(-2);
    vertices.putf(-2);
    vertices.putf(0);
    vertices.putf(2);
    vertices.putf(-2);
    vertices.putf(0);
    vertices.seal(gl, true);
    st.ownAttribute(vertices, true);
    vertices.enableBuffer(gl, false);

    // Allocate Color Array
    colors = GLArrayDataServer.createGLSL("mgl_Color", 4, GL.GL_FLOAT, false, 4, GL.GL_STATIC_DRAW);
    colors.putf(1);
    colors.putf(0);
    colors.putf(0);
    colors.putf(1);
    colors.putf(0);
    colors.putf(0);
    colors.putf(1);
    colors.putf(1);
    colors.putf(1);
    colors.putf(0);
    colors.putf(0);
    colors.putf(1);
    colors.putf(1);
    colors.putf(0);
    colors.putf(0);
    colors.putf(1);
    colors.seal(gl, true);
    st.ownAttribute(colors, true);
    colors.enableBuffer(gl, false);

    // OpenGL Render Settings
    gl.glEnable(GL.GL_DEPTH_TEST);
    st.useProgram(gl, false);

    t0 = System.currentTimeMillis();
    System.err.println(Thread.currentThread() + " RedSquareES2.init FIN");
  }