示例#1
0
文件: Tile.java 项目: joaogl/LD29
  protected void compile() {
    vao = glGenVertexArrays();
    glBindVertexArray(vao);
    {
      vbo = glGenBuffers();
      glBindBuffer(GL_ARRAY_BUFFER, vbo);
      {
        glBufferData(GL_ARRAY_BUFFER, Buffer.createFloatBuffer(vertices), GL_STATIC_DRAW);
        glVertexAttribPointer(0, 3, GL_FLOAT, false, 0, 0);
      }
      glBindBuffer(GL_ARRAY_BUFFER, 0);

      vio = glGenBuffers();
      glBindBuffer(GL_ARRAY_BUFFER, vio);
      {
        glBufferData(GL_ARRAY_BUFFER, Buffer.createByteBuffer(indices), GL_STATIC_DRAW);
      }
      glBindBuffer(GL_ARRAY_BUFFER, 0);

      vto = glGenBuffers();
      glBindBuffer(GL_ARRAY_BUFFER, vto);
      {
        glBufferData(GL_ARRAY_BUFFER, Buffer.createByteBuffer(texCoords), GL_STATIC_DRAW);
        glVertexAttribPointer(1, 3, GL_UNSIGNED_BYTE, false, 0, 1);
      }
      glBindBuffer(GL_ARRAY_BUFFER, 0);
    }
    glBindVertexArray(0);
  }
示例#2
0
文件: Player.java 项目: joaogl/LD29
  protected void compile() {
    vao = glGenVertexArrays();
    glBindVertexArray(vao);
    {
      vbo = glGenBuffers();
      glBindBuffer(GL_ARRAY_BUFFER, vbo);
      {
        glBufferData(GL_ARRAY_BUFFER, Buffer.createFloatBuffer(vertices), GL_STATIC_DRAW);
        glVertexAttribPointer(0, 3, GL_FLOAT, false, 0, 0);
      }
      glBindBuffer(GL_ARRAY_BUFFER, 0);

      vio = glGenBuffers();
      glBindBuffer(GL_ARRAY_BUFFER, vio);
      {
        glBufferData(GL_ARRAY_BUFFER, Buffer.createByteBuffer(indices), GL_STATIC_DRAW);
      }
      glBindBuffer(GL_ARRAY_BUFFER, 0);

      vto = glGenBuffers();
      glBindBuffer(GL_ARRAY_BUFFER, vto);
      {
        glBufferData(GL_ARRAY_BUFFER, Buffer.createByteBuffer(texCoords), GL_STATIC_DRAW);
        glVertexAttribPointer(1, 3, GL_UNSIGNED_BYTE, false, 0, 1);
      }
      glBindBuffer(GL_ARRAY_BUFFER, 0);
    }
    glBindVertexArray(0);

    glActiveTexture(GL_TEXTURE1);
    shader.bind();
    int uniform = glGetUniformLocation(shader.getID(), "texture");
    glUniform1i(uniform, 1);
    shader.release();
  }
示例#3
0
文件: Tile.java 项目: joaogl/LD29
  public void bindUniforms(List<Light> lights) {
    if (lights.size() > 10) {
      System.err.println("Too many lights.");
      return;
    }
    float[] positions = new float[10 * 2];
    float[] colors = new float[10 * 3];
    float[] intensities = new float[10];

    for (int i = 0; i < lights.size() * 2; i += 2) {
      positions[i] = lights.get(i >> 1).getX() - lights.get(i >> 1).getXOffset();
      positions[i + 1] =
          GameSettings.height - lights.get(i >> 1).getY() + lights.get(i >> 1).getYOffset();
    }

    for (int i = 0; i < lights.size(); i++) {
      intensities[i] = lights.get(i).intensity;
    }

    for (int i = 0; i < lights.size() * 3; i += 3) {
      colors[i] = lights.get(i / 3).vc.x;
      colors[i + 1] = lights.get(i / 3).vc.y;
      colors[i + 2] = lights.get(i / 3).vc.z;
    }

    shader.bind();
    int uniform = glGetUniformLocation(shader.getID(), "lightPosition");
    glUniform2(uniform, Buffer.createFloatBuffer(positions));

    uniform = glGetUniformLocation(shader.getID(), "lightColor");
    glUniform3(uniform, Buffer.createFloatBuffer(colors));

    uniform = glGetUniformLocation(shader.getID(), "lightIntensity");
    glUniform1(uniform, Buffer.createFloatBuffer(intensities));
    shader.release();
  }