From 09bc17bdb556d240ae458eb25a6d9f19e40f6039 Mon Sep 17 00:00:00 2001 From: Luke Campagnola <luke.campagnola@gmail.com> Date: Sat, 30 Mar 2013 22:39:11 -0400 Subject: [PATCH] Fixed GLLinePlotItem line width option Added antialiasing to GL line items --- examples/GLLinePlotItem.py | 2 +- pyqtgraph/opengl/items/GLAxisItem.py | 10 +++++++--- pyqtgraph/opengl/items/GLGridItem.py | 15 +++++++++------ pyqtgraph/opengl/items/GLLinePlotItem.py | 14 +++++++++++--- 4 files changed, 28 insertions(+), 13 deletions(-) diff --git a/examples/GLLinePlotItem.py b/examples/GLLinePlotItem.py index ab2fd75b..1de07cff 100644 --- a/examples/GLLinePlotItem.py +++ b/examples/GLLinePlotItem.py @@ -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) diff --git a/pyqtgraph/opengl/items/GLAxisItem.py b/pyqtgraph/opengl/items/GLAxisItem.py index 1586d70a..9dbcd443 100644 --- a/pyqtgraph/opengl/items/GLAxisItem.py +++ b/pyqtgraph/opengl/items/GLAxisItem.py @@ -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() diff --git a/pyqtgraph/opengl/items/GLGridItem.py b/pyqtgraph/opengl/items/GLGridItem.py index 630b2aba..01a2b178 100644 --- a/pyqtgraph/opengl/items/GLGridItem.py +++ b/pyqtgraph/opengl/items/GLGridItem.py @@ -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() diff --git a/pyqtgraph/opengl/items/GLLinePlotItem.py b/pyqtgraph/opengl/items/GLLinePlotItem.py index ef747d17..9ef34cab 100644 --- a/pyqtgraph/opengl/items/GLLinePlotItem.py +++ b/pyqtgraph/opengl/items/GLLinePlotItem.py @@ -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) -- GitLab