Example #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);
  }
Example #2
0
  public void display(GLAutoDrawable glad) {
    final GL2ES2 gl = glad.getGL().getGL2ES2();
    if (multisample) {
      gl.glEnable(GL.GL_MULTISAMPLE);
    }
    gl.glClearColor(0, 0, 0, 0);
    //      gl.glEnable(GL.GL_DEPTH_TEST);
    //      gl.glDepthFunc(GL.GL_LESS);
    gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);

    st.useProgram(gl, true);

    immModeSink.draw(gl, true);

    st.useProgram(gl, false);
  }
Example #3
0
  public void init(GLAutoDrawable glad) {
    final GL2ES2 gl = glad.getGL().getGL2ES2();

    System.err.println();
    System.err.println("req. msaa: " + multisample);
    System.err.println(
        "Requested: "
            + glad.getNativeSurface().getGraphicsConfiguration().getRequestedCapabilities());
    multisample = multisample & glad.getChosenGLCapabilities().getNumSamples() > 0;
    System.err.println("Chosen   : " + glad.getChosenGLCapabilities());
    System.err.println("has  msaa: " + multisample);
    System.err.println();

    final ShaderCode vp0 =
        ShaderCode.create(
            gl,
            GL2ES2.GL_VERTEX_SHADER,
            MultisampleDemoES2.class,
            "shader",
            "shader/bin",
            "mgl_default_xxx",
            true);
    final ShaderCode fp0 =
        ShaderCode.create(
            gl,
            GL2ES2.GL_FRAGMENT_SHADER,
            MultisampleDemoES2.class,
            "shader",
            "shader/bin",
            "mgl_default_xxx",
            true);
    vp0.defaultShaderCustomization(gl, true, true);
    fp0.defaultShaderCustomization(gl, true, true);

    sp0 = new ShaderProgram();
    sp0.add(gl, vp0, System.err);
    sp0.add(gl, fp0, System.err);
    st.attachShaderProgram(gl, sp0, true);

    pmvMatrixUniform = new GLUniformData("mgl_PMVMatrix", 4, 4, pmvMatrix.glGetPMvMatrixf());
    st.ownUniform(pmvMatrixUniform);
    st.uniform(gl, pmvMatrixUniform);

    // Using predef array names, see
    //    GLPointerFuncUtil.getPredefinedArrayIndexName(glArrayIndex);
    immModeSink =
        ImmModeSink.createGLSL(
            40,
            3,
            GL.GL_FLOAT, // vertex
            4,
            GL.GL_FLOAT, // color
            0,
            GL.GL_FLOAT, // normal
            0,
            GL.GL_FLOAT, // texCoords
            GL.GL_STATIC_DRAW,
            st);
    final int numSteps = 20;
    final double increment = Math.PI / numSteps;
    final double radius = 1;
    immModeSink.glBegin(GL.GL_LINES);
    for (int i = numSteps - 1; i >= 0; i--) {
      immModeSink.glVertex3f(
          (float) (radius * Math.cos(i * increment)),
          (float) (radius * Math.sin(i * increment)),
          0f);
      immModeSink.glColor4f(1f, 1f, 1f, 1f);
      immModeSink.glVertex3f(
          (float) (-1.0 * radius * Math.cos(i * increment)),
          (float) (-1.0 * radius * Math.sin(i * increment)),
          0f);
      immModeSink.glColor4f(1f, 1f, 1f, 1f);
    }
    immModeSink.glEnd(gl, false);

    st.useProgram(gl, false);
  }
Example #4
0
 public void dispose(GLAutoDrawable glad) {
   final GL2ES2 gl = glad.getGL().getGL2ES2();
   immModeSink.destroy(gl);
   immModeSink = null;
   st.destroy(gl);
 }