问题
I use LWJGL to render everything in my game I am making, and I use it to render backgrounds, which is okay, but when I render things less than the full size of the display, it shows random lines and the image is slanted. Here is a screenshot picture;
See the split line about a third of the way across, and the line on the left hand side.
http://i.stack.imgur.com/6O9dI.png
And here is my code;
ImageLoader.STAT_BAR.bind();
GL11.glBegin(GL11.GL_QUADS);
GL11.glTexCoord2f(0,0); //TOP LEFT
GL11.glVertex2f(0,0);
GL11.glTexCoord2f(1,0); //TOP RIGHT
GL11.glVertex2f(ImageLoader.STAT_BAR.getTextureWidth(),0);
GL11.glTexCoord2f(1,1); //BOTTOM RIGHT
GL11.glVertex2f(ImageLoader.STAT_BAR.getTextureWidth(), ImageLoader.STAT_BAR.getTextureHeight());
GL11.glTexCoord2f(0,1); //BOTTOM LEFT
GL11.glVertex2f(0, ImageLoader.STAT_BAR.getTextureHeight());
GL11.glEnd();
PS. ImageLoad is just a class I made that get the images and loads them. It's very simple and works for all the images. It's just the rendering that isn't working.
EDIT: Even when changing GL11.glVertex2f to 2i, it still doesnt work :/
回答1:
Sorry, I'm not absolutely sure what the problem is. I can't seem to reproduce it afterwards, unfortunately. Yet I figured it should be solved by one of the following:
- Unsupported Image Size
OpenGL relies heavily on so images, whose resolution's width and height are powers of 2 (when width/height=n*2). If the images files aren't up to that specification, LWJGL might act oddly. Also, don't worry about the image files being squished. That's dependent on the vertex input, not on the texture input.
- Unsupported Image Extension
Try saving your image files as non-interlaced PNG files. Slick_Util, or whatever you use for loading the image files, might not fully support the images you're giving to it.
- Correction Hints
As a last resort, you could add the following lines of code to your initialization code:
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
Hopefully one of these tips helps you.
来源:https://stackoverflow.com/questions/8618802/lwjgl-not-rendering-textures-correctly