2013-01-17 29 views
1

我想在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(); 
} 

任何幫助將不勝感激!

回答

1

你的混合配置似乎很好。他們和我的一模一樣,實際上工作。然而,我認爲錯誤在於newTextureData(GLProfile glp ...方法),您的方法說newTextureData(file ... newtexturedata()方法不接受File對象,而是期望GLProfile配置文件作爲第一個參數。正如我的文檔http://jogamp.org/deployment/jogamp-next/javadoc/jogl/javadoc/com/jogamp/opengl/util/texture/TextureIO.html

我建議在閱讀您更改線路:

TextureData data = TextureIO.newTextureData(file, GL.GL_RGBA, GL.GL_SRGB8_ALPHA8, false, TextureIO.PNG); 
textTexture = TextureIO.newTexture(data); 

textTexture = TextureIO.newTexture(file,mipmap); 

textTexture = TextureIO.newTexture(cl.getResource("/my/file/path/myimage.png"), false, null); 

改爲。如果你的文件變量是正確的,它應該工作。

如需進一步JOGL讀數你應該考慮這些教程:http://www3.ntu.edu.sg/home/ehchua/programming/opengl/JOGL2.0.html

對於JOGL文檔,你應該考慮閱讀:http://jogamp.org/deployment/jogamp-next/javadoc/jogl/javadoc