Beispiel #1
0
def drawFilledCircle(color, center, radius, normal):
    """
    Scale, rotate/translate the unit circle properly.
    Added a filled circle variant, piotr 080405
    """
    glMatrixMode(GL_MODELVIEW)
    glPushMatrix() 
    glColor3fv(color)
    glDisable(GL_LIGHTING)

    glTranslatef(center[0], center[1], center[2])
    rQ = Q(V(0, 0, 1), normal)
    rotAngle = rQ.angle*180.0/pi

    #This may cause problems as proved before in Linear motor display.
    #rotation around (0, 0, 0)
    #if vlen(V(rQ.x, rQ.y, rQ.z)) < 0.00005:
    #      rQ.x = 1.0

    glRotatef(rotAngle, rQ.x, rQ.y, rQ.z)
    glScalef(radius, radius, 1.0)
    glCallList(drawing_globals.filledCircleList)
    glEnable(GL_LIGHTING)
    glPopMatrix()
    return
Beispiel #2
0
    def render(self):
        """ The render pass for the scene """
        self.init_view()

        # Enable lighting and color
        glEnable(GL_LIGHTING)

        glClearColor(0.4, 0.4, 0.4, 0.0)
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)

        # Load the modelview matrix from the current state of the trackball
        glMatrixMode(GL_MODELVIEW)
        glPushMatrix()
        glLoadIdentity()
        loc = self.interaction.translation
        glTranslated(-loc[0], -loc[1], -loc[2])
        glMultMatrixf(self.interaction.trackball.matrix)

        # store the inverse of the current modelview.
        currentModelView = numpy.array(glGetFloatv(GL_MODELVIEW_MATRIX))
        self.modelView = numpy.transpose(currentModelView)
        self.inverseModelView = inv(numpy.transpose(currentModelView))

        # render the scene. This will call the render function for each object in the scene
        self.scene.render()

        # draw the grid
        glDisable(GL_LIGHTING)
        glCallList(G_OBJ_PLANE)
        glPopMatrix()

        # flush the buffers so that the scene can be drawn
        glFlush()
Beispiel #3
0
    def draw(self, x, y, z=0, angle=0, scale=1):
        """Draws the SVG to screen.

        :Parameters
            `x` : float
                The x-coordinate at which to draw.
            `y` : float
                The y-coordinate at which to draw.
            `z` : float
                The z-coordinate at which to draw. Defaults to 0. Note that z-ordering may not
                give expected results when transparency is used.
            `angle` : float
                The angle by which the image should be rotated (in degrees). Defaults to 0.
            `scale` : float
                The amount by which the image should be scaled, either as a float, or a tuple
                of two floats (xscale, yscale).

        """
        glPushMatrix()
        glTranslatef(x, y, z)
        if angle:
            glRotatef(angle, 0, 0, 1)
        if scale != 1:
            try:
                glScalef(scale[0], scale[1], 1)
            except TypeError:
                glScalef(scale, scale, 1)
        if self._a_x or self._a_y:
            glTranslatef(-self._a_x, -self._a_y, 0)
        glCallList(self.disp_list)
        glPopMatrix()
Beispiel #4
0
def drawFilledCircle(color, center, radius, normal):
    """
    Scale, rotate/translate the unit circle properly.
    Added a filled circle variant, piotr 080405
    """
    glMatrixMode(GL_MODELVIEW)
    glPushMatrix()
    glColor3fv(color)
    glDisable(GL_LIGHTING)

    glTranslatef(center[0], center[1], center[2])
    rQ = Q(V(0, 0, 1), normal)
    rotAngle = rQ.angle * 180.0 / pi

    #This may cause problems as proved before in Linear motor display.
    #rotation around (0, 0, 0)
    #if vlen(V(rQ.x, rQ.y, rQ.z)) < 0.00005:
    #      rQ.x = 1.0

    glRotatef(rotAngle, rQ.x, rQ.y, rQ.z)
    glScalef(radius, radius, 1.0)
    glCallList(drawing_globals.filledCircleList)
    glEnable(GL_LIGHTING)
    glPopMatrix()
    return
Beispiel #5
0
def drawwiresphere_worker(params):
    """
    Draw a wireframe sphere.  Receive parameters through a sequence so that this
    function and its parameters can be passed to another function for
    deferment.  Right now this is only ColorSorter.schedule (see below)
    """

    (color, pos, radius, detailLevel) = params
    ## assert detailLevel == 1 # true, but leave out for speed
    from utilities.debug_prefs import debug_pref, Choice_boolean_True
    #bruce 060415 experiment, re iMac G4 wiresphere bug; fixes it!
    newway = debug_pref("new wirespheres?", Choice_boolean_True)
    oldway = not newway
    # These objects want a constant line color even if they are selected or
    # highlighted.
    glColor3fv(color)
    glDisable(GL_LIGHTING)
    if oldway:
        glPolygonMode(GL_FRONT, GL_LINE)
    glPushMatrix()
    glTranslatef(pos[0], pos[1], pos[2])
    glScale(radius, radius, radius)
    if oldway:
        glCallList(drawing_globals.sphereList[detailLevel])
    else:
        glCallList(drawing_globals.wiresphere1list)
    glEnable(GL_LIGHTING)
    glPopMatrix()
    if oldway:
        glPolygonMode(GL_FRONT, GL_FILL)
    return
Beispiel #6
0
def drawwiresphere_worker(params):
    """
    Draw a wireframe sphere.  Receive parameters through a sequence so that this
    function and its parameters can be passed to another function for
    deferment.  Right now this is only ColorSorter.schedule (see below)
    """

    (color, pos, radius, detailLevel) = params
    ## assert detailLevel == 1 # true, but leave out for speed
    from utilities.debug_prefs import debug_pref, Choice_boolean_True
    #bruce 060415 experiment, re iMac G4 wiresphere bug; fixes it!
    newway = debug_pref("new wirespheres?", Choice_boolean_True)
    oldway = not newway
    # These objects want a constant line color even if they are selected or
    # highlighted.
    glColor3fv(color)
    glDisable(GL_LIGHTING)
    if oldway:
        glPolygonMode(GL_FRONT, GL_LINE)
    glPushMatrix()
    glTranslatef(pos[0], pos[1], pos[2])
    glScale(radius,radius,radius)
    if oldway:
        glCallList(drawing_globals.sphereList[detailLevel])
    else:
        glCallList(drawing_globals.wiresphere1list)
    glEnable(GL_LIGHTING)
    glPopMatrix()
    if oldway:
        glPolygonMode(GL_FRONT, GL_FILL)
    return
Beispiel #7
0
def drawbrick(color, center, axis, l, h, w, opacity = 1.0):

    if len(color) == 3:
        color = (color[0], color[1], color[2], opacity)

    if opacity != 1.0:	
        glDepthMask(GL_FALSE)
        glEnable(GL_BLEND)
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)  


    apply_material(color)
    glPushMatrix()
    glTranslatef(center[0], center[1], center[2])

    ##Huaicai 1/17/05: To avoid rotate around (0, 0, 0), which causes 
    ## display problem on some platforms
    angle = -acos(axis[2])*180.0/pi
    if (axis[2]*axis[2] >= 1.0):
        glRotate(angle, 0.0, 1.0, 0.0)
    else:
        glRotate(angle, axis[1], -axis[0], 0.0)



    glScale(h, w, l)
    #bruce 060302 revised the contents of solidCubeList while fixing bug 1595
    glCallList(drawing_globals.solidCubeList)

    if opacity != 1.0:	
        glDisable(GL_BLEND)
        glDepthMask(GL_TRUE)

    glPopMatrix()
    return
Beispiel #8
0
    def render(self):
        """ The render pass for the scene """
        self.init_view()

        # Enable lighting and color
        glEnable(GL_LIGHTING)

        glClearColor(0.4, 0.4, 0.4, 0.0)
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)

        # Load the modelview matrix from the current state of the trackball
        glMatrixMode(GL_MODELVIEW)
        glPushMatrix()
        glLoadIdentity()
        loc = self.interaction.translation
        glTranslated(-loc[0], -loc[1], -loc[2])
        glMultMatrixf(self.interaction.trackball.matrix)

        # store the inverse of the current modelview.
        currentModelView = numpy.array(glGetFloatv(GL_MODELVIEW_MATRIX))
        self.modelView = numpy.transpose(currentModelView)
        self.inverseModelView = inv(numpy.transpose(currentModelView))

        # render the scene. This will call the render function for each object in the scene
        self.scene.render()

        # draw the grid
        glDisable(GL_LIGHTING)
        glCallList(G_OBJ_PLANE)
        glPopMatrix()

        # flush the buffers so that the scene can be drawn
        glFlush()
Beispiel #9
0
 def compile_total_list(self):
     if self.total_list is not None:
         glNewList(self.total_list, GL_COMPILE)
         # reset a few things
         glDisable(GL_DEPTH_TEST)
         glDisable(GL_LIGHTING)
         glMatrixMode(GL_PROJECTION)
         glLoadIdentity()
         glMatrixMode(GL_MODELVIEW)
         glLoadIdentity()
         # change the modelview to camera coordinates
         viewport = glGetIntegerv(GL_VIEWPORT)
         width = viewport[2] - viewport[0]
         height = viewport[3] - viewport[1]
         if width > height:
             w = float(width) / float(height)
             h = 1.0
         else:
             w = 1.0
             h = float(height) / float(width)
         glScalef(2 / w, 2 / h, 1.0)
         glCallList(self.draw_list)
         glEnable(GL_DEPTH_TEST)
         glEnable(GL_LIGHTING)
         glEndList()
Beispiel #10
0
    def render(self):
        #init shadow matrix
        self.init_view()

        #open light
        glEnable(GL_LIGHTING)

        #clear color and depth caches
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)

        #set model view matrix(danwei matrix is ok)
        #set trackball's rotate matrix as Modelview
        glMatrixMode(GL_MODELVIEW)
        glPushMatrix()

        #replace now-matrix with hengdeng matrix
        glLoadIdentity()
        glMultMatrixf(self.interaction.trackball.matrix)

        #save Modelview matrix, later change system with anti-matrix
        currentModelView = numpy.array(glGetFloatv(GL_MODELVIEW_MATRIX))
        self.modelView = numpy.transpose(currentModelView)
        self.inverseModelView = inv(numpy.transpose(currentModelView))

        #rend the scene
        self.scene.render()

        #after each shadow , huifu light state
        glDisable(GL_LIGHTING)
        glCallList(G_OBJ_PLANE)
        glPopMatrix()

        glFlush()
Beispiel #11
0
def drawRotateSign(color, pos1, pos2, radius, rotation=0.0):
    """Rotate sign on top of the caps of the cylinder """
    glPushMatrix()
    glColor3fv(color)
    vec = pos2 - pos1
    axis = norm(vec)
    glTranslatef(pos1[0], pos1[1], pos1[2])

    ##Huaicai 1/17/05: To avoid rotate around (0, 0, 0), which causes
    ## display problem on some platforms
    angle = -acos(axis[2]) * 180.0 / pi
    if (axis[2] * axis[2] >= 1.0):
        glRotate(angle, 0.0, 1.0, 0.0)
    else:
        glRotate(angle, axis[1], -axis[0], 0.0)
    glRotate(rotation, 0.0, 0.0, 1.0)  #bruce 050518
    glScale(radius, radius, Numeric.dot(vec, vec)**.5)

    glLineWidth(2.0)
    glDisable(GL_LIGHTING)
    glCallList(drawing_globals.rotSignList)
    glEnable(GL_LIGHTING)
    glLineWidth(1.0)

    glPopMatrix()
    return
Beispiel #12
0
    def draw( self ):
        """draw stl mesh by executing opengl display list
        """
        if self.list_name is None:
            self._make_list()

        glCallList( self.list_name )
Beispiel #13
0
    def render(self):
        #初始化投影矩阵
        self.init_view()

        #启动光照
        glEnable(GL_LIGHTING)
        #清空颜色缓存与深度缓存
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)

        #设置模型视图矩阵,这节课先用单位矩阵就行了。
        glMatrixMode(GL_MODELVIEW)
        glPushMatrix()
        glLoadIdentity()
        glMultMatrixf(self.interaction.trackball.matrix)

        # 存储ModelView矩阵与其逆矩阵之后做坐标系转换用
        currentModelView = numpy.array(glGetFloatv(GL_MODELVIEW_MATRIX))
        self.modelView = numpy.transpose(currentModelView)
        self.inverseModelView = inv(numpy.transpose(currentModelView))
        #渲染场景
        self.scene.render()

        #每次渲染后复位光照状态
        glDisable(GL_LIGHTING)
        glCallList(G_OBJ_PLANE)
        glPopMatrix()
        #把数据刷新到显存上
        glFlush()
Beispiel #14
0
def drawRotateSign(color, pos1, pos2, radius, rotation = 0.0):
    """Rotate sign on top of the caps of the cylinder """
    glPushMatrix()
    glColor3fv(color)
    vec = pos2-pos1
    axis = norm(vec)
    glTranslatef(pos1[0], pos1[1], pos1[2])

    ##Huaicai 1/17/05: To avoid rotate around (0, 0, 0), which causes 
    ## display problem on some platforms
    angle = -acos(axis[2])*180.0/pi
    if (axis[2]*axis[2] >= 1.0):
        glRotate(angle, 0.0, 1.0, 0.0)
    else:
        glRotate(angle, axis[1], -axis[0], 0.0)
    glRotate(rotation, 0.0, 0.0, 1.0) #bruce 050518
    glScale(radius,radius,Numeric.dot(vec,vec)**.5)

    glLineWidth(2.0)
    glDisable(GL_LIGHTING)
    glCallList(drawing_globals.rotSignList)
    glEnable(GL_LIGHTING)
    glLineWidth(1.0)

    glPopMatrix()
    return
Beispiel #15
0
    def draw(self):
        '''Draw the mesh on screen (using display list if compiled)'''
        if self.list:
            glCallList(self.list)
            return

        glPushClientAttrib(GL_CLIENT_VERTEX_ARRAY_BIT)
        glPushAttrib(GL_CURRENT_BIT | GL_ENABLE_BIT | GL_LIGHTING_BIT)
        glEnable(GL_CULL_FACE)
        glCullFace(GL_BACK)
        for group in self.groups:
            if group.material:
                group.material.apply()
            if group.array is None:
                if group.material and group.material.texture:
                    if group.material.texture.rectangle:
                        # texture is a rectangle texture
                        # that's mean we need to adjust the range of texture
                        # coordinate from original 0-1 to 0-width/0-height
                        group.vertices[0::8] = map(
                            lambda x: x * group.material.texture.width,
                            group.vertices[0::8])
                        group.vertices[1::8] = map(
                            lambda x: x * group.material.texture.height,
                            group.vertices[1::8])
                group.array = (GLfloat * len(group.vertices))(*group.vertices)
                group.triangles = len(group.vertices) / 8
            glInterleavedArrays(GL_T2F_N3F_V3F, 0, group.array)
            glDrawArrays(GL_TRIANGLES, 0, group.triangles)
            if group.material:
                group.material.unapply()
        glPopAttrib()
        glPopClientAttrib()
Beispiel #16
0
    def draw(self, x, y, z=0, angle=0, scale=1):
        """Draws the SVG to screen.

        :Parameters
            `x` : float
                The x-coordinate at which to draw.
            `y` : float
                The y-coordinate at which to draw.
            `z` : float
                The z-coordinate at which to draw. Defaults to 0. Note that z-ordering may not
                give expected results when transparency is used.
            `angle` : float
                The angle by which the image should be rotated (in degrees). Defaults to 0.
            `scale` : float
                The amount by which the image should be scaled, either as a float, or a tuple
                of two floats (xscale, yscale).

        """
        glPushMatrix()
        glTranslatef(x, y, z)
        if angle:
            glRotatef(angle, 0, 0, 1)
        if scale != 1:
            try:
                glScalef(scale[0], scale[1], 1)
            except TypeError:
                glScalef(scale, scale, 1)
        if self._a_x or self._a_y:
            glTranslatef(-self._a_x, -self._a_y, 0)
        glCallList(self.disp_list)
        glPopMatrix()
Beispiel #17
0
def drawbrick(color, center, axis, l, h, w, opacity=1.0):

    if len(color) == 3:
        color = (color[0], color[1], color[2], opacity)

    if opacity != 1.0:
        glDepthMask(GL_FALSE)
        glEnable(GL_BLEND)
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)

    apply_material(color)
    glPushMatrix()
    glTranslatef(center[0], center[1], center[2])

    ##Huaicai 1/17/05: To avoid rotate around (0, 0, 0), which causes
    ## display problem on some platforms
    angle = -acos(axis[2]) * 180.0 / pi
    if (axis[2] * axis[2] >= 1.0):
        glRotate(angle, 0.0, 1.0, 0.0)
    else:
        glRotate(angle, axis[1], -axis[0], 0.0)

    glScale(h, w, l)
    #bruce 060302 revised the contents of solidCubeList while fixing bug 1595
    glCallList(drawing_globals.solidCubeList)

    if opacity != 1.0:
        glDisable(GL_BLEND)
        glDepthMask(GL_TRUE)

    glPopMatrix()
    return
Beispiel #18
0
 def compile_total_list(self):
     if self.total_list is not None:
         glNewList(self.total_list, GL_COMPILE)
         # reset a few things
         glDisable(GL_DEPTH_TEST)
         glDisable(GL_LIGHTING)
         glMatrixMode(GL_PROJECTION)
         glLoadIdentity()
         glMatrixMode(GL_MODELVIEW)
         glLoadIdentity()
         # change the modelview to camera coordinates
         viewport = glGetIntegerv(GL_VIEWPORT)
         width = viewport[2] - viewport[0]
         height = viewport[3] - viewport[1]
         if width > height:
             w = float(width) / float(height)
             h = 1.0
         else:
             w = 1.0
             h = float(height) / float(width)
         glScalef(2/w, 2/h, 1.0)
         glCallList(self.draw_list)
         glEnable(GL_DEPTH_TEST)
         glEnable(GL_LIGHTING)
         glEndList()
Beispiel #19
0
    def draw(self):
        '''Draw the mesh on screen (using display list if compiled)'''
        if self.list:
            glCallList(self.list)
            return

        glPushClientAttrib(GL_CLIENT_VERTEX_ARRAY_BIT)
        glPushAttrib(GL_CURRENT_BIT | GL_ENABLE_BIT | GL_LIGHTING_BIT)
        glEnable(GL_CULL_FACE)
        glCullFace(GL_BACK)
        for group in self.groups:
            if group.material:
                group.material.apply()
            if group.array is None:
                if group.material and group.material.texture:
                    if group.material.texture.rectangle:
                        # texture is a rectangle texture
                        # that's mean we need to adjust the range of texture
                        # coordinate from original 0-1 to 0-width/0-height
                        group.vertices[0::8] = map(
                            lambda x: x * group.material.texture.width,
                            group.vertices[0::8]
                        )
                        group.vertices[1::8] = map(
                            lambda x: x * group.material.texture.height,
                            group.vertices[1::8]
                        )
                group.array = (GLfloat * len(group.vertices))(*group.vertices)
                group.triangles = len(group.vertices) / 8
            glInterleavedArrays(GL_T2F_N3F_V3F, 0, group.array)
            glDrawArrays(GL_TRIANGLES, 0, group.triangles)
            if group.material:
                group.material.unapply()
        glPopAttrib()
        glPopClientAttrib()
Beispiel #20
0
 def render(self):
     glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)
     glMatrixMode(GL_MODELVIEW)
     glPushMatrix()
     glTranslated(self.center[0], self.center[1], self.center[2])
     glCallList(G_OBJ_CUBE)
     glPopMatrix()
     glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)
Beispiel #21
0
 def paintGL(self):
     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
     glLoadIdentity()
     glTranslated(0.0, 0.0, -10.0)
     glRotated(self.xRot / 16.0, 1.0, 0.0, 0.0)
     glRotated(self.yRot / 16.0, 0.0, 1.0, 0.0)
     glRotated(self.zRot / 16.0, 0.0, 0.0, 1.0)
     glCallList(self.object)
Beispiel #22
0
    def display_by_key(self, key: str):
        """Renders a specific piece of geometry from the view collection.

        :param key: The pre-computed object to render.
        """
        try:
            glCallList(self._display_lists[key])
        except KeyError:
            raise KeyError('No display list with key {0} present on PrerenderedView'.format(key))
Beispiel #23
0
def draw_mosaic(picture):
    m = mosaic_factory.mosaic(picture, args.tiles, args.reuse)
    for column in xrange(args.tiles):
        for line in xrange(args.tiles):
            glPushMatrix()
            glTranslatef(column * mosaic_factory.ratio * size, line * size,
                         0.0)
            glCallList(picture_display_lists[m[args.tiles - 1 - line][column]])
            glPopMatrix()
Beispiel #24
0
 def render(self):
     """ render the AABB. This can be useful for debugging purposes """
     glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)
     glMatrixMode(GL_MODELVIEW)
     glPushMatrix()
     glTranslated(self.center[0], self.center[1], self.center[2])
     glCallList(G_OBJ_CUBE)
     glPopMatrix()
     glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)
Beispiel #25
0
 def render(self):
     """ 渲染显示包围盒,可在调试的时候使用 """
     glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)
     glMatrixMode(GL_MODELVIEW)
     glPushMatrix()
     glTranslated(self.center[0], self.center[1], self.center[2])
     glCallList(G_OBJ_CUBE)
     glPopMatrix()
     glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)
Beispiel #26
0
 def display(self):
     """Displays the precomputed nav map view.
     This function will do nothing if no display list has yet been built.
     """
     if '_navmap' in self._display_lists:
         glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
         glEnable(GL_BLEND)
         glPushMatrix()
         glCallList(self._display_lists['_navmap'])
         glPopMatrix()
Beispiel #27
0
    def display(self):
        if self.world:
            self.world.drawGL()

        glPointSize(max(1, self.point_size))
        for point_list in self.point_lists:
            glCallList(point_list)

        for xform in self.xforms:
            gldraw.xform_widget(xform, 0.1, 0.01)
Beispiel #28
0
    def render(self):
        if self.display_list is None:
            self.display_list = glGenLists(1)
            glNewList(self.display_list, GL_COMPILE)

            for cube in self.cubes:
                cube.render()

            glEndList()
        else:
            glCallList(self.display_list)
Beispiel #29
0
    def paintGL(self):
        if self.parent.ipcon == None:
            return

        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)

        # Move Right And Into The Screen
        glLoadIdentity()
        glTranslatef(0.0, 0.0, -5.0)
        glMultMatrixf(self.m)

        glCallList(self.display_list)
Beispiel #30
0
    def paintGL(self):
        if self.parent.ipcon == None:
            return

        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)

        # Move Right And Into The Screen
        glLoadIdentity()
        glTranslatef(0.0, 0.0, -5.0)
        glMultMatrixf(self.m)

        glCallList(self.display_list)
Beispiel #31
0
 def draw_dl(self):                  #russ 080320 Added.
     """
     Draw the displist (cached display procedure.)
     """
     #russ 080320: Experiment with VBO drawing from cached ColorSorter lists.
     if (ColorSortedDisplayList.cache_ColorSorter and
         drawing_globals.allow_color_sorting and
         drawing_globals.use_color_sorted_vbos):
         ColorSorter.draw_sorted(self.sorted_by_color)
     else:
         # Call a normal OpenGL display list.
         glCallList(self.dl)
     return
Beispiel #32
0
 def draw_dl(self):  #russ 080320 Added.
     """
     Draw the displist (cached display procedure.)
     """
     #russ 080320: Experiment with VBO drawing from cached ColorSorter lists.
     if (ColorSortedDisplayList.cache_ColorSorter
             and drawing_globals.allow_color_sorting
             and drawing_globals.use_color_sorted_vbos):
         ColorSorter.draw_sorted(self.sorted_by_color)
     else:
         # Call a normal OpenGL display list.
         glCallList(self.dl)
     return
Beispiel #33
0
    def render(self):
        glPushMatrix()
        glMultMatrixf(numpy.transpose(self.translation))
        glMultMatrixf(self.scalemat)
        cur_color = color.COLORS[self.color_index]
        glColor3f(cur_color[0], cur_color[1], cur_color[2])
        if self.selected:  # emit light if the node is selected
            glMaterialfv(GL_FRONT, GL_EMISSION, [0.3, 0.3, 0.3])
        glCallList(self.call_list)
        if self.selected:
            glMaterialfv(GL_FRONT, GL_EMISSION, [0.0, 0.0, 0.0])

        glPopMatrix()
Beispiel #34
0
def draw_mosaic(picture):
    m = mosaic_factory.mosaic(picture, args.tiles, args.reuse)
    for column in xrange(args.tiles):
        for line in xrange(args.tiles):
            glPushMatrix()
            glTranslatef(
                column * mosaic_factory.ratio * size,
                line * size, 0.0
            )
            glCallList(
                picture_display_lists[m[args.tiles - 1 - line][column]]
            )
            glPopMatrix()
Beispiel #35
0
    def render(self):
        glPushMatrix()
        glMultMatrixf(numpy.transpose(self.translation))
        glMultMatrixf(self.scalemat)
        cur_color = color.COLORS[self.color_index]
        glColor3f(cur_color[0], cur_color[1], cur_color[2])
        if self.selected:  # emit light if the node is selected
            glMaterialfv(GL_FRONT, GL_EMISSION, [0.3, 0.3, 0.3])
        glCallList(self.call_list)
        if self.selected:
            glMaterialfv(GL_FRONT, GL_EMISSION, [0.0, 0.0, 0.0])

        glPopMatrix()
Beispiel #36
0
 def call(self):
     """Calls the display list using glCallList(). If this display list
     has not previously been used with the current context, allocates
     a display list number and arranges for do_setup() to be called
     to compile a representation of the display list."""
     share_group = current_share_group()
     gl_id = self._gl_id.get(share_group)
     if gl_id is None:
         gl_id = glGenLists(1)
         #print "GLDisplayList: assigned id %d for %s in share group %s" % (
         #	gl_id, self, share_group) ###
         self._gl_id[share_group] = gl_id
         call_when_not_compiling_display_list(lambda: self._compile(gl_id))
     glCallList(gl_id)
 def call(self):
     """Calls the display list using glCallList(). If this display list
     has not previously been used with the current context, allocates
     a display list number and arranges for do_setup() to be called
     to compile a representation of the display list."""
     share_group = current_share_group()
     gl_id = self._gl_id.get(share_group)
     if gl_id is None:
         gl_id = glGenLists(1)
         #print "GLDisplayList: assigned id %d for %s in share group %s" % (
         #	gl_id, self, share_group) ###
         self._gl_id[share_group] = gl_id
         call_when_not_compiling_display_list(lambda: self._compile(gl_id))
     glCallList(gl_id)
Beispiel #38
0
def drawwirebox(color, pos, len):
    glPolygonMode(GL_FRONT, GL_LINE)
    glPolygonMode(GL_BACK, GL_LINE)
    glDisable(GL_LIGHTING)
    glDisable(GL_CULL_FACE)
    glColor3fv(color)
    glPushMatrix()
    glTranslatef(pos[0], pos[1], pos[2])
    glScale(len[0], len[1], len[2])
    glCallList(drawing_globals.CubeList)
    glPopMatrix()
    glEnable(GL_CULL_FACE)
    glEnable(GL_LIGHTING)
    glPolygonMode(GL_FRONT, GL_FILL)
    #bruce 050729 to help fix bug 835 or related bugs
    glPolygonMode(GL_BACK, GL_FILL)
    return
Beispiel #39
0
def drawwirebox(color, pos, length):
    glPolygonMode(GL_FRONT, GL_LINE)
    glPolygonMode(GL_BACK, GL_LINE)
    glDisable(GL_LIGHTING)
    glDisable(GL_CULL_FACE)
    glColor3fv(color)
    glPushMatrix()
    glTranslatef(pos[0], pos[1], pos[2])
    glScale(length[0], length[1], length[2])
    glCallList(drawing_globals.CubeList)
    glPopMatrix()
    glEnable(GL_CULL_FACE)
    glEnable(GL_LIGHTING)
    glPolygonMode(GL_FRONT, GL_FILL)
    #bruce 050729 to help fix bug 835 or related bugs
    glPolygonMode(GL_BACK, GL_FILL)
    return
Beispiel #40
0
 def _anotherDraw(self, layerColor):
     """
     The original way of selecting cookies, but do it layer by layer,
     so we can control how to display each layer.
     """
     if self.havelist:
         glCallList(self.displist.dl)
         return
     glNewList(self.displist.dl, GL_COMPILE_AND_EXECUTE)
     for layer in self.layeredCurves.keys():
         bbox = self.layeredCurves[layer][0]
         curves = self.layeredCurves[layer][1:]
         if not curves:
             continue
         color = layerColor[layer]
         for c in curves:
             c.draw()
         try:
             bblo, bbhi = bbox.data[1], bbox.data[0]
             allCells = genDiam(bblo - 1.6, bbhi + 1.6, self.latticeType)
             for cell in allCells:
                 for pp in cell:
                     p1 = p2 = None
                     if self.isin(pp[0], curves):
                         if self.isin(pp[1], curves):
                             p1 = pp[0]
                             p2 = pp[1]
                         else:
                             p1 = pp[0]
                             p2 = ((pp[1] + pp[0]) / 2, )
                     elif self.isin(pp[1], curves):
                         p1 = pp[1]
                         p2 = ((pp[1] + pp[0]) / 2, )
                     if p1 and p2:
                         self._cellDraw(color, p1, p2)
         except:
             # bruce 041028 -- protect against exceptions while making display
             # list, or OpenGL will be left in an unusable state (due to the lack
             # of a matching glEndList) in which any subsequent glNewList is an
             # invalid operation. (Also done in chem.py; see more comments there.)
             print_compact_traceback(
                 "bug: exception in shape.draw's displist; ignored: ")
     glEndList()
     self.havelist = 1  #
     return
Beispiel #41
0
 def orthogonalPass(self):
     """ display FPS. """
     
     secs = self.passedSecs
     self.timePassed += secs
     
     if self.timePassed>=1.0:
         self.timePassed -= 1.0
         fps = self.getFPS()
         
         if fps!=self.FPS:
             self.FPS = fps
             glNewList(self.fpsDisplayList, GL_COMPILE)
             self.printFPS(5, self.fpsY, "FPS %d" % self.FPS)
             glEndList()
     
     # we expect to be in orthogonal projection now
     glCallList(self.fpsDisplayList)
Beispiel #42
0
 def _anotherDraw(self, layerColor):
     """
     The original way of selecting cookies, but do it layer by layer, 
     so we can control how to display each layer.
     """
     if self.havelist:
         glCallList(self.displist.dl)
         return
     glNewList(self.displist.dl, GL_COMPILE_AND_EXECUTE)
     for layer in self.layeredCurves.keys():
         bbox = self.layeredCurves[layer][0]
         curves = self.layeredCurves[layer][1:]
         if not curves:
             continue
         color = layerColor[layer]
         for c in curves:
             c.draw()
         try:
             bblo, bbhi = bbox.data[1], bbox.data[0]
             allCells = genDiam(bblo - 1.6, bbhi + 1.6, self.latticeType)
             for cell in allCells:
                 for pp in cell:
                     p1 = p2 = None
                     if self.isin(pp[0], curves):
                         if self.isin(pp[1], curves):
                             p1 = pp[0]
                             p2 = pp[1]
                         else:
                             p1 = pp[0]
                             p2 = ((pp[1] + pp[0]) / 2,)
                     elif self.isin(pp[1], curves):
                         p1 = pp[1]
                         p2 = ((pp[1] + pp[0]) / 2,)
                     if p1 and p2:
                         self._cellDraw(color, p1, p2)
         except:
             # bruce 041028 -- protect against exceptions while making display
             # list, or OpenGL will be left in an unusable state (due to the lack
             # of a matching glEndList) in which any subsequent glNewList is an
             # invalid operation. (Also done in chem.py; see more comments there.)
             print_compact_traceback("bug: exception in shape.draw's displist; ignored: ")
     glEndList()
     self.havelist = 1  #
     return
Beispiel #43
0
def render_to_png(filename,
                  callback,
                  obb,
                  model_matrix=(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0,
                                1)):
    from pygame import init, display, quit
    from pygame.constants import OPENGL, DOUBLEBUF
    from OpenGL.GL import glLightfv, glCullFace, glEnable, glShadeModel, glMatrixMode, glLoadIdentity, glClear, \
        glLoadMatrixf, glPolygonMode, glCallList, glReadPixels, GL_LIGHT0, GL_POSITION, GL_AMBIENT, GL_DIFFUSE, \
        GL_BACK, GL_LIGHTING, GL_COLOR_MATERIAL, GL_DEPTH_TEST, GL_SMOOTH, GL_PROJECTION, GL_MODELVIEW, \
        GL_COLOR_BUFFER_BIT, GL_DEPTH_BUFFER_BIT, GL_FRONT_AND_BACK, GL_FILL, GL_LINE, GL_BGR, GL_UNSIGNED_BYTE
    from OpenGL.GLU import gluPerspective
    from cv2 import imwrite
    from numpy import frombuffer, uint8
    init()
    viewport = (800, 600)
    display.set_mode(viewport, OPENGL | DOUBLEBUF)
    glLightfv(GL_LIGHT0, GL_POSITION, (0, -1, 0, 0))
    glLightfv(GL_LIGHT0, GL_AMBIENT, (0.2, 0.2, 0.2, 1))
    glLightfv(GL_LIGHT0, GL_DIFFUSE, (0.5, 0.5, 0.5, 1))
    glCullFace(GL_BACK)
    glEnable(GL_LIGHT0)
    glEnable(GL_LIGHTING)
    glEnable(GL_COLOR_MATERIAL)
    glEnable(GL_DEPTH_TEST)
    glShadeModel(GL_SMOOTH)
    glMatrixMode(GL_PROJECTION)
    glLoadIdentity()
    width, height = viewport
    gluPerspective(90.0, width / float(height), 0.1, 100.0)
    glEnable(GL_DEPTH_TEST)
    glMatrixMode(GL_MODELVIEW)
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
    glLoadIdentity()
    glLoadMatrixf(model_matrix)
    glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)
    glCallList(callback())
    glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)
    glCallList(create_obb_gl_list(obb))
    img_data = glReadPixels(0, 0, width, height, GL_BGR, GL_UNSIGNED_BYTE)
    img = frombuffer(img_data, dtype=uint8)
    img = img.reshape((height, width, 3))
    imwrite(filename, img)
    quit()
Beispiel #44
0
    def draw(self, eyeX, horizonY, cardList):
        """draw the card in place, using small/large image data as needed """

        with pushMatrix():
            pos = num.array(self.center)
            pos[2] += self.z.x
            if self.zoom:
                full = [eyeX, horizonY, 6.3]
                pos = lerp(pos, full, self.zoom)
            glTranslatef(*pos)

            layers = [('thumb', 1, self.thumbImage.getData('thumb'))]
            if self.zoom:
                data = self.thumbImage.getData('full')
                if data is not None:
                    layers.append(('full', 1, data))
                    # once opacity is fadable, and it's at 1, then we
                    # can remove the thumb layer from the list.

                    layers.reverse() # fix opengl draw order so hires is on top

                    

            for size, opacity, imgData in layers:
                if imgData is None:
                    # need to unset tx here!
                    glCallList(cardList)
                    # or draw a blank border, maybe some load status
                    # indication
                else:
                    (w,h), textureData = imgData
                    glBindTexture(GL.GL_TEXTURE_2D, 0)
                    glTexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_RGB,
                                 w,
                                 h,
                                 0,
                                 GL.GL_RGB, GL.GL_UNSIGNED_BYTE, textureData)
                    glTexParameterf(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER,
                                    GL.GL_LINEAR)
                    glTexParameterf(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER,
                                    GL.GL_LINEAR)

                    # card facing +Z from -1<x<1 -1<y<1
                    glCallList(cardList)
 def glCallList(self, listname):
     """
     Compile a call to the given display list.
     Note: most error checking and any extra tracking is responsibility of caller.
     """
     ##e in future, could merge successive calls into one call of multiple lists
     ## assert not self.compiling_displist # redundant with OpenGL only if we have no bugs in maintaining it, so worth checking
     # above was WRONG -- what was I thinking? This is permitted, and we'll need it whenever one displist can call another.
     # (And I'm surprised I didn't encounter it before -- did I still never try an MT with displists?)
     # (Did I mean to put this into some other method? or into only certain uses of this method??
     # For now, do an info print, in case sometimes this does indicate an error, and since it's useful
     # for analyzing whether nested displists are behaving as expected. [bruce 070203]
     if self.compiling_displist and debug_pref(
         "GLPane: print nested displist compiles?", Choice_boolean_False, prefs_key=True
     ):
         print "debug: fyi: displist %r is compiling a call to displist %r" % (self.compiling_displist, listname)
     assert listname  # redundant with following?
     glCallList(listname)
     return
Beispiel #46
0
def displayListify(name):
    global displayLists
    if name in displayLists:
        # Hey, we've made this display list before!
        # Run the existing list, then break out of the with block
        glCallList(displayLists[name])
        try:
            yield True
        except LeaveWith:
            pass
            
    else:
        # Nope, not made this display list. Wrap the block in "work rememberers"
        displayLists[name] = thisList = glGenLists(1)
        glNewList(thisList, GL_COMPILE_AND_EXECUTE)
        try:
            yield
        finally:
            glEndList()
    def render(self):
        """ The render pass for the scene """
        self.init_view()

        glEnable(GL_LIGHTING)
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)

        # Load the modelview matrix from the current state of the trackball
        glMatrixMode(GL_MODELVIEW)
        glPushMatrix()
        glLoadIdentity()
        tar = self.interaction.LookAttarget;
        self.Camera.target = (tar[0],tar[1],tar[2])
        if self.Camera.CameraMode == 'Trackball':
            loc = self.Camera.position;
            #Camera.position
            glTranslated(-loc[0], -loc[1], -loc[2])
            glMultMatrixf(self.interaction.trackball.matrix)
        elif self.Camera.CameraMode == 'LookAt':
            # embed()
            self.Camera.point()
        elif self.Camera.CameraMode == 'LookAtFollow':
            self.Camera.follow()
            self.Camera.point()
        else:
            glMultMatrixf(self.interaction.trackball.matrix) # by default revert to trackball if mode is set incorrectly

        # store the inverse of the current modelview.
        currentModelView = numpy.array(glGetFloatv(GL_MODELVIEW_MATRIX))
        self.modelView = numpy.transpose(currentModelView)
        self.inverseModelView = inv(numpy.transpose(currentModelView))

        # render the scene. This will call the render function for each object in the scene
        self.scene.render()

        # draw the grid
        glDisable(GL_LIGHTING)
        glCallList(G_OBJ_PLANE)
        glPopMatrix()

        # flush the buffers so that the scene can be drawn
        glFlush()
Beispiel #48
0
 def glCallList(self, listname):
     """
     Compile a call to the given display list.
     Note: most error checking and any extra tracking is responsibility of caller.
     """
     ##e in future, could merge successive calls into one call of multiple lists
     ## assert not self.compiling_displist # redundant with OpenGL only if we have no bugs in maintaining it, so worth checking
     # above was WRONG -- what was I thinking? This is permitted, and we'll need it whenever one displist can call another.
     # (And I'm surprised I didn't encounter it before -- did I still never try an MT with displists?)
     # (Did I mean to put this into some other method? or into only certain uses of this method??
     # For now, do an info print, in case sometimes this does indicate an error, and since it's useful
     # for analyzing whether nested displists are behaving as expected. [bruce 070203]
     if self.compiling_displist and \
        debug_pref("GLPane: print nested displist compiles?",
                   Choice_boolean_False,
                   prefs_key = True):
         print "debug: fyi: displist %r is compiling a call to displist %r" % \
               (self.compiling_displist, listname)
     assert listname  # redundant with following?
     glCallList(listname)
     return
Beispiel #49
0
def test_Draw_model(glpane):
    # WARNING: this duplicates some code with test_drawing().
    if first_time:
        return    # Do nothing during the initial setup script.

    if testCase == 1:
        test_csdl.draw()
    elif testCase == 2 or testCase == 5:
        glColor3i(127, 127, 127)
        glCallList(test_dl)
    elif int(testCase) == 3:
        test_spheres.draw()
    elif int(testCase) == 8:
        test_Draw_8x(glpane)
        pass
    elif int(testCase) >= 100:
        #bruce 090102
        glpane.configure_enabled_shaders()
        test_Object.draw_complete()
        pass
    return
Beispiel #50
0
def test_Draw_model(glpane):
    # WARNING: this duplicates some code with test_drawing().
    if first_time:
        return  # Do nothing during the initial setup script.

    if testCase == 1:
        test_csdl.draw()
    elif testCase == 2 or testCase == 5:
        glColor3i(127, 127, 127)
        glCallList(test_dl)
    elif int(testCase) == 3:
        test_spheres.draw()
    elif int(testCase) == 8:
        test_Draw_8x(glpane)
        pass
    elif int(testCase) >= 100:
        #bruce 090102
        glpane.configure_enabled_shaders()
        test_Object.draw_complete()
        pass
    return
Beispiel #51
0
    def draw(self, eyeX, horizonY, cardList):
        """draw the card in place, using small/large image data as needed """

        with pushMatrix():
            pos = num.array(self.center)
            pos[2] += self.z.x
            if self.zoom:
                full = [eyeX, horizonY, 6.3]
                pos = lerp(pos, full, self.zoom)
            glTranslatef(*pos)

            layers = [('thumb', 1, self.thumbImage.getData('thumb'))]
            if self.zoom:
                data = self.thumbImage.getData('full')
                if data is not None:
                    layers.append(('full', 1, data))
                    # once opacity is fadable, and it's at 1, then we
                    # can remove the thumb layer from the list.

                    layers.reverse(
                    )  # fix opengl draw order so hires is on top

            for size, opacity, imgData in layers:
                if imgData is None:
                    # need to unset tx here!
                    glCallList(cardList)
                    # or draw a blank border, maybe some load status
                    # indication
                else:
                    (w, h), textureData = imgData
                    glBindTexture(GL.GL_TEXTURE_2D, 0)
                    glTexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_RGB, w, h, 0,
                                 GL.GL_RGB, GL.GL_UNSIGNED_BYTE, textureData)
                    glTexParameterf(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER,
                                    GL.GL_LINEAR)
                    glTexParameterf(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER,
                                    GL.GL_LINEAR)

                    # card facing +Z from -1<x<1 -1<y<1
                    glCallList(cardList)
Beispiel #52
0
def drawcylinder_worker(params):
    """
    Draw a cylinder.  Receive parameters through a sequence so that this
    function and its parameters can be passed to another function for
    deferment.  Right now this is only ColorSorter.schedule (see below)

    @warning: our circular cross-section is approximated by a 13-gon
    whose alignment around the axis is chosen arbitrary, in a way
    which depends on the direction of the axis; negating the axis usually
    causes a different alignment of that 13-gon. This effect can cause
    visual bugs when drawing one cylinder over an identical or slightly
    smaller one (e.g. when highlighting a bond), unless the axes are kept
    parallel as opposed to antiparallel.
    """
    if not _DRAW_BONDS:
        return

    (pos1, pos2, radius, capped) = params

    glPushMatrix()
    vec = pos2-pos1
    axis = norm(vec)
    glTranslatef(pos1[0], pos1[1], pos1[2])

    ##Huaicai 1/17/05: To avoid rotate around (0, 0, 0), which causes 
    ## display problem on some platforms
    angle = -acos(axis[2])*180.0/pi
    if (axis[2]*axis[2] >= 1.0):
        glRotate(angle, 0.0, 1.0, 0.0)
    else:
        glRotate(angle, axis[1], -axis[0], 0.0)

    glScale(radius,radius,Numeric.dot(vec,vec)**.5)
    glCallList(drawing_globals.CylList)
    if capped:
        glCallList(drawing_globals.CapList)

    glPopMatrix()

    return
Beispiel #53
0
def drawcylinder_worker(params):
    """
    Draw a cylinder.  Receive parameters through a sequence so that this
    function and its parameters can be passed to another function for
    deferment.  Right now this is only ColorSorter.schedule (see below)

    @warning: our circular cross-section is approximated by a 13-gon
    whose alignment around the axis is chosen arbitrary, in a way
    which depends on the direction of the axis; negating the axis usually
    causes a different alignment of that 13-gon. This effect can cause
    visual bugs when drawing one cylinder over an identical or slightly
    smaller one (e.g. when highlighting a bond), unless the axes are kept
    parallel as opposed to antiparallel.
    """
    if not _DRAW_BONDS:
        return

    (pos1, pos2, radius, capped) = params

    glPushMatrix()
    vec = pos2 - pos1
    axis = norm(vec)
    glTranslatef(pos1[0], pos1[1], pos1[2])

    ##Huaicai 1/17/05: To avoid rotate around (0, 0, 0), which causes
    ## display problem on some platforms
    angle = -acos(axis[2]) * 180.0 / pi
    if (axis[2] * axis[2] >= 1.0):
        glRotate(angle, 0.0, 1.0, 0.0)
    else:
        glRotate(angle, axis[1], -axis[0], 0.0)

    glScale(radius, radius, Numeric.dot(vec, vec)**.5)
    glCallList(drawing_globals.CylList)
    if capped:
        glCallList(drawing_globals.CapList)

    glPopMatrix()

    return
Beispiel #54
0
def display():
    start_point = (
        start_picture_coord[0] * HEIGHT * mosaic_factory.ratio / (args.tiles - 1),
        start_picture_coord[1] * HEIGHT / (args.tiles - 1)
    )
    center = (HEIGHT * mosaic_factory.ratio / 2., HEIGHT / 2.)
    reverse_sigmoid_progress = fake_sigmoid(1 - progress)
    sigmoid_progress = 1 - reverse_sigmoid_progress
    max_zoom = args.tiles
    zoom = max_zoom ** reverse_sigmoid_progress
    angle = start_orientation + sigmoid_progress * angle_difference(
        current_mosaic_picture.orientation,
        start_orientation
    )
    if reverse_sigmoid_progress > 0.1:
        alpha = 1.0
    else:
        alpha = reverse_sigmoid_progress * 10.0

    glClear(GL_COLOR_BUFFER_BIT)
    glPushMatrix()

    glTranslatef(center[0], center[1], 0.0)
    glRotatef(angle, 0, 0, 1)
    glTranslatef(-center[0], -center[1], 0.0)

    glTranslatef(start_point[0], start_point[1], 0.0)
    glScalef(zoom, zoom, 1.0)
    glTranslatef(-start_point[0], -start_point[1], 0.0)

    glColor4f(0.0, 0.0, 0.0, alpha)
    glCallList(mosaic_display_lists[current_mosaic_picture])
    glColor4f(0.0, 0.0, 0.0, 1.0 - alpha)

    glScalef(max_zoom, max_zoom, 1.0)
    glCallList(picture_display_lists[current_mosaic_picture])

    glPopMatrix()
    glutSwapBuffers()
Beispiel #55
0
def drawwirecube(color, pos, radius, lineWidth=3.0):
    glPolygonMode(GL_FRONT, GL_LINE)
    glPolygonMode(GL_BACK, GL_LINE)
    glDisable(GL_LIGHTING)
    glDisable(GL_CULL_FACE)
    glColor3fv(color)
    glPushMatrix()
    glTranslatef(pos[0], pos[1], pos[2])
    if type(radius) == type(1.0):
        glScale(radius,radius,radius)
    else: 
        glScale(radius[0], radius[1], radius[2])
    glLineWidth(lineWidth)
    glCallList(drawing_globals.lineCubeList)
    glLineWidth(1.0) ## restore its state
    glPopMatrix()
    glEnable(GL_CULL_FACE)
    glEnable(GL_LIGHTING)
    glPolygonMode(GL_FRONT, GL_FILL)
    #bruce 050729 to help fix bug 835 or related bugs
    glPolygonMode(GL_BACK, GL_FILL)
    return
Beispiel #56
0
def drawLinearArrows(longScale):   
    glCallList(drawing_globals.linearArrowList)
    newPos = drawing_globals.halfHeight*longScale
    glPushMatrix()
    glTranslate(0.0, 0.0, -newPos)
    glCallList(drawing_globals.linearArrowList)
    glPopMatrix()
    glPushMatrix()
    glTranslate(0.0, 0.0, newPos -2.0*drawing_globals.halfEdge)
    glCallList(drawing_globals.linearArrowList)
    glPopMatrix()
    return
def drawSiCGrid(color, line_type, w, h, up, right):
    """
    Draw SiC grid.
    """
    
    if line_type == NO_LINE:
        return
    
    XLen = sic_uLen * 3.0
    YLen = sic_yU * 2.0
    hw = w/2.0; hh = h/2.0
    i1 = int(floor(-hw/XLen))
    i2 = int(ceil(hw/XLen))
    j1 = int(floor(-hh/YLen))
    j2 = int(ceil(hh/YLen))
    
    glDisable(GL_LIGHTING)
    glColor3fv(color)

    if line_type > 1:
        glEnable(GL_LINE_STIPPLE)
        if line_type == DASHED_LINE:
            glLineStipple (1, 0x00FF)  #  dashed
        elif line_type == DOTTED_LINE:
            glLineStipple (1, 0x0101)  #  dotted
        else:
            print "drawer.drawSiCGrid(): line_type '", line_type, \
                  "' is not valid.  Drawing dashed grid line."
            glLineStipple (1, 0x00FF)  #  dashed
    
    glClipPlane(GL_CLIP_PLANE0, (1.0, 0.0, 0.0, hw))
    glClipPlane(GL_CLIP_PLANE1, (-1.0, 0.0, 0.0, hw))
    glClipPlane(GL_CLIP_PLANE2, (0.0, 1.0, 0.0, hh))
    glClipPlane(GL_CLIP_PLANE3, (0.0, -1.0, 0.0, hh))
    glEnable(GL_CLIP_PLANE0)
    glEnable(GL_CLIP_PLANE1)
    glEnable(GL_CLIP_PLANE2)
    glEnable(GL_CLIP_PLANE3)
     
    glPushMatrix()
    glTranslate(i1*XLen,  j1*YLen, 0.0)
    for i in range(i1, i2):
        glPushMatrix()
        for j in range(j1, j2):
            glCallList(SiCGridList)
            glTranslate(0.0, YLen, 0.0)
        glPopMatrix()
        glTranslate(XLen, 0.0, 0.0)
    glPopMatrix()
    
    glDisable(GL_CLIP_PLANE0)
    glDisable(GL_CLIP_PLANE1)
    glDisable(GL_CLIP_PLANE2)
    glDisable(GL_CLIP_PLANE3)
        
    if line_type > 1:
        glDisable (GL_LINE_STIPPLE)

    xpos, ypos = hw, 0.0
    f3d = Font3D(xpos=xpos, ypos=ypos, right=right, up=up,
                 rot90=False, glBegin=False)
    for j in range(j1, j2):
        yoff = j * YLen
        if -hh < yoff + ypos < hh:
            f3d.drawString("%-.4g" % yoff, color=color, yoff=yoff)

    xpos, ypos = 0.0, hh
    f3d = Font3D(xpos=xpos, ypos=ypos, right=right, up=up,
                 rot90=True, glBegin=False)
    for i in range(2*i1, 2*i2):
        yoff = i * (XLen/2)
        if -hw < yoff + xpos < hw:
            f3d.drawString("%-.4g" % yoff, color=color, yoff=yoff)
    
    glEnable(GL_LIGHTING)
    return
Beispiel #58
0
 def call_list(self, l):
     glCallList(l)