2015-08-08 161 views
0

因此,我正在使用lwjgl製作2D遊戲,渲染紋理四方將不起作用。 我有3個紋理,名稱是:渲染紋理四方不工作

DirtTexture.png, GrassTexture.png, WaterTexture.png 

所有位於「資源」包內。

我的代碼是這樣的:

public static void DrawQuadTex(Texture tex, float x, float y, float width, float height) { 

    tex.bind(); 
    glTranslatef(x, y, 0); 
    glBegin(GL_QUADS); 
    glTexCoord2f(0, 0); 
    glVertex2f(0, 0); 
    glTexCoord2f(1, 0); 
    glVertex2f(width, 0); 
    glTexCoord2f(1, 1); 
    glVertex2f(width, height); 
    glTexCoord2f(0, 1); 
    glVertex2f(0, height); 
    glLoadIdentity(); 
    glEnd(); 

} 

public static Texture LoadTexture(String path, String fileType) { 

    Texture tex = null; 
    InputStream in = ResourceLoader.getResourceAsStream(path); 
    try { 
     tex = TextureLoader.getTexture(fileType, in); 
    } catch (IOException e) { 
     e.printStackTrace(); 
    } 
    return tex; 

} 

它被稱爲是這樣的:

public class Boot { 

public Boot() { 

    BeginSession(); 

    Texture t = LoadTexture("res/GrassTexture.png", "PNG"); 
    while(!Display.isCloseRequested()) { 

     DrawQuadTex(t, 0, 0, 64, 64); 

     Display.update(); 
     Display.sync(60); 

    } 

    Display.destroy(); 

} 

    public static void main(String[] args) { 
     new Boot(); 
    } 

} 

我的問題是,它呈現白色的質感,即使我選擇的紋理不是白色。 任何人都知道爲什麼?謝謝:)

回答

0

我不知道爲什麼,但在顯示固定的問題,同時2個圖像...

0

您可能需要使用繪圖之前清除屏幕:

glClear(GL_COLOR_BUFFER_BIT, GL_DEPTH_BUFFER_BIT); 

tex.bind(); 
glTranslatef(x, y, 0); 
glBegin(GL_QUADS); 
...