我的图像是 1280x800,我的屏幕尺寸是 1280x800。它应该画得很完美。但它现在在我屏幕的左上角绘制了一个方形纹理,它超出了比例并且不够大。我不知道为什么它不起作用,我尝试在绘图时将纹理的大小写得更大,它似乎可以工作,但我不知道为什么在 1280x800 四边形上绘图时它不起作用.
这是我的 OPENGL 和显示设置代码:
try {
DisplayMode displayMode = null;
DisplayMode[] modes = Display.getAvailableDisplayModes();
for (int i = 0; i < modes.length; i++) {
if (modes[i].getWidth() == World.SCREEN_WIDTH && modes[i].getHeight() == World.SCREEN_HEIGHT && modes[i].isFullscreenCapable()) {
displayMode = modes[i];
}
}
Display.setDisplayMode(displayMode);
Display.setFullscreen(false);
Display.create();
} catch (LWJGLException e) {
e.printStackTrace();
}
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, World.SCREEN_WIDTH, World.SCREEN_HEIGHT, 0, 1, -1);
glMatrixMode(GL_MODELVIEW);
glEnable(GL_TEXTURE_2D);
这是我绘制纹理的代码:
background = TextureLoader.getTexture("PNG", new FileInputStream(new File("res/menu/background.png")));
girl_01 = TextureLoader.getTexture("PNG", new FileInputStream(new File("res/menu/girl_01.png")));
girl_02 = TextureLoader.getTexture("PNG", new FileInputStream(new File("res/menu/girl_02.png")));
glBindTexture(GL_TEXTURE_2D, background.getTextureID());
glPushMatrix();
glBegin(GL_QUADS);
glTexCoord2f(0, 0);
glVertex2f(0, 0); // Upper left
glTexCoord2f(1, 0);
glVertex2f(World.SCREEN_WIDTH, 0); // Upper right
glTexCoord2f(1, 1);
glVertex2f(World.SCREEN_WIDTH, World.SCREEN_HEIGHT); // Lower right
glTexCoord2f(0, 1);
glVertex2f(0, World.SCREEN_HEIGHT); // Lower left
glEnd();
glPopMatrix();
Edit : After searching for hours, I've discovered, I've arrived at a weird solution in my opinion, I made the image 2048x1024 and left the extra blank. it worked. BUT this is how it should work? So I'm suppose to make all image size powers of two leaving the extra space blank? Or is there a better way?