Fixed GLLinePlotItem line width option
Added antialiasing to GL line items
This commit is contained in:
parent
70ec358995
commit
09bc17bdb5
@ -40,7 +40,7 @@ for i in range(n):
|
||||
d = (x**2 + yi**2)**0.5
|
||||
z = 10 * np.cos(d) / (d+1)
|
||||
pts = np.vstack([x,yi,z]).transpose()
|
||||
plt = gl.GLLinePlotItem(pos=pts, color=pg.glColor((i,n*1.3)))
|
||||
plt = gl.GLLinePlotItem(pos=pts, color=pg.glColor((i,n*1.3)), width=(i+1)/10., antialias=True)
|
||||
w.addItem(plt)
|
||||
|
||||
|
||||
|
@ -12,10 +12,11 @@ class GLAxisItem(GLGraphicsItem):
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self, size=None):
|
||||
def __init__(self, size=None, antialias=True):
|
||||
GLGraphicsItem.__init__(self)
|
||||
if size is None:
|
||||
size = QtGui.QVector3D(1,1,1)
|
||||
self.antialias = antialias
|
||||
self.setSize(size=size)
|
||||
|
||||
def setSize(self, x=None, y=None, z=None, size=None):
|
||||
@ -39,8 +40,11 @@ class GLAxisItem(GLGraphicsItem):
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
|
||||
glEnable( GL_BLEND )
|
||||
glEnable( GL_ALPHA_TEST )
|
||||
glEnable( GL_POINT_SMOOTH )
|
||||
#glDisable( GL_DEPTH_TEST )
|
||||
|
||||
if self.antialias:
|
||||
glEnable(GL_LINE_SMOOTH)
|
||||
glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
|
||||
|
||||
glBegin( GL_LINES )
|
||||
|
||||
x,y,z = self.size()
|
||||
|
@ -11,9 +11,10 @@ class GLGridItem(GLGraphicsItem):
|
||||
Displays a wire-grame grid.
|
||||
"""
|
||||
|
||||
def __init__(self, size=None, color=None, glOptions='translucent'):
|
||||
def __init__(self, size=None, color=None, antialias=True, glOptions='translucent'):
|
||||
GLGraphicsItem.__init__(self)
|
||||
self.setGLOptions(glOptions)
|
||||
self.antialias = antialias
|
||||
if size is None:
|
||||
size = QtGui.QVector3D(1,1,1)
|
||||
self.setSize(size=size)
|
||||
@ -36,11 +37,13 @@ class GLGridItem(GLGraphicsItem):
|
||||
|
||||
def paint(self):
|
||||
self.setupGLState()
|
||||
#glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
|
||||
#glEnable( GL_BLEND )
|
||||
#glEnable( GL_ALPHA_TEST )
|
||||
glEnable( GL_POINT_SMOOTH )
|
||||
#glDisable( GL_DEPTH_TEST )
|
||||
|
||||
if self.antialias:
|
||||
glEnable(GL_LINE_SMOOTH)
|
||||
glEnable(GL_BLEND)
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
|
||||
glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
|
||||
|
||||
glBegin( GL_LINES )
|
||||
|
||||
x,y,z = self.size()
|
||||
|
@ -32,13 +32,14 @@ class GLLinePlotItem(GLGraphicsItem):
|
||||
color tuple of floats (0.0-1.0) specifying
|
||||
a color for the entire item.
|
||||
width float specifying line width
|
||||
antialias enables smooth line drawing
|
||||
==================== ==================================================
|
||||
"""
|
||||
args = ['pos', 'color', 'width', 'connected']
|
||||
args = ['pos', 'color', 'width', 'connected', 'antialias']
|
||||
for k in kwds.keys():
|
||||
if k not in args:
|
||||
raise Exception('Invalid keyword argument: %s (allowed arguments are %s)' % (k, str(args)))
|
||||
|
||||
self.antialias = False
|
||||
for arg in args:
|
||||
if arg in kwds:
|
||||
setattr(self, arg, kwds[arg])
|
||||
@ -72,8 +73,15 @@ class GLLinePlotItem(GLGraphicsItem):
|
||||
try:
|
||||
glVertexPointerf(self.pos)
|
||||
glColor4f(*self.color)
|
||||
glLineWidth(self.width)
|
||||
#glPointSize(self.width)
|
||||
|
||||
glPointSize(self.width)
|
||||
if self.antialias:
|
||||
glEnable(GL_LINE_SMOOTH)
|
||||
glEnable(GL_BLEND)
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
|
||||
glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
|
||||
|
||||
glDrawArrays(GL_LINE_STRIP, 0, self.pos.size / self.pos.shape[-1])
|
||||
finally:
|
||||
glDisableClientState(GL_VERTEX_ARRAY)
|
||||
|
Loading…
Reference in New Issue
Block a user