我用谷歌搜索了很多,但找不到这个问题的答案。我知道如何加载图像,我需要加载不是 256 x 256 或 2 的直接幂的图像。
就像我如何加载 128 x 384 或类似的图像。
我现在使用的是:
加载图像:
public static Texture cow = loadTexture("res/cow.png");
private static Texture loadTexture(String file){
try {
return TextureLoader.getTexture("JPG", new FileInputStream(new File(file)));
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
现在将其绘制在 3D 多边形面上:
txt.bind();
GL11.glBegin(GL11.GL_QUADS);
{
//GL11.glColor3d(lightLevel, lightLevel, lightLevel);
GL11.glColor3d(l, l, l);
GL11.glTexCoord2f(0,0); GL11.glVertex3f(x1,y1, z1);
GL11.glTexCoord2f(1,0); GL11.glVertex3f(x1+(x2-x1), y1,z1);
GL11.glTexCoord2f(1,1); GL11.glVertex3f(x1+(x2-x1), y1+(y2-y1), z1+(z2-z1));
GL11.glTexCoord2f(0,1); GL11.glVertex3f(x1,y1+(y2-y1), z1+(z2-z1));
}
GL11.glEnd();
现在效果很好,我只需要加载不是 2 的幂的图像。
最佳答案
你可以使用 slick2d,它更容易使用并且可以与 lwjgl 一起使用!您所要做的就是:
Image title = null;
public static void main(String[] args) {
}
@Override
public void init(GameContainer Gc, StateBasedGame Sbg)
throws SlickException {
/**
* Images
*/
title = new Image("gfx/main_menu/title/new_title.png");
}
@Override
public void render(GameContainer Gc, StateBasedGame Sbg, Graphics G)
throws SlickException {
/**
* Background
*/
G.setColor(Color.white);
G.fillRect(0, 0, w*s, h*s);
/**
* Images
*/
title.draw(titleY*s,titleX*s);
}
关于java - 如何使用 LWJGL 加载图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16596525/