我是openGL的新手,我使用LWJGL。
我不知道如何查看“Mipmaps 是否正常工作”
这就是我加载图像 (64x64) 的方式:
private int loadPNGTexture(String filename) {
ByteBuffer buf = null;
int tWidth = 0;
int tHeight = 0;
try {
InputStream in = new FileInputStream(ClassLoader.getSystemResource(filename).getPath());
decoder = new PNGDecoder(in);
tWidth = decoder.getWidth();
tHeight = decoder.getHeight();
buf = BufferUtils.createByteBuffer(4 * decoder.getWidth() * decoder.getHeight());
decoder.decode(buf, decoder.getWidth() * 4, PNGDecoder.Format.RGBA);
buf.flip();
in.close();
} catch (IOException e) {
e.printStackTrace();
System.exit(-1);
}
int texId = GL11.glGenTextures();
GL13.glActiveTexture(GL13.GL_TEXTURE0);
GL11.glBindTexture(GL11.GL_TEXTURE_2D, texId);
GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1);
GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGB, tWidth, tHeight, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, buf);
GL30.glGenerateMipmap(GL11.GL_TEXTURE_2D);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_REPEAT);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_REPEAT);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR_MIPMAP_LINEAR);
return texId;
}
这就是我绘制图像的方式:
public void drawGL() {
GL11.glPushMatrix();
GL11.glBindTexture(GL11.GL_TEXTURE_2D, playerTextures[0]);
GL11.glBegin(GL11.GL_TRIANGLE_STRIP);
GL11.glTexCoord2f(1, 0);
GL11.glVertex2f(decoder.getWidth(), 0);
GL11.glTexCoord2f(1, 1);
GL11.glVertex2f(decoder.getWidth(), decoder.getWidth());
GL11.glTexCoord2f(0, 0);
GL11.glVertex2f(0, 0);
GL11.glTexCoord2f(0, 1);
GL11.glVertex2f(0, decoder.getWidth());
GL11.glEnd();
GL11.glPopMatrix();
}
绘制是正确的,我可以看到我的图像,但如果我更改 DisplayMode(从 800x600 到 1280x960),图像不会长大。所以问题是我需要图像长大以适应分辨率。