OpenGL Mipmap Texture_2D

时间:2013-02-05 23:57:21

标签: java opengl lwjgl mipmaps

我是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),图像就不会成长。所以问题是我需要Image随着分辨率的增长而成长。

0 个答案:

没有答案