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 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);
  }