【发布时间】:2015-11-01 00:14:24
【问题描述】:
所以,我正在使用 lwjgl 制作 2D 游戏,而渲染带纹理的四边形将不起作用。 我有 3 个纹理,名称是:
DirtTexture.png, GrassTexture.png, WaterTexture.png
所有都位于“res”包内。
我的代码是这样的:
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();
}
}
我的问题是它呈现白色纹理,即使我选择的纹理不是白色的。 有谁知道为什么?谢谢:)
【问题讨论】:
标签: java opengl 2d lwjgl texture2d