java - Slick2d 使用动画/图像抗锯齿

标签 java opengl antialiasing slick2d artifacts

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

如果没有 AA,运动就会不稳定,正如人们对没有 AA 的情况所期望的那样。 我在游戏的 preRenderState 中打开 AA:

g.setAntiAlias(true);

这导致:

Image with graphical glitch

注意中心的对角线,可能是由两个三角形导致矩形不精确相交造成的。如何在仍然使用 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 时,几乎没有人能正确完成大量工作。 .

关于java - Slick2d 使用动画/图像抗锯齿,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32151974/

相关文章:

windows - 为什么我的 Windows 窗体字符串在消除锯齿后看起来很难看?

vector - Corona SDK 矢量圆圈抗锯齿 - 有效吗?

Java 反射 - 如果前面有 "set"操作,则在 "get"上出现 IllegalAccessException

java - 当我们使用 Bitmap 时内存不足

c++ - ARB_sync 和适当的测试

c++ - 如何使用鼠标滚轮修复放大和缩小?

ios - 不必要的轮廓出现在UIBezierPath的轮廓上,该UIBezierPath已填充并用作透视渐变的剪辑

java - 我正在尝试将值插入 MySQL 数据库,但出现 NullPointerException

java - 如何阻止 JFrame/JPanel 自动格式化组件之间的距离?

c++ - 推荐的 OpenGL/GLUT 引用