【发布时间】:2020-04-13 02:24:41
【问题描述】:
我正在尝试使用 Slick 在项目中的某些 2D 精灵上重新创建阴影效果。为此,我正在重新着色精灵的副本并使用 Slick OpenGL 使用此方法拉伸它:
public static void getStretched(Shape shape, Image image) {
TextureImpl.bindNone();
image.getTexture().bind();
SGL GL = Renderer.get();
GL.glEnable(SGL.GL_TEXTURE_2D);
GL.glBegin(SGL.GL_QUADS);
//topleft
GL.glTexCoord2f(0f, 0f);
GL.glVertex2f(shape.getPoints()[0], shape.getPoints()[1]);
//topright
GL.glTexCoord2f(0.5f, 0f);
GL.glVertex2f(shape.getPoints()[2], shape.getPoints()[3]);
//bottom right
GL.glTexCoord2f(1f, 1f);
GL.glVertex2f(shape.getPoints()[4], shape.getPoints()[5]);
//btoom left
GL.glTexCoord2f(0.5f, 1f);
GL.glVertex2f(shape.getPoints()[6], shape.getPoints()[7]);
GL.glEnd();
GL.glDisable(SGL.GL_TEXTURE_2D);
TextureImpl.bindNone();
}
This gives the almost the desired effect, aside from the fact that the image is cropped a bit.
This becomes more extreme for higher distortions
我是使用 OpenGL 的新手,所以关于如何解决这个问题的一些帮助会很棒。
此外,如果我将图像输入到使用getSubImage、OpenGL renders the original image, rather than the sub image 获得的方法中。
我不确定为什么会发生这种情况,因为精灵本身是从使用getSubImage 的精灵表中获取的,并且渲染没有问题。
非常感谢您的帮助!
【问题讨论】:
标签: java opengl rendering slick2d