예제 #1
0
def draw_callback_px(self, context): 
    region = context.region  
    rv3d = context.space_data.region_3d
            
    init2d = self.obLoc[:2]
    dest2d = self.mouseCoNew[:2]

    # Line drawing
    bgl.glPushAttrib(bgl.GL_ENABLE_BIT)
    # glPushAttrib is done to return everything to normal after drawing
    
    bgl.glLineStipple(2, 0x9999)
    bgl.glEnable(bgl.GL_LINE_STIPPLE)
    
    bgl.glEnable(bgl.GL_BLEND)
    bgl.glColor4f(0.0, 0.0, 0.0, 1)
    #bgl.glLineWidth(2)

    bgl.glBegin(bgl.GL_LINE_STRIP)
    bgl.glVertex2f(*init2d)
    bgl.glVertex2f(*dest2d)
    bgl.glEnd()
    bgl.glPopAttrib()

    # restore opengl defaults
    bgl.glLineWidth(1)
    bgl.glDisable(bgl.GL_BLEND)
    bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
	def draw_callback_postview(self, context):
		bgl.glPushAttrib(bgl.GL_ALL_ATTRIB_BITS)    # save OpenGL attributes
		self.draw_postview(context)
		if len(self.selectCntrl):
			cntrlLength = len(self.selectCntrl)
			for x in range(0,cntrlLength):
				# assuming that we have only one control point, so if
				# anything is selected it would be the only point
				p111 = self.selectCntrl[x]
				t111 = p111.to_tuple()
				vrot = context.space_data.region_3d.view_rotation
				dx = (vrot * Vector((1,0,0))).normalized()          # compute right dir relative to view
				dy = (vrot * Vector((0,1,0))).normalized()          # compute up dir relative to view
				px = tuple(p111 + dx*0.5)
				py = tuple(p111 + dy*0.5)

				# highlight the point
				bgl.glColor3f(1,1,0)
				bgl.glBegin(bgl.GL_POINTS)
				bgl.glVertex3f(*t111)
				bgl.glEnd()

				# draw lines to indicate right (red) and up (green)
				bgl.glBegin(bgl.GL_LINES)
				bgl.glColor3f(1,0,0)
				bgl.glVertex3f(*t111)
				bgl.glVertex3f(*px)
				bgl.glColor3f(0,1,0)
				bgl.glVertex3f(*t111)
				bgl.glVertex3f(*py)
				bgl.glEnd()
		bgl.glPopAttrib()                           # restore OpenGL attributes
예제 #3
0
 def draw(self, context, render=False):
     if self.image is None:
         return
     bgl.glPushAttrib(bgl.GL_ENABLE_BIT)
     p0 = self.pts[0]
     p1 = self.pts[1]
     bgl.glEnable(bgl.GL_BLEND)
     bgl.glColor4f(*self.colour)
     bgl.glRectf(p0.x, p0.y, p1.x, p1.y)
     self.image.gl_load()
     bgl.glEnable(bgl.GL_BLEND)
     bgl.glBindTexture(bgl.GL_TEXTURE_2D, self.image.bindcode[0])
     bgl.glTexParameteri(bgl.GL_TEXTURE_2D, bgl.GL_TEXTURE_MIN_FILTER, bgl.GL_NEAREST)
     bgl.glTexParameteri(bgl.GL_TEXTURE_2D, bgl.GL_TEXTURE_MAG_FILTER, bgl.GL_NEAREST)
     bgl.glEnable(bgl.GL_TEXTURE_2D)
     bgl.glBlendFunc(bgl.GL_SRC_ALPHA, bgl.GL_ONE_MINUS_SRC_ALPHA)
     # bgl.glColor4f(1, 1, 1, 1)
     bgl.glBegin(bgl.GL_QUADS)
     bgl.glTexCoord2d(0, 0)
     bgl.glVertex2d(p0.x, p0.y)
     bgl.glTexCoord2d(0, 1)
     bgl.glVertex2d(p0.x, p1.y)
     bgl.glTexCoord2d(1, 1)
     bgl.glVertex2d(p1.x, p1.y)
     bgl.glTexCoord2d(1, 0)
     bgl.glVertex2d(p1.x, p0.y)
     bgl.glEnd()
     self.image.gl_free()
     bgl.glDisable(bgl.GL_TEXTURE_2D)
예제 #4
0
    def draw(self, context, render=False):
        """
            render flag when rendering
        """

        # print("draw_line %s" % (type(self).__name__))
        bgl.glPushAttrib(bgl.GL_ENABLE_BIT)
        if self.style == bgl.GL_LINE_STIPPLE:
            bgl.glLineStipple(1, 0x9999)
        bgl.glEnable(self.style)
        bgl.glEnable(bgl.GL_BLEND)
        if render:
            # enable anti-alias on lines
            bgl.glEnable(bgl.GL_LINE_SMOOTH)
        bgl.glColor4f(*self.colour)
        bgl.glLineWidth(self.width)
        if self.closed:
            bgl.glBegin(bgl.GL_LINE_LOOP)
        else:
            bgl.glBegin(bgl.GL_LINE_STRIP)

        for pt in self.pts:
            x, y = self.position_2d_from_coord(context, pt, render)
            bgl.glVertex2f(x, y)
        self._end()
예제 #5
0
 def _start_line(self, colour, width=1):
     bgl.glPushAttrib(bgl.GL_ENABLE_BIT)
     bgl.glEnable(bgl.GL_BLEND)
     bgl.glEnable(bgl.GL_LINE)
     bgl.glColor4f(*colour)
     bgl.glLineWidth(width)
     bgl.glBegin(bgl.GL_LINE_STRIP)
예제 #6
0
    def draw(self):
        context = bpy.context
        scene = context.scene
        view = context.area.spaces.active

        if context.mode != self.last_mode:
            self.last_mode = context.mode
            self.cleanup()

        if view.viewport_shade != 'TEXTURED':
            return

        bgl.glPushAttrib(bgl.GL_CLIENT_ALL_ATTRIB_BITS)
        bgl.glShadeModel(bgl.GL_SMOOTH)

        for obj in context.visible_objects:
            if (obj.type == 'MESH' and
                obj.data.edges and not
                obj.data.polygons and not
                # obj.select and not
                obj == context.edit_object):

                cache = self.obj_cache.get(hash(obj))
                if cache is None:
                    cache = LineObjCache()
                    self.obj_cache[hash(obj)] = cache
                cache.draw(self, obj)

        bgl.glPopAttrib()
예제 #7
0
    def draw_callback_postview(self, context):
        bgl.glPushAttrib(bgl.GL_ALL_ATTRIB_BITS)  # save OpenGL attributes
        self.draw_postview(context)
        if len(self.selectCntrl):
            cntrlLength = len(self.selectCntrl)
            for x in range(0, cntrlLength):
                # assuming that we have only one control point, so if
                # anything is selected it would be the only point
                p111 = self.selectCntrl[x]
                t111 = p111.to_tuple()
                vrot = context.space_data.region_3d.view_rotation
                dx = (vrot * Vector(
                    (1, 0,
                     0))).normalized()  # compute right dir relative to view
                dy = (vrot * Vector(
                    (0, 1, 0))).normalized()  # compute up dir relative to view
                px = tuple(p111 + dx * 0.5)
                py = tuple(p111 + dy * 0.5)

                # highlight the point
                bgl.glColor3f(1, 1, 0)
                bgl.glBegin(bgl.GL_POINTS)
                bgl.glVertex3f(*t111)
                bgl.glEnd()

                # draw lines to indicate right (red) and up (green)
                bgl.glBegin(bgl.GL_LINES)
                bgl.glColor3f(1, 0, 0)
                bgl.glVertex3f(*t111)
                bgl.glVertex3f(*px)
                bgl.glColor3f(0, 1, 0)
                bgl.glVertex3f(*t111)
                bgl.glVertex3f(*py)
                bgl.glEnd()
        bgl.glPopAttrib()  # restore OpenGL attributes
예제 #8
0
 def draw_callback_postpixel(self, context):
     bgl.glPushAttrib(bgl.GL_ALL_ATTRIB_BITS)  # save OpenGL attributes
     try:
         self.draw_postpixel()
     except:
         bricker_handle_exception()
     bgl.glPopAttrib()  # restore OpenGL attributes
def draw_callback_px(self, context):
    #print("callback_px")
    # Maybe print a nice red circle in some corner

    bgl.glPushAttrib(bgl.GL_CLIENT_ALL_ATTRIB_BITS)

    FONT_RGBA = (0.8, 0.1, 0.1, 0.5)
    bgl.glColor4f(*FONT_RGBA)

    font_size = 11
    DPI = 72

    blf.size(0, font_size, DPI)
    msg = "Logging..."
    
    msg_w,msg_h = blf.dimensions(0, msg)

    pos_x = context.region.width - msg_w
    pos_y = font_size / 2
    blf.position(0, pos_x, pos_y, 0)
    #blf.position(0, 10, 10, 0)

    blf.draw(0, msg)

    bgl.glPopAttrib()

    pass
예제 #10
0
파일: test.py 프로젝트: CGCookie/retopoflow
    def draw_postpixel(self):
        bgl.glPushAttrib(bgl.GL_ALL_ATTRIB_BITS)

        bgl.glEnable(bgl.GL_BLEND)

        bgl.glMatrixMode(bgl.GL_MODELVIEW)
        bgl.glPushMatrix()
        bgl.glLoadIdentity()
        bgl.glMatrixMode(bgl.GL_PROJECTION)
        bgl.glPushMatrix()
        bgl.glLoadIdentity()

        bgl.glColor4f(1,0,0,0.2)    # TODO: use window background color??
        bgl.glEnable(bgl.GL_BLEND)
        bgl.glDisable(bgl.GL_DEPTH_TEST)
        bgl.glBegin(bgl.GL_QUADS)   # TODO: not use immediate mode
        bgl.glVertex2f(-1, -1)
        bgl.glVertex2f( 1, -1)
        bgl.glVertex2f( 1,  1)
        bgl.glVertex2f(-1,  1)
        bgl.glEnd()

        bgl.glPopMatrix()
        bgl.glMatrixMode(bgl.GL_MODELVIEW)
        bgl.glPopMatrix()
        bgl.glMatrixMode(bgl.GL_PROJECTION)
        bgl.glPopAttrib()
def crosshairs():
    """
    Show crosshais in Manipulation Mode
    Use the OpenGL-Wrapper to draw the image
    """

    imageHeight = windowHeight * 0.05
    imageWidth = imageHeight

    x = windowWidth * 0.5 - imageWidth / 2
    y = windowHeight * 0.5 - imageHeight / 2

    gl_position = [[x, y], [x + imageWidth, y],
                   [x + imageWidth, y + imageHeight], [x, y + imageHeight]]

    view_buf = bgl.Buffer(bgl.GL_INT, 4)
    bgl.glGetIntegerv(bgl.GL_VIEWPORT, view_buf)
    view = view_buf.to_list() if hasattr(view_buf,
                                         "to_list") else view_buf.list
    # Save the state
    bgl.glPushAttrib(bgl.GL_ALL_ATTRIB_BITS)
    # Disable depth test so we always draw over things
    bgl.glDisable(bgl.GL_DEPTH_TEST)
    # Disable lighting so everything is shadless
    bgl.glDisable(bgl.GL_LIGHTING)
    # Unbinding the texture prevents BGUI frames from somehow picking up on
    # color of the last used texture
    bgl.glBindTexture(bgl.GL_TEXTURE_2D, 0)
    # Make sure we're using smooth shading instead of flat
    bgl.glShadeModel(bgl.GL_SMOOTH)
    # Setup the matrices
    bgl.glMatrixMode(bgl.GL_PROJECTION)
    bgl.glPushMatrix()
    bgl.glLoadIdentity()
    bgl.gluOrtho2D(0, view[2], 0, view[3])
    bgl.glMatrixMode(bgl.GL_MODELVIEW)
    bgl.glPushMatrix()
    bgl.glLoadIdentity()

    bgl.glEnable(bgl.GL_TEXTURE_2D)
    # Enable alpha blending
    bgl.glEnable(bgl.GL_BLEND)
    bgl.glBlendFunc(bgl.GL_SRC_ALPHA, bgl.GL_ONE_MINUS_SRC_ALPHA)
    # Bind the texture
    bgl.glBindTexture(bgl.GL_TEXTURE_2D, crosshairs_id)
    # Draw the textured quad
    bgl.glColor4f(1, 1, 1, 1)
    bgl.glEnable(bgl.GL_POLYGON_OFFSET_FILL)
    bgl.glPolygonOffset(1.0, 1.0)
    bgl.glBegin(bgl.GL_QUADS)
    for i in range(4):
        bgl.glTexCoord2f(texco[i][0], texco[i][1])
        bgl.glVertex2f(gl_position[i][0], gl_position[i][1])
    bgl.glEnd()
    bgl.glBindTexture(bgl.GL_TEXTURE_2D, 0)

    bgl.glPopMatrix()
    bgl.glMatrixMode(bgl.GL_PROJECTION)
    bgl.glPopMatrix()
    bgl.glPopAttrib()
예제 #12
0
파일: test.py 프로젝트: CGCookie/retopoflow
    def draw_preview(self):
        bgl.glPushAttrib(bgl.GL_ALL_ATTRIB_BITS)
        bgl.glMatrixMode(bgl.GL_MODELVIEW)
        bgl.glPushMatrix()
        bgl.glLoadIdentity()
        bgl.glMatrixMode(bgl.GL_PROJECTION)
        bgl.glPushMatrix()
        bgl.glLoadIdentity()

        bgl.glEnable(bgl.GL_BLEND)
        bgl.glDisable(bgl.GL_DEPTH_TEST)

        bgl.glBegin(bgl.GL_QUADS)   # TODO: not use immediate mode
        bgl.glColor4f(0,0,0.2,0.5)
        bgl.glVertex2f(-1, -1)
        bgl.glVertex2f( 1, -1)
        bgl.glColor4f(0,0,0.2,0)
        bgl.glVertex2f( 1,  1)
        bgl.glVertex2f(-1,  1)
        bgl.glEnd()

        bgl.glPopMatrix()
        bgl.glMatrixMode(bgl.GL_MODELVIEW)
        bgl.glPopMatrix()
        bgl.glMatrixMode(bgl.GL_PROJECTION)
        bgl.glPopAttrib()
def draw_callback_px(self, context):
    #print("callback_px")
    # Maybe print a nice red circle in some corner

    bgl.glPushAttrib(bgl.GL_CLIENT_ALL_ATTRIB_BITS)

    FONT_RGBA = (0.8, 0.1, 0.1, 0.5)
    bgl.glColor4f(*FONT_RGBA)

    font_size = 11
    DPI = 72

    blf.size(0, font_size, DPI)
    msg = "Logging..."

    msg_w, msg_h = blf.dimensions(0, msg)

    pos_x = context.region.width - msg_w
    pos_y = font_size / 2
    blf.position(0, pos_x, pos_y, 0)
    #blf.position(0, 10, 10, 0)

    blf.draw(0, msg)

    bgl.glPopAttrib()

    pass
예제 #14
0
 def draw_callback_postview(self, context):
     bgl.glPushAttrib(bgl.GL_ALL_ATTRIB_BITS)    # save OpenGL attributes
     try:
         self.draw_postview(context)
     except:
         self.handle_exception()
     bgl.glPopAttrib()                           # restore OpenGL attributes
예제 #15
0
 def draw_callback_preview(self, context):
     bgl.glPushAttrib(bgl.GL_ALL_ATTRIB_BITS)  # save OpenGL attributes
     try:
         self.draw_preview()
     except:
         interactive_physics_handle_exception()
     bgl.glPopAttrib()  # restore OpenGL attributes
예제 #16
0
def draw_underline_in_strip(strip_coords, pixel_size_x, color):
    from bgl import glColor4f, glRectf, glEnable, glDisable, GL_BLEND
    import bgl

    context = bpy.context

    # Strip coords
    s_x1, s_y1, s_x2, s_y2 = strip_coords

    # be careful not to draw over the current frame line
    cf_x = context.scene.frame_current_final

    bgl.glPushAttrib(bgl.GL_COLOR_BUFFER_BIT | bgl.GL_LINE_BIT)

    glColor4f(*color)
    glEnable(GL_BLEND)
    bgl.glLineWidth(2)
    bgl.glBegin(bgl.GL_LINES)

    bgl.glVertex2f(s_x1, s_y1)
    if s_x1 < cf_x < s_x2:
        # Bad luck, the line passes our strip
        bgl.glVertex2f(cf_x - pixel_size_x, s_y1)
        bgl.glVertex2f(cf_x + pixel_size_x, s_y1)
    bgl.glVertex2f(s_x2, s_y1)

    bgl.glEnd()
    bgl.glPopAttrib()
예제 #17
0
파일: test.py 프로젝트: chuong/cut_mesh
 def draw_postpixel(self):
     bgl.glPushAttrib(bgl.GL_ALL_ATTRIB_BITS)
     
     bgl.glEnable(bgl.GL_BLEND)
     
     bgl.glMatrixMode(bgl.GL_MODELVIEW)
     bgl.glPushMatrix()
     bgl.glLoadIdentity()
     bgl.glMatrixMode(bgl.GL_PROJECTION)
     bgl.glPushMatrix()
     bgl.glLoadIdentity()
     
     bgl.glColor4f(1,0,0,0.2)    # TODO: use window background color??
     bgl.glEnable(bgl.GL_BLEND)
     bgl.glDisable(bgl.GL_DEPTH_TEST)
     bgl.glBegin(bgl.GL_QUADS)   # TODO: not use immediate mode
     bgl.glVertex2f(-1, -1)
     bgl.glVertex2f( 1, -1)
     bgl.glVertex2f( 1,  1)
     bgl.glVertex2f(-1,  1)
     bgl.glEnd()
     
     bgl.glPopMatrix()
     bgl.glMatrixMode(bgl.GL_MODELVIEW)
     bgl.glPopMatrix()
     bgl.glMatrixMode(bgl.GL_PROJECTION)
     bgl.glPopAttrib()
예제 #18
0
파일: test.py 프로젝트: chuong/cut_mesh
 def draw_preview(self):
     bgl.glPushAttrib(bgl.GL_ALL_ATTRIB_BITS)
     bgl.glMatrixMode(bgl.GL_MODELVIEW)
     bgl.glPushMatrix()
     bgl.glLoadIdentity()
     bgl.glMatrixMode(bgl.GL_PROJECTION)
     bgl.glPushMatrix()
     bgl.glLoadIdentity()
     
     bgl.glEnable(bgl.GL_BLEND)
     bgl.glDisable(bgl.GL_DEPTH_TEST)
     
     bgl.glBegin(bgl.GL_QUADS)   # TODO: not use immediate mode
     bgl.glColor4f(0,0,0.2,0.5)
     bgl.glVertex2f(-1, -1)
     bgl.glVertex2f( 1, -1)
     bgl.glColor4f(0,0,0.2,0)
     bgl.glVertex2f( 1,  1)
     bgl.glVertex2f(-1,  1)
     bgl.glEnd()
     
     bgl.glPopMatrix()
     bgl.glMatrixMode(bgl.GL_MODELVIEW)
     bgl.glPopMatrix()
     bgl.glMatrixMode(bgl.GL_PROJECTION)
     bgl.glPopAttrib()
    def draw_viewport_2d(self, context):
        bgl.glPushAttrib(
            bgl.GL_DEPTH_BUFFER_BIT |
            bgl.GL_LINE_BIT |
            bgl.GL_COLOR_BUFFER_BIT |
            bgl.GL_CURRENT_BIT)

        bgl.glEnable(bgl.GL_BLEND)
        bgl.glDepthFunc(bgl.GL_ALWAYS)
        bgl.glLineWidth(1)

        if self.started:
            ax, ay = self.mouse_a
            bx, by = self.mouse_b

            bgl.glBegin(bgl.GL_LINES)

            bgl.glColor4f(0, 0, 0, 1)
            bgl.glVertex2f(ax + 1, ay)
            bgl.glVertex2f(bx + 1, by)
            bgl.glVertex2f(ax - 1, ay)
            bgl.glVertex2f(bx - 1, by)
            bgl.glVertex2f(ax, ay + 1)
            bgl.glVertex2f(bx, by + 1)
            bgl.glVertex2f(ax, ay - 1)
            bgl.glVertex2f(bx, by - 1)

            bgl.glColor4f(1, 1, 1, 1)
            bgl.glVertex2f(ax, ay)
            bgl.glVertex2f(bx, by)

            bgl.glEnd()

        mx, my = self.mouse_now
        my -= 16

        bgl.glBegin(bgl.GL_QUADS)
        bgl.glColor3f(0, 0, 0)
        bgl.glVertex2f(mx - 9, my - 8)
        bgl.glVertex2f(mx, my + 1)
        bgl.glVertex2f(mx + 9, my - 8)
        bgl.glVertex2f(mx, my - 17)
        bgl.glEnd()

        bgl.glBegin(bgl.GL_TRIANGLES)
        bgl.glColor3f(*self.color_a)
        bgl.glVertex2f(mx - 8, my - 8)
        bgl.glVertex2f(mx, my)
        bgl.glVertex2f(mx, my - 16)
        bgl.glEnd()

        bgl.glBegin(bgl.GL_TRIANGLES)
        bgl.glColor3f(*self.color_b)
        bgl.glVertex2f(mx, my)
        bgl.glVertex2f(mx + 8, my - 8)
        bgl.glVertex2f(mx, my - 16)
        bgl.glEnd()

        bgl.glPopAttrib();
예제 #20
0
 def _start_line(self, colour, width=2, style=bgl.GL_LINE_STIPPLE):
     bgl.glPushAttrib(bgl.GL_ENABLE_BIT)
     bgl.glLineStipple(1, 0x9999)
     bgl.glEnable(style)
     bgl.glEnable(bgl.GL_BLEND)
     bgl.glColor4f(*colour)
     bgl.glLineWidth(width)
     bgl.glBegin(bgl.GL_LINE_STRIP)
    def draw_callback_postview(self, context):
        bgl.glPushAttrib(bgl.GL_ALL_ATTRIB_BITS)    # save OpenGL attributes

        if self.sublvl > 0:
            self.draw_postview(context, self.submesh, False)
        self.draw_postview(context, self.mesh, True)

        bgl.glPopAttrib()                           # restore OpenGL attributes
 def _start_line(self, colour, width=2, style=bgl.GL_LINE_STIPPLE):
     bgl.glPushAttrib(bgl.GL_ENABLE_BIT)
     bgl.glLineStipple(1, 0x9999)
     bgl.glEnable(style)
     bgl.glEnable(bgl.GL_BLEND)
     bgl.glColor4f(*colour)
     bgl.glLineWidth(width)
     bgl.glBegin(bgl.GL_LINE_STRIP)
    def draw_callback_postview(self, context):
        bgl.glPushAttrib(bgl.GL_ALL_ATTRIB_BITS)  # save OpenGL attributes

        if self.sublvl > 0:
            self.draw_postview(context, self.submesh, False)
        self.draw_postview(context, self.mesh, True)

        bgl.glPopAttrib()  # restore OpenGL attributes
예제 #24
0
 def draw_callback_postpixel(self, context):
     if not registered_check(): return
     bgl.glPushAttrib(bgl.GL_ALL_ATTRIB_BITS)  # save OpenGL attributes
     try:
         self.draw_postpixel(context)
     except:
         self.handle_exception()
     bgl.glPopAttrib()  # restore OpenGL attributes
예제 #25
0
def crosshairs():
    """
    Show crosshais in Manipulation Mode
    Use the OpenGL-Wrapper to draw the image
    """
    
    imageHeight = windowHeight * 0.05
    imageWidth = imageHeight

    x = windowWidth * 0.5 - imageWidth/2
    y = windowHeight * 0.5 - imageHeight/2
    
    gl_position = [[x, y],[x+imageWidth, y],[x+imageWidth, y+imageHeight],[x, y+imageHeight]]
    
    view_buf = bgl.Buffer(bgl.GL_INT, 4)
    bgl.glGetIntegerv(bgl.GL_VIEWPORT, view_buf)
    view = view_buf.to_list() if hasattr(view_buf, "to_list") else view_buf.list
    # Save the state
    bgl.glPushAttrib(bgl.GL_ALL_ATTRIB_BITS)      
    # Disable depth test so we always draw over things
    bgl.glDisable(bgl.GL_DEPTH_TEST)   
    # Disable lighting so everything is shadless
    bgl.glDisable(bgl.GL_LIGHTING)   
    # Unbinding the texture prevents BGUI frames from somehow picking up on
    # color of the last used texture
    bgl.glBindTexture(bgl.GL_TEXTURE_2D, 0)      
    # Make sure we're using smooth shading instead of flat
    bgl.glShadeModel(bgl.GL_SMOOTH)
    # Setup the matrices
    bgl.glMatrixMode(bgl.GL_PROJECTION)
    bgl.glPushMatrix()
    bgl.glLoadIdentity()
    bgl.gluOrtho2D(0, view[2], 0, view[3])
    bgl.glMatrixMode(bgl.GL_MODELVIEW)
    bgl.glPushMatrix()
    bgl.glLoadIdentity()
    
    bgl.glEnable(bgl.GL_TEXTURE_2D)
    # Enable alpha blending
    bgl.glEnable(bgl.GL_BLEND)
    bgl.glBlendFunc(bgl.GL_SRC_ALPHA, bgl.GL_ONE_MINUS_SRC_ALPHA)
    # Bind the texture
    bgl.glBindTexture(bgl.GL_TEXTURE_2D, crosshairs_id)
    # Draw the textured quad
    bgl.glColor4f(1, 1, 1, 1)
    bgl.glEnable(bgl.GL_POLYGON_OFFSET_FILL)
    bgl.glPolygonOffset(1.0, 1.0)
    bgl.glBegin(bgl.GL_QUADS)
    for i in range(4):
       bgl.glTexCoord2f(texco[i][0], texco[i][1])
       bgl.glVertex2f(gl_position[i][0], gl_position[i][1])
    bgl.glEnd()
    bgl.glBindTexture(bgl.GL_TEXTURE_2D, 0)

    bgl.glPopMatrix()
    bgl.glMatrixMode(bgl.GL_PROJECTION)
    bgl.glPopMatrix()
    bgl.glPopAttrib()
 def Polygon(self, pts, colour):
     bgl.glPushAttrib(bgl.GL_ENABLE_BIT)
     bgl.glEnable(bgl.GL_BLEND)
     bgl.glColor4f(*colour)
     bgl.glBegin(bgl.GL_POLYGON)
     for pt in pts:
         x, y = pt
         bgl.glVertex2f(x, y)
     self._end()
예제 #27
0
 def draw_callback_postpixel(self, context):
     bgl.glPushAttrib(bgl.GL_ALL_ATTRIB_BITS)    # save OpenGL attributes
     try:
         self.draw_postpixel(context)
     except:
         self.handle_exception()
     if self.settings.show_help and self.help_box:
         self.help_box.draw()
     bgl.glPopAttrib()                           # restore OpenGL attributes
예제 #28
0
 def Polygon(self, pts, colour):
     bgl.glPushAttrib(bgl.GL_ENABLE_BIT)
     bgl.glEnable(bgl.GL_BLEND)
     bgl.glColor4f(*colour)
     bgl.glBegin(bgl.GL_POLYGON)
     for pt in pts:
         x, y = pt
         bgl.glVertex2f(x, y)
     self._end()
예제 #29
0
 def draw_callback_postpixel(self, context):
     bgl.glPushAttrib(bgl.GL_ALL_ATTRIB_BITS)    # save OpenGL attributes
     try:
         self.draw_postpixel(context)
     except:
         self.handle_exception()
     if self.settings.show_help and self.help_box:
         self.help_box.draw()
     bgl.glPopAttrib()                           # restore OpenGL attributes
def draw_callback_px(self, context):

    bgl.glPushAttrib(bgl.GL_ENABLE_BIT)
    # glPushAttrib is done to return everything to normal after drawing

    bgl.glLineStipple(10, 0x9999)
    bgl.glEnable(bgl.GL_LINE_STIPPLE)

    # 50% alpha, 2 pixel width line
    bgl.glEnable(bgl.GL_BLEND)
    bgl.glColor4f(1.0, 1.0, 1.0, 0.8)
    bgl.glLineWidth(5)

    bgl.glBegin(bgl.GL_LINE_STRIP)
    for x, y in self.mouse_path:
        bgl.glVertex2i(x, y)

    bgl.glEnd()
    bgl.glPopAttrib()

    bgl.glEnable(bgl.GL_BLEND)

    # ...api_current/bpy.types.Area.html?highlight=bpy.types.area
    header_height = context.area.regions[0].height # 26px
    width = context.area.width
    height = context.area.height - header_height

    p1_2d = (0,0)
    p2_2d = (width, height)
    p3_2d = (width, 0)
    p4_2d = (0, height)

    # green line
    bgl.glLineWidth(3)

    draw_line_2d((0.0, 1.0, 0.0, 0.8), p1_2d, p2_2d)

    # yellow line
    bgl.glLineWidth(5)
    draw_line_2d((1.0, 1.0, 0.0, 0.8), p3_2d, p4_2d) 

    # white circle
    bgl.glLineWidth(4)
    draw_circle_2d((1.0, 1.0, 1.0, 0.8), width/2, height/2, 70, 360)

    # red circle
    bgl.glLineWidth(5)
    draw_circle_2d((1.0, 0.0, 0.0, 0.4), width/2, height/2, 230, 5)

    # draw text
    draw_typo_2d((1.0, 1.0, 1.0, 1), "Hello Word " + str(len(self.mouse_path)))

    # restore opengl defaults
    bgl.glLineWidth(1)
    bgl.glDisable(bgl.GL_BLEND)
    bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
예제 #31
0
def draw_callback_px(self, context):

    bgl.glPushAttrib(bgl.GL_ENABLE_BIT)
    # glPushAttrib is done to return everything to normal after drawing

    bgl.glLineStipple(10, 0x9999)
    bgl.glEnable(bgl.GL_LINE_STIPPLE)

    # 50% alpha, 2 pixel width line
    bgl.glEnable(bgl.GL_BLEND)
    bgl.glColor4f(1.0, 1.0, 1.0, 0.8)
    bgl.glLineWidth(5)

    bgl.glBegin(bgl.GL_LINE_STRIP)
    for x, y in self.mouse_path:
        bgl.glVertex2i(x, y)

    bgl.glEnd()
    bgl.glPopAttrib()

    bgl.glEnable(bgl.GL_BLEND)

    # ...api_current/bpy.types.Area.html?highlight=bpy.types.area
    header_height = context.area.regions[0].height  # 26px
    width = context.area.width
    height = context.area.height - header_height

    p1_2d = (0, 0)
    p2_2d = (width, height)
    p3_2d = (width, 0)
    p4_2d = (0, height)

    # green line
    bgl.glLineWidth(3)

    draw_line_2d((0.0, 1.0, 0.0, 0.8), p1_2d, p2_2d)

    # yellow line
    bgl.glLineWidth(5)
    draw_line_2d((1.0, 1.0, 0.0, 0.8), p3_2d, p4_2d)

    # white circle
    bgl.glLineWidth(4)
    draw_circle_2d((1.0, 1.0, 1.0, 0.8), width / 2, height / 2, 70, 360)

    # red circle
    bgl.glLineWidth(5)
    draw_circle_2d((1.0, 0.0, 0.0, 0.4), width / 2, height / 2, 230, 5)

    # draw text
    draw_typo_2d((1.0, 1.0, 1.0, 1), "Hello Word " + str(len(self.mouse_path)))

    # restore opengl defaults
    bgl.glLineWidth(1)
    bgl.glDisable(bgl.GL_BLEND)
    bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
예제 #32
0
파일: vagl.py 프로젝트: JT-a/blenderpython
 def push(self, mask=bgl.GL_ALL_ATTRIB_BITS):
     """glPushAttrib()で状態変数を保存しておく。
     glPushMatrix(), glPopMatrix() は GL_MAX_MODELVIEW_STACK_DEPTH が 32
     なのに対し、GL_MAX_PROJECTION_STACK_DEPTH が 4 しか無い為、使用しない。
     """
     bgl.glPushAttrib(mask)
     self._modelview_stack.append(
         Buffer('double', (4, 4), bgl.GL_MODELVIEW_MATRIX))
     self._projection_stack.append(
         Buffer('double', (4, 4), bgl.GL_PROJECTION_MATRIX))
예제 #33
0
 def push(self, mask=bgl.GL_ALL_ATTRIB_BITS):
     """glPushAttrib()で状態変数を保存しておく。
     glPushMatrix(), glPopMatrix() は GL_MAX_MODELVIEW_STACK_DEPTH が 32
     なのに対し、GL_MAX_PROJECTION_STACK_DEPTH が 4 しか無い為、使用しない。
     """
     bgl.glPushAttrib(mask)
     self._modelview_stack.append(
         Buffer('double', (4, 4), bgl.GL_MODELVIEW_MATRIX))
     self._projection_stack.append(
         Buffer('double', (4, 4), bgl.GL_PROJECTION_MATRIX))
예제 #34
0
 def draw_callback_postview(self, context):
     if not still_registered(self): return
     self.drawing.update_dpi()
     self.drawing.set_font_size(12, force=True)
     self.drawing.point_size(1)
     self.drawing.line_width(1)
     bgl.glPushAttrib(bgl.GL_ALL_ATTRIB_BITS)    # save OpenGL attributes
     try:    self.rfctx.draw_postview()
     except: self.handle_exception()
     bgl.glPopAttrib()                           # restore OpenGL attributes
 def _start_line(self, colour, width=2, style=None):
     if style is None:
         # NOTE: this is no longer supported in Blender3.0.
         # style = bgl.GL_LINE_STIPPLE
         style = bgl.GL_LINE
     bgl.glPushAttrib(bgl.GL_ENABLE_BIT)
     bgl.glLineStipple(1, 0x9999)
     bgl.glEnable(style)
     bgl.glEnable(bgl.GL_BLEND)
     bgl.glColor4f(*colour)
     bgl.glLineWidth(width)
     bgl.glBegin(bgl.GL_LINE_STRIP)
예제 #36
0
 def draw_callback_postview(self, context):
     if not still_registered(self): return
     self.drawing.update_dpi()
     self.drawing.set_font_size(12, force=True)
     self.drawing.point_size(1)
     self.drawing.line_width(1)
     bgl.glPushAttrib(bgl.GL_ALL_ATTRIB_BITS)  # save OpenGL attributes
     try:
         self.rfctx.draw_postview()
     except:
         self.handle_exception()
     bgl.glPopAttrib()  # restore OpenGL attributes
예제 #37
0
    def draw3d(self):
        '''描画を行う(3次元)'''
        if (self.fwScene is None) or (self.fwScene.GetPHScene() is None):
            return

        # --- <!!> ---
        if bpy.context.scene.spr_debug_draw_enabled == 1:
            render = spbapi_cpp.GetGRRender()
            if not render is None:
                bgl.glPushAttrib(bgl.GL_ALL_ATTRIB_BITS)
                self.fwScene.DrawPHScene(render)
                bgl.glPopAttrib()
예제 #38
0
 def draw(self, context, render=False):
     self.render = render
     bgl.glPushAttrib(bgl.GL_ENABLE_BIT)
     bgl.glEnable(bgl.GL_BLEND)
     if render:
         # enable anti-alias on polygons
         bgl.glEnable(bgl.GL_POLYGON_SMOOTH)
     bgl.glColor4f(*self.colour)
     p0 = self.pts[0]
     p1 = self.pts[1]
     bgl.glRectf(p0.x, p0.y, p1.x, p1.y)
     self._end()
예제 #39
0
    def draw(self, context, render=False):

        self.render = render
        bgl.glPushAttrib(bgl.GL_ENABLE_BIT)
        bgl.glEnable(bgl.GL_BLEND)
        if render:
            # enable anti-alias on polygons
            bgl.glEnable(bgl.GL_POLYGON_SMOOTH)
        bgl.glColor4f(*self.colour)
        p0 = self.pts[0]
        p1 = self.pts[1]
        bgl.glRectf(p0.x, p0.y, p1.x, p1.y)
        self._end()
def color_placing():
    """
    Draw the green rectangle via OpenGL-Wrapper
    """
    imageHeight = windowHeight * 0.05
    imageWidth = imageHeight

    x = windowWidth * 0.5 - imageWidth / 2
    y = windowHeight * 0.5 - imageHeight / 2

    gl_position = [[x, y], [x + imageWidth, y],
                   [x + imageWidth, y + imageHeight], [x, y + imageHeight]]

    view_buf = bgl.Buffer(bgl.GL_INT, 4)
    bgl.glGetIntegerv(bgl.GL_VIEWPORT, view_buf)
    view = view_buf.to_list() if hasattr(view_buf,
                                         "to_list") else view_buf.list
    # Save the state
    bgl.glPushAttrib(bgl.GL_ALL_ATTRIB_BITS)
    # Disable depth test so we always draw over things
    bgl.glDisable(bgl.GL_DEPTH_TEST)
    # Disable lighting so everything is shadless
    bgl.glDisable(bgl.GL_LIGHTING)
    # Make sure we're using smooth shading instead of flat
    bgl.glShadeModel(bgl.GL_SMOOTH)
    # Setup the matrices
    bgl.glMatrixMode(bgl.GL_PROJECTION)
    bgl.glPushMatrix()
    bgl.glLoadIdentity()
    bgl.gluOrtho2D(0, view[2], 0, view[3])
    bgl.glMatrixMode(bgl.GL_MODELVIEW)
    bgl.glPushMatrix()
    bgl.glLoadIdentity()

    # Enable alpha blending
    bgl.glEnable(bgl.GL_BLEND)
    bgl.glBlendFunc(bgl.GL_SRC_ALPHA, bgl.GL_ONE_MINUS_SRC_ALPHA)
    # Draw the colored quad
    bgl.glColor4f(0, 1, 0, 0.25)
    bgl.glEnable(bgl.GL_POLYGON_OFFSET_FILL)
    bgl.glPolygonOffset(1.0, 1.0)
    bgl.glBegin(bgl.GL_QUADS)
    for i in range(4):
        bgl.glTexCoord2f(texco[i][0], texco[i][1])
        bgl.glVertex2f(gl_position[i][0], gl_position[i][1])
    bgl.glEnd()

    bgl.glPopMatrix()
    bgl.glMatrixMode(bgl.GL_PROJECTION)
    bgl.glPopMatrix()
    bgl.glPopAttrib()
예제 #41
0
    def push_attrib(cls, mask=bgl.GL_ALL_ATTRIB_BITS, matrix=True):
        """with文で使用する。
        with GLSettings.push_attrib():
            ...
        :rtype: GCM
        """

        bgl.glPushAttrib(mask)
        modelview = Buffer('double', (4, 4), bgl.GL_MODELVIEW_MATRIX)
        projection = Buffer('double', (4, 4), bgl.GL_PROJECTION_MATRIX)
        yield
        if matrix:
            cls._load_matrix(modelview, projection)
        bgl.glPopAttrib()
예제 #42
0
def color_placing():
    """
    Draw the green rectangle via OpenGL-Wrapper
    """
    imageHeight = windowHeight * 0.05
    imageWidth = imageHeight

    x = windowWidth * 0.5 - imageWidth/2
    y = windowHeight * 0.5 - imageHeight/2
    
    gl_position = [[x, y],[x+imageWidth, y],[x+imageWidth, y+imageHeight],[x, y+imageHeight]]
    
    view_buf = bgl.Buffer(bgl.GL_INT, 4)
    bgl.glGetIntegerv(bgl.GL_VIEWPORT, view_buf)
    view = view_buf.to_list() if hasattr(view_buf, "to_list") else view_buf.list
    # Save the state
    bgl.glPushAttrib(bgl.GL_ALL_ATTRIB_BITS)      
    # Disable depth test so we always draw over things
    bgl.glDisable(bgl.GL_DEPTH_TEST)   
    # Disable lighting so everything is shadless
    bgl.glDisable(bgl.GL_LIGHTING)   
    # Make sure we're using smooth shading instead of flat
    bgl.glShadeModel(bgl.GL_SMOOTH)
    # Setup the matrices
    bgl.glMatrixMode(bgl.GL_PROJECTION)
    bgl.glPushMatrix()
    bgl.glLoadIdentity()
    bgl.gluOrtho2D(0, view[2], 0, view[3])
    bgl.glMatrixMode(bgl.GL_MODELVIEW)
    bgl.glPushMatrix()
    bgl.glLoadIdentity()
    
    
    # Enable alpha blending
    bgl.glEnable(bgl.GL_BLEND)
    bgl.glBlendFunc(bgl.GL_SRC_ALPHA, bgl.GL_ONE_MINUS_SRC_ALPHA)
    # Draw the colored quad
    bgl.glColor4f(0, 1, 0, 0.25)
    bgl.glEnable(bgl.GL_POLYGON_OFFSET_FILL)
    bgl.glPolygonOffset(1.0, 1.0)
    bgl.glBegin(bgl.GL_QUADS)
    for i in range(4):
       bgl.glTexCoord2f(texco[i][0], texco[i][1])
       bgl.glVertex2f(gl_position[i][0], gl_position[i][1])
    bgl.glEnd()

    bgl.glPopMatrix()
    bgl.glMatrixMode(bgl.GL_PROJECTION)
    bgl.glPopMatrix()
    bgl.glPopAttrib()
예제 #43
0
 def draw_callback_postpixel(self, context):
     if not still_registered(self): return
     self.drawing.update_dpi()
     self.drawing.set_font_size(12, force=True)
     self.drawing.point_size(1)
     self.drawing.line_width(1)
     bgl.glPushAttrib(bgl.GL_ALL_ATTRIB_BITS)  # save OpenGL attributes
     try:
         self.rfctx.draw_postpixel()
     except:
         dprint('Exception in draw_postpixel')
         self.handle_exception()
     #if self.settings.show_help and self.help_box: self.help_box.draw()
     bgl.glPopAttrib()  # restore OpenGL attributes
예제 #44
0
    def push_attrib(cls, mask=bgl.GL_ALL_ATTRIB_BITS, matrix=True):
        """with文で使用する。
        with GLSettings.push_attrib():
            ...
        :rtype: GCM
        """

        bgl.glPushAttrib(mask)
        modelview = Buffer('double', (4, 4), bgl.GL_MODELVIEW_MATRIX)
        projection = Buffer('double', (4, 4), bgl.GL_PROJECTION_MATRIX)
        yield
        if matrix:
            cls._load_matrix(modelview, projection)
        bgl.glPopAttrib()
예제 #45
0
 def draw_callback_postpixel(self, context):
     if not still_registered(self): return
     self.drawing.update_dpi()
     self.drawing.set_font_size(12, force=True)
     self.drawing.point_size(1)
     self.drawing.line_width(1)
     bgl.glPushAttrib(bgl.GL_ALL_ATTRIB_BITS)    # save OpenGL attributes
     try:
         self.rfctx.draw_postpixel()
     except:
         dprint('Exception in draw_postpixel')
         self.handle_exception()
     #if self.settings.show_help and self.help_box: self.help_box.draw()
     bgl.glPopAttrib()                           # restore OpenGL attributes
예제 #46
0
 def _cc_region_draw_cover(self, a):
     bgl.glPushAttrib(bgl.GL_ALL_ATTRIB_BITS)
     bgl.glMatrixMode(bgl.GL_PROJECTION)
     bgl.glPushMatrix()
     bgl.glLoadIdentity()
     bgl.glColor4f(0, 0, 0, 0.5)  # TODO: use window background color??
     bgl.glEnable(bgl.GL_BLEND)
     bgl.glDisable(bgl.GL_DEPTH_TEST)
     bgl.glBegin(bgl.GL_QUADS)  # TODO: not use immediate mode
     bgl.glVertex2f(-1, -1)
     bgl.glVertex2f(1, -1)
     bgl.glVertex2f(1, 1)
     bgl.glVertex2f(-1, 1)
     bgl.glEnd()
     bgl.glPopMatrix()
     bgl.glPopAttrib()
예제 #47
0
def draw_callback_px(context):
    # Note that the "context" passed in here is a regular dictionary and not the Blender context
    global screen_display_lines
    pid = None
    if 'mcell' in bpy.context.scene:
        mcell = bpy.context.scene.mcell
        if 'run_simulation' in mcell:
            rs = mcell.run_simulation
            if len(rs.processes_list) > 0:
                pid_str = rs.processes_list[rs.active_process_index].name
                pid = pid_str.split(',')[0].split()[1]

    bgl.glPushAttrib(bgl.GL_ENABLE_BIT)

    if parameter_dictionary['Clear']['val']:
        bgl.glClearColor(0.0, 0.0, 0.0, 1.0)
        bgl.glClear(bgl.GL_COLOR_BUFFER_BIT)

    font_id = 0  # XXX, need to find out how best to get this.

    y_pos = 15 * (scroll_offset + 1)
    if pid and (pid in screen_display_lines):
        for l in screen_display_lines[pid]:
            blf.position(font_id, 15, y_pos, 0)
            y_pos += 15
            blf.size(font_id, 14, 72)  # fontid, size, DPI
            bgl.glColor4f(1.0, 1.0, 1.0, 0.5)
            blf.draw(font_id, l)
    else:
        keys = screen_display_lines.keys()
        for k in keys:
            for l in screen_display_lines[k]:
                blf.position(font_id, 15, y_pos, 0)
                y_pos += 15
                blf.size(font_id, 14, 72)  # fontid, size, DPI
                bgl.glColor4f(1.0, 1.0, 1.0, 0.5)
                blf.draw(font_id, l)

    # 100% alpha, 2 pixel width line
    bgl.glEnable(bgl.GL_BLEND)

    bgl.glPopAttrib()

    # restore opengl defaults
    bgl.glLineWidth(1)
    bgl.glDisable(bgl.GL_BLEND)
    bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
예제 #48
0
 def draw_callback_cover(self, context):
     if not still_registered(self): return
     bgl.glPushAttrib(bgl.GL_ALL_ATTRIB_BITS)
     bgl.glMatrixMode(bgl.GL_PROJECTION)
     bgl.glPushMatrix()
     bgl.glLoadIdentity()
     bgl.glColor4f(0,0,0,0.5)    # TODO: use window background color??
     bgl.glEnable(bgl.GL_BLEND)
     bgl.glDisable(bgl.GL_DEPTH_TEST)
     bgl.glBegin(bgl.GL_QUADS)   # TODO: not use immediate mode
     bgl.glVertex2f(-1, -1)
     bgl.glVertex2f( 1, -1)
     bgl.glVertex2f( 1,  1)
     bgl.glVertex2f(-1,  1)
     bgl.glEnd()
     bgl.glPopMatrix()
     bgl.glPopAttrib()
예제 #49
0
    def draw(self, context, render=False):
        """
            render flag when rendering
        """

        # print("draw_polygon")
        self.render = render
        bgl.glPushAttrib(bgl.GL_ENABLE_BIT)
        bgl.glEnable(bgl.GL_BLEND)
        if render:
            # enable anti-alias on polygons
            bgl.glEnable(bgl.GL_POLYGON_SMOOTH)
        bgl.glColor4f(*self.colour)
        bgl.glBegin(bgl.GL_POLYGON)

        for pt in self.pts:
            x, y = self.position_2d_from_coord(context, pt, render)
            bgl.glVertex2f(x, y)
        self._end()
    def draw_action_header_text(self, x, y, speaker, action, margin=4):
        bgl.glPushAttrib(bgl.GL_COLOR_BUFFER_BIT | bgl.GL_ENABLE_BIT)
        font_id = 0
        x = x + margin
        y = y + margin
        # bgl.glEnable(bgl.GL_BLEND)
        bgl.glColor4f(1.0, 1.0, 1.0, 1.0)
        blf.size(font_id, 16, 64)
        blf.position(font_id, x, y, 0.0)
        baking = ""
        if bpy.types.BakeSoundPanel.baking:
            baking = "(BAKING....)"

        s = "[%s] %s %s" % (action["channel_name"], action.name, baking)
        blf.draw(font_id, s)
        blf.size(font_id, 20, 36)
        blf.position(font_id, x + 10 * len(s), y, 0.0)
        blf.draw(font_id, action["wavfile"])
        bgl.glPopAttrib()
def draw_callback_px(self, context):
    bgl.glPushAttrib(bgl.GL_CLIENT_ALL_ATTRIB_BITS)

    FONT_RGBA = (0.8, 0.1, 0.1, 0.5)
    bgl.glColor4f(*FONT_RGBA)

    font_size = 11
    DPI = 72

    blf.size(0, font_size, DPI)
    msg = "Head Camera on..."
    
    msg_w,msg_h = blf.dimensions(0, msg)

    pos_x = context.region.width - msg_w
    pos_y = font_size / 2
    blf.position(0, pos_x, pos_y, 0)
    #blf.position(0, 10, 10, 0)

    blf.draw(0, msg)

    bgl.glPopAttrib()

    pass
예제 #52
0
def status_image():
    """
    Show the corrensponding Image for the status
    """
    imageHeight = windowHeight * 0.075
    imageWidth = imageHeight

    x = windowWidth * 0.35 - imageWidth/2
    y = windowHeight * 0.45 - imageHeight/2
    
    gl_position = [[x, y],[x+imageWidth, y],[x+imageWidth, y+imageHeight],[x, y+imageHeight]]

    cam = logic.getCurrentScene().active_camera

    # get the suffix of the human to reference the right objects
    suffix = cam.name[-4:] if cam.name[-4] == "." else ""

    hand = objects['Hand_Grab.R' + suffix]

    # select the right Image
    if hand["selected"]:
        tex_id = closed_id
    else:
        tex_id = open_id

    
    view_buf = bgl.Buffer(bgl.GL_INT, 4)
    bgl.glGetIntegerv(bgl.GL_VIEWPORT, view_buf)
    view = view_buf.to_list() if hasattr(view_buf, "to_list") else view_buf.list
    # Save the state
    bgl.glPushAttrib(bgl.GL_ALL_ATTRIB_BITS)      
    # Disable depth test so we always draw over things
    bgl.glDisable(bgl.GL_DEPTH_TEST)   
    # Disable lighting so everything is shadless
    bgl.glDisable(bgl.GL_LIGHTING)   
    # Unbinding the texture prevents BGUI frames from somehow picking up on
    # color of the last used texture
    bgl.glBindTexture(bgl.GL_TEXTURE_2D, 0)      
    # Make sure we're using smooth shading instead of flat
    bgl.glShadeModel(bgl.GL_SMOOTH)
    # Setup the matrices
    bgl.glMatrixMode(bgl.GL_PROJECTION)
    bgl.glPushMatrix()
    bgl.glLoadIdentity()
    bgl.gluOrtho2D(0, view[2], 0, view[3])
    bgl.glMatrixMode(bgl.GL_MODELVIEW)
    bgl.glPushMatrix()
    bgl.glLoadIdentity()
    
    
    bgl.glEnable(bgl.GL_TEXTURE_2D)
    # Enable alpha blending
    bgl.glEnable(bgl.GL_BLEND)
    bgl.glBlendFunc(bgl.GL_SRC_ALPHA, bgl.GL_ONE_MINUS_SRC_ALPHA)
    # Bind the texture
    bgl.glBindTexture(bgl.GL_TEXTURE_2D, tex_id)
    # Draw the textured quad
    bgl.glColor4f(1, 1, 1, 1)
    bgl.glEnable(bgl.GL_POLYGON_OFFSET_FILL)
    bgl.glPolygonOffset(1.0, 1.0)
    bgl.glBegin(bgl.GL_QUADS)
    for i in range(4):
       bgl.glTexCoord2f(texco[i][0], texco[i][1])
       bgl.glVertex2f(gl_position[i][0], gl_position[i][1])
    bgl.glEnd()
    bgl.glBindTexture(bgl.GL_TEXTURE_2D, 0)

    bgl.glPopMatrix()
    bgl.glMatrixMode(bgl.GL_PROJECTION)
    bgl.glPopMatrix()
    bgl.glPopAttrib()
예제 #53
0
	def draw(self):
		cam = bge.logic.getCurrentScene().active_camera
		
		self.position[2] += self.speed
		
		# Get some viewport info
		view_buf = bgl.Buffer(bgl.GL_INT, 4)
		bgl.glGetIntegerv(bgl.GL_VIEWPORT, view_buf)
		view = view_buf[:]

		if 0:
			# Save the state
			bgl.glPushAttrib(bgl.GL_ALL_ATTRIB_BITS)

			# Disable depth test so we always draw over things
			bgl.glDisable(bgl.GL_DEPTH_TEST)

			# Disable lighting so everything is shadless
			bgl.glDisable(bgl.GL_LIGHTING)

			# Unbinding the texture prevents BGUI frames from somehow picking up on
			# color of the last used texture
			bgl.glBindTexture(bgl.GL_TEXTURE_2D, 0)

			# Make sure we're using smooth shading instead of flat
			bgl.glShadeModel(bgl.GL_SMOOTH)


		# Calculate x and y
		screen_coord = cam.getScreenPosition(self.position)
		x = screen_coord[0] * ras.getWindowWidth()
		y = ras.getWindowHeight() - (screen_coord[1] * ras.getWindowHeight())
		
		# Check to make sure the position isn't behind the camera
		if not cam.pointInsideFrustum(self.position):
			return
	
		# Calculate scale
		distance = cam.getDistanceTo(self.position)
		if 1000 - distance > 0:
			scale = (1000 - distance) / 1000
		else:
			scale = 0

		# Setup the matrices
		bgl.glMatrixMode(bgl.GL_PROJECTION)
		bgl.glPushMatrix()
		bgl.glLoadIdentity()
		bgl.gluOrtho2D(0, view[2], 0, view[3])
		bgl.glMatrixMode(bgl.GL_MODELVIEW)
		bgl.glPushMatrix()
		bgl.glLoadIdentity()
		
		# Center the x
		text_width, text_height = blf.dimensions(self.fontid, self.text)
		x -= text_width / 2

			
		# Draw the font if large enough
		if scale:
			blf.size(self.fontid, int(self.pt_size*scale), 72)
			blf.position(self.fontid, x, y, 0)
			blf.draw(self.fontid, self.text)
			
		# Reset the state
		bgl.glPopMatrix()
		bgl.glMatrixMode(bgl.GL_PROJECTION)
		bgl.glPopMatrix()
예제 #54
0
 def draw_callback_postpixel(self, context):
     bgl.glPushAttrib(bgl.GL_ALL_ATTRIB_BITS)    # save OpenGL attributes
     self.draw_postpixel(context)
     bgl.glPopAttrib()                           # restore OpenGL attributes