如何在 jogl 中使用 TextureIO.newTextureData()

how to use TextureIO.newTextureData() in jogl

我正在尝试创建透明纹理,但我不知道 newTextureData() 中的内部格式参数是什么。我尝试使用 GL4。GL_RGBA32F,但纹理仍然不透明。

代码看起来像这样:

//clear background (in a GameLoop class)
gl.glClearColor(0.0f, 0.0f, 0.2f, 1.0f);
gl.glClear(gl.GL_COLOR_BUFFER_BIT);

//update sprite vao (method in Sprite class)
gl.glBindVertexArray(vao[0]);

gl.glBindBuffer(GL4.GL_ELEMENT_ARRAY_BUFFER, ebo[0]);
gl.glBindBuffer(GL.GL_ARRAY_BUFFER, vbo[0]);

gl.glBufferData(GL4.GL_ELEMENT_ARRAY_BUFFER, indexData.capacity() * 4L, indexData, GL4.GL_STATIC_DRAW);
gl.glBufferData(GL4.GL_ARRAY_BUFFER, vertexData.capacity() * 4L, vertexData, GL.GL_STATIC_DRAW);

int stride = (3 + vertexColorLength + 2) * 4;
int textureCoordsOffset = stride - 2 * 4;

gl.glVertexAttribPointer(0, 3, GL.GL_FLOAT, false, stride, 0);
gl.glEnableVertexAttribArray(0);
gl.glVertexAttribPointer(1, vertexColorLength, GL.GL_FLOAT, false, stride, 12);
gl.glEnableVertexAttribArray(1);
gl.glVertexAttribPointer(2, 2, GL.GL_FLOAT, false, stride, textureCoordsOffset);
gl.glEnableVertexAttribArray(2);

gl.glBindVertexArray(0);
gl.glBindBuffer(GL4.GL_ELEMENT_ARRAY_BUFFER, 0);
gl.glBindBuffer(GL4.GL_ARRAY_BUFFER, 0);

//load textures (in Sprite constructor)
for (String path : texturePaths) {
  File textureFile = new File(path);
  TextureData textureData;

  try {
    textureData = TextureIO.newTextureData(gl.getGLProfile(), textureFile, GL4.GL_RGBA16, GL4.GL_RGBA, false, TextureIO.PNG);
    textures.add(TextureIO.newTexture(textureData));
  } catch (IOException e) {
    System.err.println("Failed to load Sprite texture");
    e.printStackTrace();
  }
}

//diplay Sprite (method in Sprite class)
program.setUniforms();
gl.glBindVertexArray(vao[0]);
program.use();
gl.glActiveTexture(GL.GL_TEXTURE0);
gl.glUniform1i(gl.glGetUniformLocation(program.ID, "u_texture0"), 0);
textures.get(0).enable(gl);
textures.get(0).bind(gl);
gl.glUniform1i(gl.glGetUniformLocation(program.ID, "u_textureAmnt"), textures.size());
gl.glDrawElements(GL.GL_TRIANGLES, 6, GL.GL_UNSIGNED_INT, 0);
for(Texture texture : textures){
  texture.disable(gl);
}

我忘记启用 Gl_Blend...