Reputation: 1
Texture texture = loadTexture("main_menu/bg");
texture.bind();
glBegin(GL_QUADS);
glTexCoord2f(0, 0);
glVertex2i(1, 1);
glTexCoord2f(0, 1);
glVertex2i(1, 720);
glTexCoord2f(1, 1);
glVertex2i(1280, 720);
glTexCoord2f(1, 0);
glVertex2i(1280, 1);
glEnd();
I use LWJGL library with slick2D. I am rendering textures with above way, but textures has incorrect position. I have 1280x720 fullscreen window and I render background texture over window but texture is reduced at X axis to 2/3 of window and at Y axis at 3/4 of window.
I am adding setup of openGL, so here it is:
WINDOW_WIDTH = 1280;
WINDOW_HEIGHT = 720;
glEnable(GL_TEXTURE_2D);
glDisable(GL_DEPTH_TEST);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, WINDOW_WIDTH, WINDOW_HEIGHT, 0, -1, 1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glViewport(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT);
And here is method for loading textures:
private Texture loadTexture(String key) {
try {
return TextureLoader.getTexture("PNG", new FileInputStream(
new File("res/" + key + ".png")));
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
Upvotes: 0
Views: 276
Reputation: 21377
In OpenGL1, texture widths and heights must be integral powers of 2, e.g.
128x128, 256x256, 512x64, ...
Yours seem to be 1280x720, which is not one. :) Note that your dimensions don't matter in OpenGL2.
Upvotes: 0