有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java如何在从glTexImage2D()分配后编辑纹理的像素颜色

现在我想在我将像素颜色初始化到lwjgl中的内存后编辑它们

除了重新实例化并用imageIO重写图像之外,我什么都做不了,但悬垂非常可怕

我的代码在下面

    public static int loadTexture(String fileName) throws Exception {
    PNGDecoder decoder = new PNGDecoder(Texture.class.getResourceAsStream(fileName));

     ByteBuffer buf = ByteBuffer.allocateDirect(
             4 * decoder.getWidth() * decoder.getHeight());
     decoder.decode(buf, decoder.getWidth() * 4, Format.RGBA);
     buf.flip();

     int textureId = glGenTextures();
     glBindTexture(GL_TEXTURE_2D, textureId);
     glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
     //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
     //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
     glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, decoder.getWidth(), decoder.getHeight(), 0, GL_RGBA, GL_UNSIGNED_BYTE, buf);
     glGenerateMipmap(GL_TEXTURE_2D);
     return textureId;
}

还有这个

    public void render() {
if (texture != null) {
      // Activate first texture bank
      glActiveTexture(GL_TEXTURE0);
      // Bind the texture
      glBindTexture(GL_TEXTURE_2D, texture.getId());
  }
  // Draw the mesh
  glBindVertexArray(getVaoId());
  glEnableVertexAttribArray(0);
  glEnableVertexAttribArray(1);
  glEnableVertexAttribArray(2);

  glDrawElements(GL_TRIANGLES, getVertexCount(), GL_UNSIGNED_INT, 0);

  // Restore state
  glDisableVertexAttribArray(0);
  glDisableVertexAttribArray(1);
  glDisableVertexAttribArray(2);
  glBindVertexArray(0);
 }

我想做的是使用ID并设置一个像素,比如:

setPixel(int-id、pixelX、pixelY、int-newColor)

有没有办法做到这一点,我能想到的唯一方法就是使用不安全的,这是很难理解的,很容易打破


共 (0) 个答案