Пример #1
0
  private void initVertexArray(GL3 gl3) {

    gl3.glGenVertexArrays(1, vertexArrayName);
    gl3.glBindVertexArray(vertexArrayName.get(0));
    {
      gl3.glBindBuffer(GL_ARRAY_BUFFER, bufferName.get(Buffer.VERTEX));
      {
        int stride = (2 + 3) * Float.BYTES;
        int offset = 0 * Float.BYTES;

        gl3.glEnableVertexAttribArray(Semantic.Attr.POSITION);
        gl3.glVertexAttribPointer(Semantic.Attr.POSITION, 2, GL_FLOAT, false, stride, offset);

        offset = 2 * Float.BYTES;
        gl3.glEnableVertexAttribArray(Semantic.Attr.COLOR);
        gl3.glVertexAttribPointer(Semantic.Attr.COLOR, 3, GL_FLOAT, false, stride, offset);
      }
      gl3.glBindBuffer(GL_ARRAY_BUFFER, 0);

      gl3.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bufferName.get(Buffer.ELEMENT));
    }
    gl3.glBindVertexArray(0);

    checkError(gl3, "initVao");
  }
Пример #2
0
  @Override
  public void init(GLAutoDrawable glad) {
    GL3 gl3 = glad.getGL().getGL3();

    try {
      shaders.add(
          GLSLHelpers.createShader(gl3, getClass(), GL3.GL_VERTEX_SHADER, "glsl/simple_vs"));
      shaders.add(
          GLSLHelpers.createShader(gl3, getClass(), GL3.GL_FRAGMENT_SHADER, "glsl/simple_fs"));
      program = GLSLHelpers.createProgram(gl3, shaders);

      gl3.glGenVertexArrays(1, VAO, 0);
      gl3.glBindVertexArray(VAO[0]);

      gl3.glGenBuffers(1, VBO, 0);
      gl3.glBindBuffer(GL3.GL_ARRAY_BUFFER, VBO[0]);
      FloatBuffer buffer = GLBuffers.newDirectFloatBuffer(TRIANGLE);
      gl3.glBufferData(GL3.GL_ARRAY_BUFFER, buffer.capacity() * 4, buffer, GL3.GL_STATIC_DRAW);
      gl3.glEnableVertexAttribArray(0);
      gl3.glVertexAttribPointer(0, 2, GL3.GL_FLOAT, false, 0, 0);

      gl3.glBindVertexArray(0);
    } catch (Throwable t) {
      t.printStackTrace();
    }
  }
Пример #3
0
  private boolean initVertexArray(GL3 gl3) {

    gl3.glGenVertexArrays(1, vertexArrayName);
    gl3.glBindVertexArray(vertexArrayName.get(0));
    {
      gl3.glBindBuffer(GL_ARRAY_BUFFER, bufferName.get(0));
      gl3.glVertexAttribPointer(Semantic.Attr.POSITION, 2, GL_FLOAT, false, Vertex_v2fv2f.SIZE, 0);
      gl3.glVertexAttribPointer(
          Semantic.Attr.TEXCOORD, 2, GL_FLOAT, false, Vertex_v2fv2f.SIZE, Vec2.SIZE);
      gl3.glBindBuffer(GL_ARRAY_BUFFER, 0);

      gl3.glEnableVertexAttribArray(Semantic.Attr.POSITION);
      gl3.glEnableVertexAttribArray(Semantic.Attr.TEXCOORD);
    }
    gl3.glBindVertexArray(0);

    return checkError(gl3, "initVertexArray");
  }
Пример #4
0
  private boolean initVertexArray(GL3 gl3) {

    gl3.glGenVertexArrays(1, vertexArrayName);
    gl3.glBindVertexArray(vertexArrayName.get(0));
    {
      gl3.glBindBuffer(GL_ARRAY_BUFFER, bufferName.get(Buffer.VERTEX));
      gl3.glVertexAttribPointer(
          Semantic.Attr.POSITION, 2, GL_FLOAT, false, glf.Vertex_v2fv2f.SIZE, 0);
      gl3.glVertexAttribPointer(
          Semantic.Attr.TEXCOORD, 2, GL_FLOAT, false, glf.Vertex_v2fv2f.SIZE, Vec2.SIZE);
      gl3.glBindBuffer(GL_ARRAY_BUFFER, 0);

      gl3.glEnableVertexAttribArray(Semantic.Attr.POSITION);
      gl3.glEnableVertexAttribArray(Semantic.Attr.TEXCOORD);

      gl3.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bufferName.get(Buffer.ELEMENT));
    }
    gl3.glBindVertexArray(0);

    return true;
  }