我想在jogl中使用透明png編寫文本,但我無法爲我的生活找出如何使其工作。我在互聯網上到處都是,但適合JOGL的文檔很少。無法獲得PNG透明度在JOGL中工作
下面是如何載入紋理:
private void loadTEXTure() //Har har, get it?
{
File file = new File(fontMap);
try
{
TextureData data = TextureIO.newTextureData(file, GL.GL_RGBA, GL.GL_SRGB8_ALPHA8, false, TextureIO.PNG);
textTexture = TextureIO.newTexture(data);
}
catch (GLException e) { e.printStackTrace(); }
catch (IOException e) { e.printStackTrace(); }
}
這是巴新的顯示方式:
public void displayCharacter(GL gl, int[] textureBounds, int x1, int y1, int x2, int y2)
{
float texCordsx1 = ((float) textureBounds[0])/((float) textTexture.getWidth());
float texCordsy1 = ((float) textureBounds[1])/((float) textTexture.getHeight());
float texCordsx2 = ((float) textureBounds[2])/((float) textTexture.getWidth());
float texCordsy2 = ((float) textureBounds[3])/((float) textTexture.getHeight());
gl.glEnable(GL.GL_BLEND);
gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
textTexture.enable();
textTexture.bind();
gl.glBegin(GL.GL_QUADS);
gl.glTexCoord2f(texCordsx1, texCordsy1);
gl.glVertex2f(x1, y1);
gl.glTexCoord2f(texCordsx1, texCordsy2);
gl.glVertex2f(x1, y2);
gl.glTexCoord2f(texCordsx2, texCordsy2);
gl.glVertex2f(x2, y2);
gl.glTexCoord2f(texCordsx2, texCordsy1);
gl.glVertex2f(x2, y1);
gl.glEnd();
textTexture.disable();
}
任何幫助將不勝感激!