Wednesday, 21 August 2013

Can't draw 1280x800 texture in LWJGL

Can't draw 1280x800 texture in LWJGL

My image is 1280x800, and my screen size is 1280x800. it should draw
perfectly. But it right now it draws a square texture on my upper left
corner of my screen that's out of scale and not large enough. I don't know
why it doesn't work, I've tried writing the size of the texture larger
when drawing and it seems to work sortof, but I don't know why it didn't
work when drawing on a 1280x800 quad.

This is my OPENGL and display setup code:
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);
This is my code for drawing the textures:
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?

No comments:

Post a Comment