2017-01-21 6 views
-2

バックグラウンドのないスプライトのレンダリング方法は?私はスプライト全体をレンダリングすることができますが、背景を無視したいです。私はそれが可能であることを知っている、私は脛骨でそのようなレンダリングを見たので。脛骨のスプライトはピンクの背景色をしていますが、これは無視されます。
スプライト:LWJGL、Slick Util、背景のない2dレンダリングスプライト

public class Sprite { 

private Texture texture; 


private float sx; 
private float sy; 
private String extension; 
private String path; 


/** 
* 
* @param sx 
* @param sy 
* @param extension 
* @param path 
*/ 
public Sprite(float sx, float sy, String extension, String path) { 

    this.sx = sx; 
    this.sy = sy; 
    this.extension = extension; 
    this.path = path; 
} 


public void render() { 

    try { 
     initTexture(); 

    } catch (Exception e) { 
     System.out.println(e.toString()); 
    } 
    Color.white.bind(); 
    texture.bind(); 
    glBegin(GL_QUADS); 


    glTexCoord2f(0, 0); 
    glVertex2f(0, 0); 
    glTexCoord2f(0, 1); 
    glVertex2f(0, texture.getTextureHeight()*2); 
    glTexCoord2f(1, 1); 
    glVertex2f(texture.getTextureWidth()*2, texture.getTextureHeight()*2); 
    glTexCoord2f(1, 0); 
    glVertex2f(texture.getTextureWidth()*2, 0); 


    glEnd(); 


} 

public float getSx() { 
    return sx; 
} 

public void setSx(float sx) { 
    this.sx = sx; 
} 

public float getSy() { 
    return sy; 
} 

public void setSy(float sy) { 
    this.sy = sy; 
} 

public void initTexture() throws Exception { 

    texture = TextureLoader.getTexture(extension, ResourceLoader.getResourceAsStream(path)); 


} 

}

答えて

0

私はあなたがタイルセットあなたのゲームのために、紫色のグリッドを持って使用しようとしていることを推測しています。

ピンクの色を透明に置き換えることをお勧めします。 はその後、あなたのプログラムでは、単に実行します。

glEnable(GL_BLEND); 
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 

紫のタイルセット/ SpriteSheetsは古いゲームで使用されていました。実際にそれらの必要はありません。

関連する問題