Slick2d 使用抗锯齿 Animations/Images

Slick2d using anti-aliasing with Animations/Images

我正在使用 slick2d 渲染动画,但使用抗锯齿

没有 AA,运动是不稳定的,正如人们对没有 AA 的东西所期望的那样。 我在游戏的 preRenderState 中打开 AA:

g.setAntiAlias(true);

这导致:

注意中间的对角线,可能是由于渲染矩形的两个三角形没有精确相交造成的。如何在仍然使用 AA 来平滑我的运动的同时删除它?我找到了 http://www.java-gaming.org/index.php?topic=27313.0 但解决方案是“删除 AA”,我不愿意这样做。

由于 GL_POLYGON_SMOOTH,这看起来像人工制品。

当您使用该(已弃用)功能时,您应该在启用混合和混合功能的情况下绘制所有不透明几何体:GL_SRC_ALPHA_SATURATE, GL_ONE。不这样做会在大多数轮廓上产生白色轮廓(基本上是锯齿边缘)。

Chapter 6 of the OpenGL Redbook states:

Now you need to blend overlapping edges appropriately. First, turn off the depth buffer so that you have control over how overlapping pixels are drawn. Then set the blending factors to GL_SRC_ALPHA_SATURATE (source) and GL_ONE (destination). With this specialized blending function, the final color is the sum of the destination color and the scaled source color; the scale factor is the smaller of either the incoming source alpha value or one minus the destination alpha value.

This means that for a pixel with a large alpha value, successive incoming pixels have little effect on the final color because one minus the destination alpha is almost zero. With this method, a pixel on the edge of a polygon might be blended eventually with the colors from another polygon that's drawn later. Finally, you need to sort all the polygons in your scene so that they're ordered from front to back before drawing them.

当他们尝试启用 GL_POLYGON_SMOOTH.

时,几乎没有人能正确完成大量工作

每次在 Slick2D 中启用抗锯齿时,它应该看起来像这样。

g.setAntiAlias(true);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA_SATURATE, GL11.GL_ONE);

与 Andon 的回答基本相同,但带有应该可以解决问题的代码。

请注意,使用此功能,您首先绘制的内容将位于顶部,而不是您最后绘制的内容。所以您可能需要反转渲染顺序。