简体   繁体   English

LWJGL无法正确渲染纹理?

[英]LWJGL not rendering textures correctly?

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. 我使用LWJGL渲染我正在制作的游戏中的所有内容,并使用它来渲染背景,这没关系,但是当我渲染的内容小于显示器的整个尺寸时,它会显示随机线条并且图像会倾斜。 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 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. PS。 ImageLoad is just a class I made that get the images and loads them. ImageLoad只是我制作的用于获取图像并加载它们的类。 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 :/ 编辑:即使将GL11.glVertex2f更改为2i,它仍然不起作用:/

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). OpenGL严重依赖于此类图像,其分辨率的宽度和高度为2的幂(当width / height = n * 2时)。 If the images files aren't up to that specification, LWJGL might act oddly. 如果图像文件不符合该规范,则LWJGL可能会表现异常。 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. 尝试将图像文件另存为非隔行PNG文件。 Slick_Util, or whatever you use for loading the image files, might not fully support the images you're giving to it. Slick_Util或用于加载图像文件的任何方法,可能都不完全支持您为其提供的图像。

  • 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. 希望这些技巧之一对您有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM