Python OpenGL.GL.glEnd() Examples

The following are 21 code examples of OpenGL.GL.glEnd(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module OpenGL.GL , or try the search function .
Example #1
Source File: ndwindow.py    From spectral with MIT License 7 votes vote down vote up
def draw_box(self, x0, y0, x1, y1):
        '''Draws a selection box in the 3-D window.
        Coordinates are with respect to the lower left corner of the window.
        '''
        import OpenGL.GL as gl
        gl.glMatrixMode(gl.GL_PROJECTION)
        gl.glLoadIdentity()
        gl.glOrtho(0.0, self.size[0],
                   0.0, self.size[1],
                   -0.01, 10.0)

        gl.glLineStipple(1, 0xF00F)
        gl.glEnable(gl.GL_LINE_STIPPLE)
        gl.glLineWidth(1.0)
        gl.glColor3f(1.0, 1.0, 1.0)
        gl.glBegin(gl.GL_LINE_LOOP)
        gl.glVertex3f(x0, y0, 0.0)
        gl.glVertex3f(x1, y0, 0.0)
        gl.glVertex3f(x1, y1, 0.0)
        gl.glVertex3f(x0, y1, 0.0)
        gl.glEnd()
        gl.glDisable(gl.GL_LINE_STIPPLE)
        gl.glFlush()

        self.resize(*self.size) 
Example #2
Source File: render_scene.py    From holistic_scene_parsing with MIT License 6 votes vote down vote up
def __init__(self, obj_info, obj_color=None, swapyz=False):
        """Loads a Wavefront OBJ file. """
        self.vertices = obj_info.vertices
        self.normals = obj_info.normals
        self.texcoords = obj_info.texcoords
        self.faces = obj_info.faces

        self.gl_list = GL.glGenLists(1)
        GL.glNewList(self.gl_list, GL.GL_COMPILE)
        for face in self.faces:
            vertices, normals, _, texture_coords = face
            GL.glBegin(GL.GL_POLYGON)
            for i in range(len(vertices)):
                GL.glVertex3fv(self.vertices[vertices[i] - 1])
            GL.glEnd()
        # GL.glDisable(GL.GL_TEXTURE_2D)
        GL.glEndList() 
Example #3
Source File: render_scene.py    From holistic_scene_parsing with MIT License 6 votes vote down vote up
def __init__(self, obj_info, color=None, swapyz=False):
        """Loads a Wavefront OBJ file. """
        self.vertices = obj_info.vertices
        self.normals = obj_info.normals
        self.texcoords = obj_info.texcoords
        self.faces = obj_info.faces
        self.color = color

        self.gl_list = GL.glGenLists(1)
        GL.glNewList(self.gl_list, GL.GL_COMPILE)
        # GL.glEnable(GL.GL_TEXTURE_2D)
        GL.glFrontFace(GL.GL_CCW)
        # GL.glDisable(GL.GL_LIGHT0)
        # GL.glDisable(GL.GL_LIGHTING)
        for face in self.faces:
            vertices, normals, _, _ = face
            GL.glColor3f(self.color[0], self.color[1], self.color[2])
            GL.glBegin(GL.GL_POLYGON)
            for i in range(len(vertices)):
                # if normals[i] > 0:
                #     GL.glNormal3fv(self.normals[normals[i] - 1])
                GL.glVertex3fv(self.vertices[vertices[i] - 1])
            GL.glEnd()
        GL.glDisable(GL.GL_TEXTURE_2D)
        GL.glEndList() 
Example #4
Source File: render_scene.py    From holistic_scene_parsing with MIT License 6 votes vote down vote up
def __init__(self, obj_info, rotation_matrix, swapyz=False, layout_type=None):
        """Loads a Wavefront OBJ file. """
        self.vertices = obj_info.vertices
        self.normals = obj_info.normals
        self.texcoords = obj_info.texcoords
        self.faces = obj_info.faces
        self.rotation_matrix = rotation_matrix

        # load the mesh to OPENGL
        self.gl_list = GL.glGenLists(1)
        GL.glNewList(self.gl_list, GL.GL_COMPILE)
        for face in self.faces:
            vertices, normals, _, _ = face
            GL.glBegin(GL.GL_POLYGON)
            for i in range(len(vertices)):
                normal_color = self.rotation_matrix.dot(self.normals[normals[i] - 1])
                GL.glColor3f((normal_color[0] + 1) / 2, (-normal_color[2] + 1) / 2, (normal_color[1] + 1) / 2)
                GL.glVertex3fv(self.vertices[vertices[i] - 1])
            GL.glEnd()
        GL.glEndList() 
Example #5
Source File: LicModel.py    From lic with GNU General Public License v3.0 6 votes vote down vote up
def drawConditionalLines(self):
        if self.type != GL.GL_LINES or len(self.points) != 12:
            return  # Not a conditional line
        
        p = self.points
        p0 = GLU.gluProject(p[0], p[1], p[2])
        p1 = GLU.gluProject(p[3], p[4], p[5])
        c0 = GLU.gluProject(p[6], p[7], p[8])
        c1 = GLU.gluProject(p[9], p[10], p[11])
        
        winding1 = self.pointWinding(p0, p1, c0)
        winding2 = self.pointWinding(p0, p1, c1)
        if winding1 != winding2:
            return
    
        GL.glPushAttrib(GL.GL_CURRENT_BIT)
        GL.glColor4f(1.0, 1.0, 0.0, 1.0)
        GL.glBegin(self.type)
        GL.glVertex3f(p[0], p[1], p[2])
        GL.glVertex3f(p[3], p[4], p[5])
        GL.glEnd()
        GL.glPopAttrib() 
Example #6
Source File: viewer3D.py    From pyslam with GNU General Public License v3.0 6 votes vote down vote up
def drawPlane(num_divs=200, div_size=10):
        # Plane parallel to x-z at origin with normal -y
        minx = -num_divs*div_size
        minz = -num_divs*div_size
        maxx = num_divs*div_size
        maxz = num_divs*div_size
        #gl.glLineWidth(2)
        #gl.glColor3f(0.7,0.7,1.0)
        gl.glColor3f(0.7,0.7,0.7)
        gl.glBegin(gl.GL_LINES)
        for n in range(2*num_divs):
            gl.glVertex3f(minx+div_size*n,0,minz)
            gl.glVertex3f(minx+div_size*n,0,maxz)
            gl.glVertex3f(minx,0,minz+div_size*n)
            gl.glVertex3f(maxx,0,minz+div_size*n)
        gl.glEnd() 
Example #7
Source File: glutils.py    From MCEdit-Unified with ISC License 5 votes vote down vote up
def glBegin(cls, type):
        try:
            GL.glBegin(type)
            yield
        finally:
            GL.glEnd() 
Example #8
Source File: LicModel.py    From lic with GNU General Public License v3.0 5 votes vote down vote up
def drawGLBoundingBox(self):
        b = self.abstractPart.getBoundingBox()
        GL.glBegin(GL.GL_LINE_LOOP)
        GL.glVertex3f(b.x1, b.y1, b.z1)
        GL.glVertex3f(b.x2, b.y1, b.z1)
        GL.glVertex3f(b.x2, b.y2, b.z1)
        GL.glVertex3f(b.x1, b.y2, b.z1)
        GL.glEnd()

        GL.glBegin(GL.GL_LINE_LOOP)
        GL.glVertex3f(b.x1, b.y1, b.z2)
        GL.glVertex3f(b.x2, b.y1, b.z2)
        GL.glVertex3f(b.x2, b.y2, b.z2)
        GL.glVertex3f(b.x1, b.y2, b.z2)
        GL.glEnd()

        GL.glBegin(GL.GL_LINES)
        GL.glVertex3f(b.x1, b.y1, b.z1)
        GL.glVertex3f(b.x1, b.y1, b.z2)
        GL.glVertex3f(b.x1, b.y2, b.z1)
        GL.glVertex3f(b.x1, b.y2, b.z2)
        GL.glVertex3f(b.x2, b.y1, b.z1)
        GL.glVertex3f(b.x2, b.y1, b.z2)
        GL.glVertex3f(b.x2, b.y2, b.z1)
        GL.glVertex3f(b.x2, b.y2, b.z2)
        GL.glEnd() 
Example #9
Source File: simpleDraw.py    From pyslam with GNU General Public License v3.0 5 votes vote down vote up
def drawPlane(ndivs=100, ndivsize=1):
    # Plane parallel to x-z at origin with normal -y
    minx = -ndivs*ndivsize
    minz = -ndivs*ndivsize
    maxx = ndivs*ndivsize
    maxz = ndivs*ndivsize
    gl.glLineWidth(1)
    gl.glColor3f(0.7,0.7,1.0)
    gl.glBegin(gl.GL_LINES)
    for n in range(2*ndivs):
        gl.glVertex3f(minx+ndivsize*n,0,minz)
        gl.glVertex3f(minx+ndivsize*n,0,maxz)
        gl.glVertex3f(minx,0,minz+ndivsize*n)
        gl.glVertex3f(maxx,0,minz+ndivsize*n)
    gl.glEnd() 
Example #10
Source File: glutils.py    From GDMC with ISC License 5 votes vote down vote up
def glBegin(cls, type):
        try:
            GL.glBegin(type)
            yield
        finally:
            GL.glEnd() 
Example #11
Source File: head_model_OGL.py    From simnibs with GNU General Public License v3.0 5 votes vote down vote up
def rectangle(self, center, normal, x_axis, y_axis, dimensions):
        GL.glBegin(GL.GL_QUADS)
        GL.glNormal3f(normal[0],normal[1],normal[2])
        x_dim = dimensions[0]/2.0
        y_dim = dimensions[1]/2.0
        v1 = center+normal+x_dim*x_axis+y_dim*y_axis
        v2 = center+normal+x_dim*x_axis-y_dim*y_axis
        v3 = center+normal-x_dim*x_axis-y_dim*y_axis
        v4 = center+normal-x_dim*x_axis+y_dim*y_axis
        GL.glVertex3d(v1[0], v1[1], v1[2])
        GL.glVertex3d(v2[0], v2[1], v2[2])
        GL.glVertex3d(v3[0], v3[1], v3[2])
        GL.glVertex3d(v4[0], v4[1], v4[2])
        GL.glEnd() 
Example #12
Source File: head_model_OGL.py    From simnibs with GNU General Public License v3.0 5 votes vote down vote up
def ellipse(self, center, normal, u, v, dimensions):
        dim_x = dimensions[0]
        dim_y = dimensions[1]
        GL.glBegin(GL.GL_POLYGON)
        Pi = 3.14159265358979323846
        nbr_sides = 20
        GL.glNormal3f(normal[0],normal[1],normal[2])
        for i in range(nbr_sides):
            angle = (i * 2 * Pi) / nbr_sides
            vect = center+normal+( dim_x/2)*u*math.sin(angle)+ \
                +( dim_y/2)*v*math.cos(angle)
            GL.glVertex3d(vect[0], vect[1], vect[2])

        GL.glEnd() 
Example #13
Source File: electrodeGUI.py    From simnibs with GNU General Public License v3.0 5 votes vote down vote up
def ellipse_xy (self, center_x, center_y, center_z, x_axis, y_axis, color):
        Pi = 3.14159265358979323846
        nbr_sides = 100

        GL.glBegin(GL.GL_POLYGON)
        self.qglColor(color)
        for i in range(nbr_sides):
             angle1 = (i * 2 * Pi) / nbr_sides
             x1 = center_x + x_axis/2 * math.sin(angle1)
             y1 = center_y + y_axis/2 * math.cos(angle1)
             GL.glVertex3d(x1, y1, center_z)
        GL.glEnd() 
Example #14
Source File: electrodeGUI.py    From simnibs with GNU General Public License v3.0 5 votes vote down vote up
def plane_xy (self, center_x,center_y, center_z, size_x, size_y,color) :
        GL.glBegin(GL.GL_QUADS)
        self.qglColor(color)

        px = center_x+size_x/2
        mx =center_x-size_x/2
        py = center_y+size_y/2
        my =center_y-size_y/2

        GL.glVertex3d(px,py, center_z)
        GL.glVertex3d(mx,py, center_z)
        GL.glVertex3d(mx,my, center_z)
        GL.glVertex3d(px,my, center_z)

        GL.glEnd() 
Example #15
Source File: opengl_test.py    From PFramer with GNU General Public License v3.0 4 votes vote down vote up
def makeObject(self):
        genList = GL.glGenLists(1)
        GL.glNewList(genList, GL.GL_COMPILE)

        GL.glBegin(GL.GL_QUADS)

        x1 = +0.06
        y1 = -0.14
        x2 = +0.14
        y2 = -0.06
        x3 = +0.08
        y3 = +0.00
        x4 = +0.30
        y4 = +0.22

        self.quad(x1, y1, x2, y2, y2, x2, y1, x1)
        self.quad(x3, y3, x4, y4, y4, x4, y3, x3)

        self.extrude(x1, y1, x2, y2)
        self.extrude(x2, y2, y2, x2)
        self.extrude(y2, x2, y1, x1)
        self.extrude(y1, x1, x1, y1)
        self.extrude(x3, y3, x4, y4)
        self.extrude(x4, y4, y4, x4)
        self.extrude(y4, x4, y3, x3)

        Pi = 3.14159265358979323846
        NumSectors = 200

        for i in range(NumSectors):
            angle1 = (i * 2 * Pi) / NumSectors
            x5 = 0.30 * math.sin(angle1)
            y5 = 0.30 * math.cos(angle1)
            x6 = 0.20 * math.sin(angle1)
            y6 = 0.20 * math.cos(angle1)

            angle2 = ((i + 1) * 2 * Pi) / NumSectors
            x7 = 0.20 * math.sin(angle2)
            y7 = 0.20 * math.cos(angle2)
            x8 = 0.30 * math.sin(angle2)
            y8 = 0.30 * math.cos(angle2)

            self.quad(x5, y5, x6, y6, x7, y7, x8, y8)

            self.extrude(x6, y6, x7, y7)
            self.extrude(x8, y8, x5, y5)

        GL.glEnd()
        GL.glEndList()

        return genList 
Example #16
Source File: ndwindow.py    From spectral with MIT License 4 votes vote down vote up
def create_axes_list(self):
        '''Creates display lists to render unit length x,y,z axes.'''
        import OpenGL.GL as gl
        gl.glNewList(self.gllist_id, gl.GL_COMPILE)
        gl.glBegin(gl.GL_LINES)
        gl.glColor3f(1.0, 0.0, 0.0)
        gl.glVertex3f(0.0, 0.0, 0.0)
        gl.glVertex3f(1.0, 0.0, 0.0)
        gl.glColor3f(0.0, 1.0, 0.0)
        gl.glVertex3f(0.0, 0.0, 0.0)
        gl.glVertex3f(0.0, 1.0, 0.0)
        gl.glColor3f(-.0, 0.0, 1.0)
        gl.glVertex3f(0.0, 0.0, 0.0)
        gl.glVertex3f(0.0, 0.0, 1.0)

        gl.glColor3f(1.0, 1.0, 1.0)
        gl.glVertex3f(0.0, 0.0, 0.0)
        gl.glVertex3f(-1.0, 0.0, 0.0)
        gl.glVertex3f(0.0, 0.0, 0.0)
        gl.glVertex3f(0.0, -1.0, 0.0)
        gl.glVertex3f(0.0, 0.0, 0.0)
        gl.glVertex3f(0.0, 0.0, -1.0)
        gl.glEnd()

        def label_axis(x, y, z, label):
            gl.glRasterPos3f(x, y, z)
            glut.glutBitmapString(glut.GLUT_BITMAP_HELVETICA_18,
                                  str(label))
        def label_axis_for_feature(x, y, z, feature_ind):
            feature = self.octant_features[feature_ind[0]][feature_ind[1]]
            label_axis(x, y, z, self.labels[feature])

        if self._have_glut:
            try:
                import OpenGL.GLUT as glut
                if bool(glut.glutBitmapString):
                    if self.quadrant_mode == 'independent':
                        label_axis(1.05, 0.0, 0.0, 'x')
                        label_axis(0.0, 1.05, 0.0, 'y')
                        label_axis(0.0, 0.0, 1.05, 'z')
                    elif self.quadrant_mode == 'mirrored':
                        label_axis_for_feature(1.05, 0.0, 0.0, (0, 0))
                        label_axis_for_feature(0.0, 1.05, 0.0, (0, 1))
                        label_axis_for_feature(0.0, 0.0, 1.05, (0, 2))
                        label_axis_for_feature(-1.05, 0.0, 0.0, (6, 0))
                        label_axis_for_feature(0.0, -1.05, 0.0, (6, 1))
                        label_axis_for_feature(0.0, 0.0, -1.05, (6, 2))
                    else:
                        label_axis_for_feature(1.05, 0.0, 0.0, (0, 0))
                        label_axis_for_feature(0.0, 1.05, 0.0, (0, 1))
                        label_axis_for_feature(0.0, 0.0, 1.05, (0, 2))
            except:
                pass
        gl.glEndList() 
Example #17
Source File: PlotCurveItem.py    From tf-pose with Apache License 2.0 4 votes vote down vote up
def paintGL(self, p, opt, widget):
        p.beginNativePainting()
        import OpenGL.GL as gl
        
        ## set clipping viewport
        view = self.getViewBox()
        if view is not None:
            rect = view.mapRectToItem(self, view.boundingRect())
            #gl.glViewport(int(rect.x()), int(rect.y()), int(rect.width()), int(rect.height()))
            
            #gl.glTranslate(-rect.x(), -rect.y(), 0)
            
            gl.glEnable(gl.GL_STENCIL_TEST)
            gl.glColorMask(gl.GL_FALSE, gl.GL_FALSE, gl.GL_FALSE, gl.GL_FALSE) # disable drawing to frame buffer
            gl.glDepthMask(gl.GL_FALSE)  # disable drawing to depth buffer
            gl.glStencilFunc(gl.GL_NEVER, 1, 0xFF)  
            gl.glStencilOp(gl.GL_REPLACE, gl.GL_KEEP, gl.GL_KEEP)  
            
            ## draw stencil pattern
            gl.glStencilMask(0xFF)
            gl.glClear(gl.GL_STENCIL_BUFFER_BIT)
            gl.glBegin(gl.GL_TRIANGLES)
            gl.glVertex2f(rect.x(), rect.y())
            gl.glVertex2f(rect.x()+rect.width(), rect.y())
            gl.glVertex2f(rect.x(), rect.y()+rect.height())
            gl.glVertex2f(rect.x()+rect.width(), rect.y()+rect.height())
            gl.glVertex2f(rect.x()+rect.width(), rect.y())
            gl.glVertex2f(rect.x(), rect.y()+rect.height())
            gl.glEnd()
                       
            gl.glColorMask(gl.GL_TRUE, gl.GL_TRUE, gl.GL_TRUE, gl.GL_TRUE)
            gl.glDepthMask(gl.GL_TRUE)
            gl.glStencilMask(0x00)
            gl.glStencilFunc(gl.GL_EQUAL, 1, 0xFF)
            
        try:
            x, y = self.getData()
            pos = np.empty((len(x), 2))
            pos[:,0] = x
            pos[:,1] = y
            gl.glEnableClientState(gl.GL_VERTEX_ARRAY)
            try:
                gl.glVertexPointerf(pos)
                pen = fn.mkPen(self.opts['pen'])
                color = pen.color()
                gl.glColor4f(color.red()/255., color.green()/255., color.blue()/255., color.alpha()/255.)
                width = pen.width()
                if pen.isCosmetic() and width < 1:
                    width = 1
                gl.glPointSize(width)
                gl.glEnable(gl.GL_LINE_SMOOTH)
                gl.glEnable(gl.GL_BLEND)
                gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)
                gl.glHint(gl.GL_LINE_SMOOTH_HINT, gl.GL_NICEST)
                gl.glDrawArrays(gl.GL_LINE_STRIP, 0, pos.size / pos.shape[-1])
            finally:
                gl.glDisableClientState(gl.GL_VERTEX_ARRAY)
        finally:
            p.endNativePainting() 
Example #18
Source File: LicModel.py    From lic with GNU General Public License v3.0 4 votes vote down vote up
def callGLDisplayList(self, paintingEdge):

        # must be called inside a glNewList/EndList pair
        p = self.points
        if self.type == GL.GL_LINES:
            if len(self.points) > 6 or not paintingEdge:  # This is a conditional line or we are not painting edges
                return

            GL.glBegin(self.type)
            GL.glVertex3f(p[0], p[1], p[2])
            GL.glVertex3f(p[3], p[4], p[5])
            GL.glEnd()
            return

        if paintingEdge:
            return

        if self.color is not None:
            GL.glPushAttrib(GL.GL_CURRENT_BIT)
            GL.glColor4fv(self.color.rgba)

        if self.winding == GL.GL_CCW:
            normal = self.addNormal(p[0:3], p[3:6], p[6:9])
            # GL.glBegin( GL.GL_LINES )
            # GL.glVertex3f(p[3], p[4], p[5])
            # GL.glVertex3f(p[3] + normal[0], p[4] + normal[1], p[5] + normal[2])
            # GL.glEnd()

            GL.glBegin(self.type)
            GL.glNormal3fv(normal)
            GL.glVertex3f(p[0], p[1], p[2])
            GL.glVertex3f(p[3], p[4], p[5])
            GL.glVertex3f(p[6], p[7], p[8])
            if self.type == GL.GL_QUADS:
                GL.glVertex3f(p[9], p[10], p[11])
            GL.glEnd()
            
        elif self.winding == GL.GL_CW:
            normal = self.addNormal(p[0:3], p[6:9], p[3:6])
            # GL.glBegin( GL.GL_LINES )
            # GL.glVertex3f(p[3], p[4], p[5])
            # GL.glVertex3f(p[3] + normal[0], p[4] + normal[1], p[5] + normal[2])
            # GL.glEnd()

            GL.glBegin(self.type)
            GL.glNormal3fv(normal)
            GL.glVertex3f(p[0], p[1], p[2])
            if self.type == GL.GL_QUADS:
                GL.glVertex3f(p[9], p[10], p[11])
            GL.glVertex3f(p[6], p[7], p[8])
            GL.glVertex3f(p[3], p[4], p[5])
            GL.glEnd()

        if self.color is not None:
            GL.glPopAttrib() 
Example #19
Source File: PlotCurveItem.py    From soapy with GNU General Public License v3.0 4 votes vote down vote up
def paintGL(self, p, opt, widget):
        p.beginNativePainting()
        import OpenGL.GL as gl
        
        ## set clipping viewport
        view = self.getViewBox()
        if view is not None:
            rect = view.mapRectToItem(self, view.boundingRect())
            #gl.glViewport(int(rect.x()), int(rect.y()), int(rect.width()), int(rect.height()))
            
            #gl.glTranslate(-rect.x(), -rect.y(), 0)
            
            gl.glEnable(gl.GL_STENCIL_TEST)
            gl.glColorMask(gl.GL_FALSE, gl.GL_FALSE, gl.GL_FALSE, gl.GL_FALSE) # disable drawing to frame buffer
            gl.glDepthMask(gl.GL_FALSE)  # disable drawing to depth buffer
            gl.glStencilFunc(gl.GL_NEVER, 1, 0xFF)  
            gl.glStencilOp(gl.GL_REPLACE, gl.GL_KEEP, gl.GL_KEEP)  
            
            ## draw stencil pattern
            gl.glStencilMask(0xFF)
            gl.glClear(gl.GL_STENCIL_BUFFER_BIT)
            gl.glBegin(gl.GL_TRIANGLES)
            gl.glVertex2f(rect.x(), rect.y())
            gl.glVertex2f(rect.x()+rect.width(), rect.y())
            gl.glVertex2f(rect.x(), rect.y()+rect.height())
            gl.glVertex2f(rect.x()+rect.width(), rect.y()+rect.height())
            gl.glVertex2f(rect.x()+rect.width(), rect.y())
            gl.glVertex2f(rect.x(), rect.y()+rect.height())
            gl.glEnd()
                       
            gl.glColorMask(gl.GL_TRUE, gl.GL_TRUE, gl.GL_TRUE, gl.GL_TRUE)
            gl.glDepthMask(gl.GL_TRUE)
            gl.glStencilMask(0x00)
            gl.glStencilFunc(gl.GL_EQUAL, 1, 0xFF)
            
        try:
            x, y = self.getData()
            pos = np.empty((len(x), 2))
            pos[:,0] = x
            pos[:,1] = y
            gl.glEnableClientState(gl.GL_VERTEX_ARRAY)
            try:
                gl.glVertexPointerf(pos)
                pen = fn.mkPen(self.opts['pen'])
                color = pen.color()
                gl.glColor4f(color.red()/255., color.green()/255., color.blue()/255., color.alpha()/255.)
                width = pen.width()
                if pen.isCosmetic() and width < 1:
                    width = 1
                gl.glPointSize(width)
                gl.glEnable(gl.GL_LINE_SMOOTH)
                gl.glEnable(gl.GL_BLEND)
                gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)
                gl.glHint(gl.GL_LINE_SMOOTH_HINT, gl.GL_NICEST)
                gl.glDrawArrays(gl.GL_LINE_STRIP, 0, pos.size / pos.shape[-1])
            finally:
                gl.glDisableClientState(gl.GL_VERTEX_ARRAY)
        finally:
            p.endNativePainting() 
Example #20
Source File: PlotCurveItem.py    From qgisSpaceSyntaxToolkit with GNU General Public License v3.0 4 votes vote down vote up
def paintGL(self, p, opt, widget):
        p.beginNativePainting()
        import OpenGL.GL as gl
        
        ## set clipping viewport
        view = self.getViewBox()
        if view is not None:
            rect = view.mapRectToItem(self, view.boundingRect())
            #gl.glViewport(int(rect.x()), int(rect.y()), int(rect.width()), int(rect.height()))
            
            #gl.glTranslate(-rect.x(), -rect.y(), 0)
            
            gl.glEnable(gl.GL_STENCIL_TEST)
            gl.glColorMask(gl.GL_FALSE, gl.GL_FALSE, gl.GL_FALSE, gl.GL_FALSE) # disable drawing to frame buffer
            gl.glDepthMask(gl.GL_FALSE)  # disable drawing to depth buffer
            gl.glStencilFunc(gl.GL_NEVER, 1, 0xFF)  
            gl.glStencilOp(gl.GL_REPLACE, gl.GL_KEEP, gl.GL_KEEP)  
            
            ## draw stencil pattern
            gl.glStencilMask(0xFF)
            gl.glClear(gl.GL_STENCIL_BUFFER_BIT)
            gl.glBegin(gl.GL_TRIANGLES)
            gl.glVertex2f(rect.x(), rect.y())
            gl.glVertex2f(rect.x()+rect.width(), rect.y())
            gl.glVertex2f(rect.x(), rect.y()+rect.height())
            gl.glVertex2f(rect.x()+rect.width(), rect.y()+rect.height())
            gl.glVertex2f(rect.x()+rect.width(), rect.y())
            gl.glVertex2f(rect.x(), rect.y()+rect.height())
            gl.glEnd()
                       
            gl.glColorMask(gl.GL_TRUE, gl.GL_TRUE, gl.GL_TRUE, gl.GL_TRUE)
            gl.glDepthMask(gl.GL_TRUE)
            gl.glStencilMask(0x00)
            gl.glStencilFunc(gl.GL_EQUAL, 1, 0xFF)
            
        try:
            x, y = self.getData()
            pos = np.empty((len(x), 2))
            pos[:,0] = x
            pos[:,1] = y
            gl.glEnableClientState(gl.GL_VERTEX_ARRAY)
            try:
                gl.glVertexPointerf(pos)
                pen = fn.mkPen(self.opts['pen'])
                color = pen.color()
                gl.glColor4f(color.red()/255., color.green()/255., color.blue()/255., color.alpha()/255.)
                width = pen.width()
                if pen.isCosmetic() and width < 1:
                    width = 1
                gl.glPointSize(width)
                gl.glEnable(gl.GL_LINE_SMOOTH)
                gl.glEnable(gl.GL_BLEND)
                gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)
                gl.glHint(gl.GL_LINE_SMOOTH_HINT, gl.GL_NICEST)
                gl.glDrawArrays(gl.GL_LINE_STRIP, 0, pos.size / pos.shape[-1])
            finally:
                gl.glDisableClientState(gl.GL_VERTEX_ARRAY)
        finally:
            p.endNativePainting() 
Example #21
Source File: electrodeGUI.py    From simnibs with GNU General Public License v3.0 4 votes vote down vote up
def cuboid(self, center_x, center_y,center_z, size_x, size_y, size_z, color, wireframe):

        if wireframe :
            GL.glPolygonMode( GL.GL_FRONT_AND_BACK, GL.GL_LINE ) 

        GL.glBegin(GL.GL_QUADS)
        self.qglColor(color)

        px = center_x+size_x/2
        mx =center_x-size_x/2
        py = center_y+size_y/2
        my =center_y-size_y/2
        pz = center_z+size_z/2
        mz =center_z-size_z/2


        GL.glVertex3d(px,py, pz)
        GL.glVertex3d(px,my, pz)
        GL.glVertex3d(mx,my, pz)
        GL.glVertex3d(mx,py, pz)

        GL.glVertex3d(px,py, mz)
        GL.glVertex3d(mx,py, mz)
        GL.glVertex3d(mx,my, mz)
        GL.glVertex3d(px,my, mz)

        self.qglColor(color.darker(250))

        GL.glVertex3d(px,py, pz)
        GL.glVertex3d(mx,py, pz)
        GL.glVertex3d(mx,py, mz)
        GL.glVertex3d(px,py, mz)

        GL.glVertex3d(px,my, pz)
        GL.glVertex3d(mx,my, pz)
        GL.glVertex3d(mx,my, mz)
        GL.glVertex3d(px,my, mz)
        
        GL.glVertex3d(px,py, pz)
        GL.glVertex3d(px,my, pz)
        GL.glVertex3d(px,my, mz)
        GL.glVertex3d(px,py, mz)

        GL.glVertex3d(mx,py, pz)
        GL.glVertex3d(mx,my, pz)
        GL.glVertex3d(mx,my, mz)
        GL.glVertex3d(mx,py, mz)


        GL.glEnd()
        if wireframe:
            GL.glPolygonMode( GL.GL_FRONT_AND_BACK, GL.GL_FILL );