Pyglet OpenGL绘图抗锯齿
我一直在寻找一种在 OpenGL 中消除锯齿线的方法,但它们似乎都不起作用......这里有一些示例代码:
import pyglet
from pyglet.gl import *
window = pyglet.window.Window(resizable=True)
@window.event
def on_draw():
window.clear()
pyglet.gl.glColor4f(1.0,0,0,1.0)
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
glEnable (GL_BLEND)
glEnable (GL_LINE_SMOOTH);
glHint (GL_LINE_SMOOTH_HINT, GL_DONT_CARE)
glLineWidth (3)
pyglet.graphics.draw(2, pyglet.gl.GL_LINES,
('v2i', (10, 15, 300, 305))
)
pyglet.app.run()
任何人都可以看到我做错了什么吗?
I've been looking around for a way to anti-alias lines in OpenGL, but none of them seem to work... here's some example code:
import pyglet
from pyglet.gl import *
window = pyglet.window.Window(resizable=True)
@window.event
def on_draw():
window.clear()
pyglet.gl.glColor4f(1.0,0,0,1.0)
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
glEnable (GL_BLEND)
glEnable (GL_LINE_SMOOTH);
glHint (GL_LINE_SMOOTH_HINT, GL_DONT_CARE)
glLineWidth (3)
pyglet.graphics.draw(2, pyglet.gl.GL_LINES,
('v2i', (10, 15, 300, 305))
)
pyglet.app.run()
Can anyone see what I am doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
允许 Pyglet 使用额外的样本缓冲区可能会有所帮助。将您的窗口线更改为:
这对我有用。
Allow Pyglet to use an extra sample buffer might help. Change your window line to this:
This works for me.
很难肯定地说。第一件事可能是将您的提示从 GL_DONT_CARE 更改为 GL_NICEST。对于大多数显卡来说,它可能不会有太大区别,但可能会有所帮助。
除此之外,就有点难说了。这里有一些代码(C++;抱歉):
这是我得到的输出:
打开线条平滑后的差异似乎非常明显。 GL_DONT_CARE 和 GL_NICEST 之间的差异(至多)要小很多。
It's a bit hard to say for sure. The first thing is probably to change your hint from GL_DONT_CARE to GL_NICEST. It probably won't make much difference with most graphics cards, but it might help a little.
Other than that, it's a bit hard to say. Here's a bit of code (in C++; sorry):
And here's what I'm getting as output from that:
The difference when line-smoothing is turned on seems pretty obvious. The difference between GL_DONT_CARE and GL_NICEST is (at most) a lot less so.