Search code examples
pythonopenglantialiasingpygletpyopengl

Pyglet OpenGL drawing anti-aliasing


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?


Solution

  • Allow Pyglet to use an extra sample buffer might help. Change your window line to this:

    config = pyglet.gl.Config(sample_buffers=1, samples=4)
    window = pyglet.window.Window(config=config, resizable=True) 
    

    This works for me.