为什么LWJGL奇怪地绘制我的图像?

时间:2014-07-05 11:32:32

标签: java lwjgl

大家好我想把100 x 100的图像画到我的屏幕上。然而,当我绘制它时,openGL将其绘制为我的正方形的一半大小,在右边缘和底边缘之间有一种边框。

这是我的代码:

package biz.boulter.lwjglgame;

import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
import org.newdawn.slick.opengl.Texture;
import org.newdawn.slick.opengl.TextureLoader;

import static org.lwjgl.opengl.GL11.*;

public class Game
{   
public static final int WIDTH = 1000;
public static final int HEIGHT = WIDTH / 16 * 9;

private static Texture t;

private static void render()
{
    glClear(GL_COLOR_BUFFER_BIT);

    t.bind();

    glBegin(GL_QUADS);
        glTexCoord2f(0, 0);
        glVertex2i(100, 100); // top-left
        glTexCoord2f(1, 0);
        glVertex2i(200, 100); // top-right
        glTexCoord2f(1, 1);
        glVertex2i(200, 200); // bottom-right
        glTexCoord2f(0, 1);
        glVertex2i(100, 200); // bottom-left
    glEnd();

}

private static Texture loadTexture(String path) throws Exception{
    return TextureLoader.getTexture("PNG", Game.class.getResourceAsStream(path));
}

public static void main(String[] args)
{
    try
    {

        Display.setDisplayMode(new DisplayMode(1000, 1000 / 16*9));
        Display.create();

        t = loadTexture("/assets/guy.png");

        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        glOrtho(0, 1000, 1000/16*9, 0, 1, -1);
        glEnable(GL_TEXTURE_2D);
        glMatrixMode(GL_MODELVIEW);

        while(!Display.isCloseRequested())
        {
            render();
            Display.sync(60);
            Display.update();
        }   
    }catch(Exception e)
    {
        e.printStackTrace();
        System.exit(0);
    }

}
}

为什么要这样做。我也使用slick-util.jar进行纹理加载。

截图:

http://oi59.tinypic.com/13zyflk.jpg

0 个答案:

没有答案