2015-08-08 110 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); 
...