LWJGL无法正确渲染纹理? [英] LWJGL not rendering textures correctly?

查看:87
本文介绍了LWJGL无法正确渲染纹理?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用LWJGL渲染我正在制作的游戏中的所有内容,并使用它来渲染背景,这没关系,但是当我渲染的内容小于显示器的整个尺寸时,它将显示随机线条,并且图像为倾斜的.这是一张截图图片;

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

这是我的代码;

        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只是我制作的一个类,用于获取图像并加载它们.这非常简单,适用于所有图像.只是渲染不起作用.

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.

即使将GL11.glVertex2f更改为2i,它仍然不起作用:/

Even when changing GL11.glVertex2f to 2i, it still doesnt work :/

推荐答案

对不起,我不确定是什么问题.不幸的是,我似乎以后无法再复制它.但是我认为应该通过以下方法之一解决该问题:

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:

  • 不支持的图片大小

OpenGL非常依赖于此类图像,其分辨率的宽度和高度为2的幂(当width/height = n * 2时).如果图像文件不符合该规范,则LWJGL可能会产生奇怪的行为.另外,不用担心图像文件被压缩.这取决于顶点输入,而不取决于纹理输入.

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.

  • 不支持的图像扩展

尝试将图像文件另存为非隔行PNG文件. Slick_Util或用于加载图像文件的任何方法,可能都不完全支持您为其提供的图像.

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.

  • 更正提示

作为最后的选择,您可以将以下代码行添加到初始化代码中:

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.

这篇关于LWJGL无法正确渲染纹理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆