我目前正在尝试处理我的 Java 项目,其中包括 LWJGL。到目前为止,我的“游戏”已经到了我现在在屏幕上绘制图像的地步。
我遇到的问题是绘制的图像是用黑框绘制的,而且它的大小不正确。这是它的外观图像。
这是实际的红色正方形图像的样子:
这是我用于使用 OpenGL 进行渲染的代码,我无法弄清楚我做错了什么。
public class Renderer {
//Integers used for player cordinates, Taken from player class by using Static variables
int playerX;
int playerY;
SpriteSheetLoader spriteLoader;
Texture player;
public Renderer(){
}
public void initRenderer(){
//Initialize OpenGL
GL11.glMatrixMode(GL11.GL_PROJECTION);
GL11.glLoadIdentity(); // Resets any previous projection matrices
GL11.glOrtho(0, 800, 600, 0, 1, -1);
GL11.glMatrixMode(GL11.GL_MODELVIEW);
try {
player = TextureLoader.getTexture("PNG",ResourceLoader.getResourceAsStream("res/PaddleTemp.png"));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void update(){
GL11.glClear( GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT );
playerX = Player.playerX; //Gets player x and y from the player class using static variables
playerY = Player.playerY;
player.bind();
GL11.glBegin(GL11.GL_QUADS);
GL11.glTexCoord2f(0, 0); //top left
GL11.glVertex2f(playerX, playerY);
GL11.glTexCoord2f(1,0); //Top right
GL11.glVertex2f(playerX + 50, playerY);
GL11.glTexCoord2f(1, 1); //Bottom right
GL11.glVertex2f(playerX + 50, playerY + 150);
GL11.glTexCoord2f(0, 1); //bottom left
GL11.glVertex2f(playerX, playerY + 150);
GL11.glEnd();
}