Пример #1
0
    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()
Пример #2
0
    def clean(self, opts=None):
        if not self.is_dirty: return

        # make not dirty first in case bad things happen while drawing
        self.is_dirty = False

        if self.src_bvh:
            # normal_update() will destroy normals of verts not connected to faces :(
            self.tar_bmesh.normal_update()
            for bmv in self.tar_bmesh.verts:
                if len(bmv.link_faces) != 0: continue
                _, n, _, _ = self.src_bvh.find_nearest(self.src_imx * bmv.co)
                bmv.normal = (self.src_mxnorm * n).normalized()

        bgl.glNewList(self.calllist, bgl.GL_COMPILE)
        # do not change attribs if they're not set
        glSetDefaultOptions(opts=opts)
        bgl.glPushMatrix()
        bgl.glMultMatrixf(self.bglMatrix)
        glDrawBMFaces(self.tar_bmesh.faces, opts=opts, enableShader=False)
        glDrawBMEdges(self.tar_bmesh.edges, opts=opts, enableShader=False)
        glDrawBMVerts(self.tar_bmesh.verts, opts=opts, enableShader=False)
        bgl.glDepthRange(0, 1)
        bgl.glPopMatrix()
        bgl.glEndList()
Пример #3
0
def draw_px_point(self, context):
    """
    Draws the handle seen when rotating or scaling
    """
    vx = Vector([1, 0])
    try:
        math.degrees(self.vec_act.angle_signed(vx))
        math.degrees(self.vec_act.angle_signed(vx))
    except ValueError:
        return

    bgl.glEnable(bgl.GL_BLEND)
    bgl.glColor4f(1.0, 0.5, 0.0, 1.0)

    bgl.glLineStipple(4, 0x5555)
    bgl.glEnable(bgl.GL_LINE_STIPPLE)

    bgl.glPushMatrix()
    bgl.glTranslatef(self.center_area.x, self.center_area.y, 0)
    bgl.glBegin(bgl.GL_LINES)
    bgl.glVertex2f(0, 0)
    bgl.glVertex2f(self.vec_act.x, self.vec_act.y)
    bgl.glEnd()
    bgl.glPopMatrix()

    bgl.glDisable(bgl.GL_LINE_STIPPLE)

    bgl.glLineWidth(3)

    bgl.glPushMatrix()
    bgl.glTranslatef(self.center_area.x + self.vec_act.x,
                     self.center_area.y + self.vec_act.y, 0)

    if self.bl_idname == 'VSE_TRANSFORM_TOOLS_OT_scale':
        bgl.glRotatef(math.degrees(self.vec_act.angle_signed(vx)), 0, 0, 1)
    if self.bl_idname == 'VSE_TRANSFORM_TOOLS_OT_rotate':
        bgl.glRotatef(
            math.degrees(self.vec_act.angle_signed(vx)) + 90, 0, 0, 1)

    bgl.glBegin(bgl.GL_LINES)
    bgl.glVertex2f(5, 0)
    bgl.glVertex2f(15, 0)
    bgl.glVertex2f(15, 0)
    bgl.glVertex2f(10, -7)
    bgl.glVertex2f(15, 0)
    bgl.glVertex2f(10, 7)

    bgl.glVertex2f(-5, 0)
    bgl.glVertex2f(-15, 0)
    bgl.glVertex2f(-15, 0)
    bgl.glVertex2f(-10, -7)
    bgl.glVertex2f(-15, 0)
    bgl.glVertex2f(-10, 7)
    bgl.glEnd()
    bgl.glPopMatrix()

    bgl.glLineWidth(1)

    bgl.glDisable(bgl.GL_BLEND)
    bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
Пример #4
0
	def text( self, text, arg1=0, arg2=0, arg3=0 ):
		x = 0
		y = 0
		z = 0
		rx = 0
		ry = 0
		rz = 0

		if type( arg1 ) is mathutils.Vector():
			x = arg1.x
			y = arg1.y
			z = arg1.z
			if type( arg2 ) is mathutils.Vector():
				rx = arg2.x
				ry = arg2.y
				rz = arg2.z

		elif type( arg1 ) is bge.types.KX_GameObject or type( arg1 ) is str:
			if type( arg1 ) is str:
				arg1 = self.getObjectByName( arg1 )
			if arg1 is not 0:
				o = self.getPosition( arg1 )
				x = o.x
				y = o.y
				z = o.z
				# translation vector
				if type( arg2 ) is mathutils.Vector():
					x += arg2.x
					y += arg2.y
					z += arg2.z
				# rotation vector
				if type( arg3 ) is mathutils.Vector():
					rx = arg3.x
					ry = arg3.y
					rz = arg3.z
		
		elif type( arg1 ) is float and type( arg2 ) is float and type( arg3 ) is float:
			x = arg1
			y = arg2
			z = arg3

		elif type( arg1 ) is int and type( arg2 ) is int and type( arg3 ) is int:
			x = arg1
			y = arg2
			z = arg3
		
		width = bge.render.getWindowWidth()
		height = bge.render.getWindowHeight()
		ratiow = 1./width
		ratioh = 1./height
		bgl.glPushMatrix()
		bgl.glTranslatef( x,y,z )
#TODO transform angles to matrix!
		# bgl.glRotate( rx,ry,rz )
		bgl.glScalef( ratiow, ratioh, 0 )
		blf.position( self.font, 0,0,0 )
		blf.size( self.font, self.tsize, 300 )
		bgl.glColor3f( self.tcolor.x, self.tcolor.y, self.tcolor.z )
		blf.draw( self.font, text )
		bgl.glPopMatrix()
Пример #5
0
def draw_udim_tiles(M, color):

    if len(UDM_TILES) == 0:
        return

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

    bgl.glColor4f(*color)

    # label placement
    for tile in UDM_TILES:
        y, x = udim_to_xy(tile)
        #print("label:",y,x)

        font_id = 0
        font_size = maprange((64, 512), (8, 12), M[0])
        if (M[0] > 64):
            blf.size(font_id, int(font_size), 72)
            offset = M[0] * (1 / 32.0)
            blf.position(font_id, x * M[0] + M[12] + offset, y * M[0] + M[13] + offset, 0)
            blf.draw(font_id, str(tile))

    bgl.glPopMatrix()

    bgl.glLineWidth(1.0)
    bgl.glEnable(bgl.GL_BLEND)
    bgl.glBlendFunc(bgl.GL_SRC_ALPHA, bgl.GL_ONE_MINUS_SRC_ALPHA)
    draw_vertex_array("udims", bgl.GL_LINES, 2, color)
Пример #6
0
def draw_snap(self, loc, orientation):
    """
    Draws the purple snap lines
    """
    bgl.glEnable(bgl.GL_BLEND)
    bgl.glLineWidth(2)
    bgl.glPushMatrix()

    r = 1.0
    g = 0.0
    b = 1.0
    a = 0.5
    bgl.glColor4f(r, g, b, a)

    if orientation == "VERTICAL":
        bgl.glTranslatef(loc, 0, 0)

        start = Vector([0, -10000])
        end = Vector([0, 10000])
        draw_line(start, end)

    elif orientation == "HORIZONTAL":
        bgl.glTranslatef(0, loc, 0)

        start = Vector([-10000, 0])
        end = Vector([10000, 0])
        draw_line(start, end)

    bgl.glPopMatrix()

    bgl.glLineWidth(1)
    bgl.glDisable(bgl.GL_BLEND)
    bgl.glColor4f(0.0, 0.0, 0.0, 1.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()
Пример #8
0
 def draw_one(u):
     c = PCVCache.cache[u]
     # update matrix, every frame for now, it should be done better.. but it works well..
     m = c['object'].matrix_world
     matrix = []
     for v in m.transposed():
         matrix.extend(list(v.to_tuple()))
     matrix_buffer = bgl.Buffer(bgl.GL_FLOAT, len(matrix), matrix)
     c['matrix'] = m
     c['matrix_buffer'] = matrix_buffer
     
     bgl.glPushMatrix()
     bgl.glMultMatrixf(c['matrix_buffer'])
     
     bgl.glEnable(bgl.GL_DEPTH_TEST)
     bgl.glEnableClientState(bgl.GL_VERTEX_ARRAY)
     bgl.glVertexPointer(3, bgl.GL_FLOAT, 0, c['vertex_buffer'])
     bgl.glEnableClientState(bgl.GL_COLOR_ARRAY)
     bgl.glColorPointer(3, bgl.GL_FLOAT, 0, c['color_buffer'])
     
     if(PCVCache.cache[u]['smooth']):
         bgl.glEnable(bgl.GL_POINT_SMOOTH)
     
     l = int((c['length'] / 100) * c['display_percent'])
     bgl.glDrawArrays(bgl.GL_POINTS, 0, l)
     
     bgl.glDisableClientState(bgl.GL_VERTEX_ARRAY)
     bgl.glDisableClientState(bgl.GL_COLOR_ARRAY)
     
     if(c['smooth']):
         bgl.glDisable(bgl.GL_POINT_SMOOTH)
     bgl.glDisable(bgl.GL_DEPTH_TEST)
     
     bgl.glPopMatrix()
Пример #9
0
    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()
Пример #10
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()
Пример #11
0
def h_draw_text(fid, text, bounds, color, margin=0, font_size=16, text_align=0, vertical_align=0, shadow=False, clip=True):
    text = str(text)
    width = render.getWindowWidth()
    height = render.getWindowHeight()
    
    #bgl.glColor4f(*(1, 0, 0, 1))
    #h_draw_quad_wire(bounds)
    
    if clip:
        h_clip_begin(bounds)
    
    blf.size(fid, font_size, 72)
    if shadow:
        blf.enable(fid, blf.SHADOW)
        blf.shadow(fid, 3, 0.0, 0.0, 0.0, 1.0)
        blf.shadow_offset(fid, 0, -1)
    else:
        blf.disable(fid, blf.SHADOW)
    bgl.glPushMatrix()
    
    # Fix upside-down text =)
    w, h = blf.dimensions(fid, text)
    bgl.glTranslated(0.0, h, 0.0)
    bgl.glScalef(1.0, -1.0, 1.0)
    
    bgl.glColor4f(*color)

    texts = text.split("\n")
    yn = 0
    if vertical_align == 0:
        yn = margin
    elif vertical_align == 1:
        yn = bounds[3]/2-(h*len(texts))/2
    elif vertical_align == 2:
        yn = (bounds[3]-(h*len(texts)))-margin
    for i in range(len(texts)):            
        texts[i] = texts[i].replace("\t", "        ")
        wl, hl = blf.dimensions(fid, texts[i])
        xn = 0
        
        if text_align == 0:
            xn = margin
        elif text_align == 1:
            xn = bounds[2]/2-wl/2
        elif text_align == 2:
            xn = (bounds[2]-wl)-margin
            
        blf.position(fid, bounds[0]+xn, -bounds[1]-(i*h)-yn, 1)
        
        blf.draw(fid, texts[i])
        
    bgl.glScalef(1.0, 1.0, 1.0)
    bgl.glPopMatrix()
    
    if clip:
        h_clip_end()
Пример #12
0
 def mul_4x4_matrixd(m1, m2):
     """double型で大きさが16のBuffer同士の積"""
     matrix_mode = Buffer('int', 0, bgl.GL_MATRIX_MODE)
     bgl.glMatrixMode(bgl.GL_MODELVIEW)  # GL_MAX_MODELVIEW_STACK_DEPTH: 32
     bgl.glPushMatrix()
     bgl.glLoadMatrixd(m1)
     bgl.glMultMatrixd(m2)
     mat = Buffer('double', (4, 4), bgl.GL_MODELVIEW_MATRIX)
     bgl.glPopMatrix()
     bgl.glMatrixMode(matrix_mode)
     return mat
Пример #13
0
 def mul_4x4_matrixd(m1, m2):
     """double型で大きさが16のBuffer同士の積"""
     matrix_mode = Buffer('int', 0, bgl.GL_MATRIX_MODE)
     bgl.glMatrixMode(bgl.GL_MODELVIEW)  # GL_MAX_MODELVIEW_STACK_DEPTH: 32
     bgl.glPushMatrix()
     bgl.glLoadMatrixd(m1)
     bgl.glMultMatrixd(m2)
     mat = Buffer('double', (4, 4), bgl.GL_MODELVIEW_MATRIX)
     bgl.glPopMatrix()
     bgl.glMatrixMode(matrix_mode)
     return mat
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()
Пример #15
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()
Пример #16
0
def draw_callback_px_2d_cursor(self, context):
    c2d = context.region.view2d.view_to_region(
        context.scene.seq_cursor2d_loc[0],
        context.scene.seq_cursor2d_loc[1],
        clip=False)

    bgl.glEnable(bgl.GL_BLEND)
    bgl.glLineWidth(1)
    bgl.glColor4f(0.7, 0.7, 0.7, 1.0)
    bgl.glPushMatrix()
    bgl.glTranslatef(c2d[0], c2d[1], 0)
    bgl.glBegin(bgl.GL_LINES)
    bgl.glVertex2i(0, -15)
    bgl.glVertex2i(0, -5)
    bgl.glVertex2i(0, 15)
    bgl.glVertex2i(0, 5)
    bgl.glVertex2i(-15, 0)
    bgl.glVertex2i(-5, 0)
    bgl.glVertex2i(15, 0)
    bgl.glVertex2i(5, 0)
    bgl.glEnd()

    size = 10
    c = []
    s = []
    for i in range(16):
        c.append(math.cos(i * math.pi / 8))
        s.append(math.sin(i * math.pi / 8))
    bgl.glColor4f(1.0, 1.0, 1.0, 1.0)
    bgl.glBegin(bgl.GL_LINE_LOOP)
    for i in range(16):
        bgl.glVertex2f(size * c[i], size * s[i])
    bgl.glEnd()

    bgl.glEnable(bgl.GL_LINE_STIPPLE)
    bgl.glLineStipple(4, 0x5555)
    bgl.glColor4f(1.0, 0.0, 0.0, 1.0)

    bgl.glBegin(bgl.GL_LINE_LOOP)
    for i in range(16):
        bgl.glVertex2f(size * c[i], size * s[i])
    bgl.glEnd()

    bgl.glPopMatrix()

    bgl.glDisable(bgl.GL_LINE_STIPPLE)
    bgl.glLineWidth(1)
    bgl.glDisable(bgl.GL_BLEND)
    bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
Пример #17
0
    def info(self, text, arg1=0, y=0, z=0):
        if self.configured is True and self.view_orientation is not 0:

            x = arg1
            if type(arg1) is mathutils.Vector():
                x = arg1.x
                y = arg1.y
                z = arg1.z
            elif type(arg1) is bge.types.KX_GameObject:
                o = self.getPosition(arg1)
                x = o.x
                y = o.y
                z = o.z

            width = bge.render.getWindowWidth()
            height = bge.render.getWindowHeight()

            ratiow = 1. / width
            ratioh = 1. / height
            ratios = mathutils.Vector(
                (self.view_orientation[0][3], self.view_orientation[1][3],
                 self.view_orientation[2][3])).length
            bgl.glPushMatrix()
            bgl.glTranslatef(x, y, z)
            buf = bgl.Buffer(bgl.GL_FLOAT, [16])
            buf[0] = self.view_orientation[0][0]
            buf[1] = self.view_orientation[0][1]
            buf[2] = self.view_orientation[0][2]
            buf[3] = 0
            buf[4] = self.view_orientation[1][0]
            buf[5] = self.view_orientation[1][1]
            buf[6] = self.view_orientation[1][2]
            buf[7] = 0
            buf[8] = self.view_orientation[2][0]
            buf[9] = self.view_orientation[2][1]
            buf[10] = self.view_orientation[2][2]
            buf[11] = 0
            buf[12] = 0
            buf[13] = 0
            buf[14] = 0
            buf[15] = 1
            bgl.glMultMatrixf(buf)
            bgl.glScalef(ratiow, ratioh, 0)
            blf.position(self.font, 0, 0, 0)
            blf.size(self.font, self.tsize, 300)
            bgl.glColor3f(self.tcolor.x, self.tcolor.y, self.tcolor.z)
            blf.draw(self.font, text)
            bgl.glPopMatrix()
Пример #18
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()
Пример #19
0
	def info( self, text, arg1=0, y=0, z=0 ):
		if self.configured is True and self.view_orientation is not 0:
			
			x = arg1
			if type( arg1 ) is mathutils.Vector():
				x = arg1.x
				y = arg1.y
				z = arg1.z
			elif type( arg1 ) is bge.types.KX_GameObject:
				o = self.getPosition( arg1 )
				x = o.x
				y = o.y
				z = o.z

			width = bge.render.getWindowWidth()
			height = bge.render.getWindowHeight()

			ratiow = 1./width
			ratioh = 1./height
			ratios = mathutils.Vector( ( self.view_orientation[0][3], self.view_orientation[1][3], self.view_orientation[2][3] ) ).length
			bgl.glPushMatrix()
			bgl.glTranslatef( x,y,z )
			buf = bgl.Buffer( bgl.GL_FLOAT, [16] )
			buf[0] = self.view_orientation[0][0]
			buf[1] = self.view_orientation[0][1]
			buf[2] = self.view_orientation[0][2]
			buf[3] = 0
			buf[4] = self.view_orientation[1][0]
			buf[5] = self.view_orientation[1][1]
			buf[6] = self.view_orientation[1][2]
			buf[7] = 0
			buf[8] = self.view_orientation[2][0]
			buf[9] = self.view_orientation[2][1]
			buf[10] = self.view_orientation[2][2]
			buf[11] = 0
			buf[12] = 0
			buf[13] = 0
			buf[14] = 0
			buf[15] = 1
			bgl.glMultMatrixf( buf )
			bgl.glScalef( ratiow, ratioh, 0 )
			blf.position( self.font, 0,0,0 )
			blf.size( self.font, self.tsize, 300 )
			bgl.glColor3f( self.tcolor.x, self.tcolor.y, self.tcolor.z )
			blf.draw( self.font, text )
			bgl.glPopMatrix()
Пример #20
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()
Пример #21
0
def draw_callback_px(self, context):
    
    #get RegionView3D
    r3d = 0
    for space in context.area.spaces:
        if space.type == 'VIEW_3D':
            r3d = space.region_3d
    
    if r3d == 0:
        print("region_3D NOT FOUND")
        pass
    
    screenWidth = context.area.width
    screenHeight = context.area.height
    
    bgl.glEnable(bgl.GL_BLEND)
    bgl.glEnable(bgl.GL_DEPTH_TEST)
    
    # get old viewport properties
    oldViewport = bgl.Buffer(bgl.GL_INT, 4)
    bgl.glGetIntegerv(bgl.GL_VIEWPORT, oldViewport) 
    
    #oldViewDistance = r3d.view_distance
    
    oldMatrix = bgl.Buffer(bgl.GL_DOUBLE, [4,4])
    bgl.glGetDoublev(bgl.GL_PROJECTION_MATRIX, oldMatrix)
    
    viewportWidth = int(oldViewport[2]/4)
    viewportHeight = int(oldViewport[3]/4)
    
    #bgl.glViewport(screenWidth - viewportWidth, screenHeight - viewportHeight, viewportWidth, viewportHeight)
    bgl.glViewport(screenWidth - viewportWidth, (screenHeight - viewportHeight) + int((viewportHeight-viewportWidth)/2), viewportWidth, viewportHeight)
    
    draw_cube(context, r3d)

    # restore opengl defaults
    #r3d.view_distance = oldViewDistance
    bgl.glLineWidth(1)
    bgl.glDisable(bgl.GL_BLEND)
    bgl.glDisable(bgl.GL_DEPTH_TEST)
    bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
    bgl.glViewport(oldViewport[0],oldViewport[1],oldViewport[2],oldViewport[3])
    
    bgl.glPushMatrix()
    bgl.glLoadMatrixf(oldMatrix)
    bgl.glPopMatrix()
Пример #22
0
    def ondraw_postview(self, obj_arm, bone):
        if obj_arm.hide or not obj_arm.data.xray.display_bone_shapes:
            return

        from .gl_utils import matrix_to_buffer, draw_wire_cube, draw_wire_sphere, draw_wire_cylinder

        shape = self.shape
        if shape.type == '0':
            return
        bgl.glEnable(bgl.GL_BLEND)
        if bpy.context.active_bone and (bpy.context.active_bone.id_data
                                        == obj_arm.data) and (
                                            bpy.context.active_bone.name
                                            == bone.name):
            bgl.glColor4f(1.0, 0.0, 0.0, 0.7)
        else:
            bgl.glColor4f(0.0, 0.0, 1.0, 0.5)
        prev_line_width = bgl.Buffer(bgl.GL_FLOAT, [1])
        bgl.glGetFloatv(bgl.GL_LINE_WIDTH, prev_line_width)
        bgl.glPushMatrix()
        try:
            m = obj_arm.matrix_world * obj_arm.pose.bones[
                bone.name].matrix * mathutils.Matrix.Scale(-1, 4, (0, 0, 1))
            bgl.glLineWidth(2)
            if shape.type == '1':  # box
                rt = shape.box_rot
                mr = mathutils.Matrix((rt[0:3], rt[3:6], rt[6:9])).transposed()
                m *= mathutils.Matrix.Translation(shape.box_trn) * mr.to_4x4()
                bgl.glMultMatrixf(matrix_to_buffer(m.transposed()))
                draw_wire_cube(*shape.box_hsz)
            if shape.type == '2':  # sphere
                m *= mathutils.Matrix.Translation(shape.sph_pos)
                bgl.glMultMatrixf(matrix_to_buffer(m.transposed()))
                draw_wire_sphere(shape.sph_rad, 16)
            if shape.type == '3':  # cylinder
                m *= mathutils.Matrix.Translation(shape.cyl_pos)
                bgl.glMultMatrixf(matrix_to_buffer(m.transposed()))
                v_dir = mathutils.Vector(shape.cyl_dir)
                q_rot = v_dir.rotation_difference((0, 1, 0))
                bgl.glMultMatrixf(matrix_to_buffer(q_rot.to_matrix().to_4x4()))
                draw_wire_cylinder(shape.cyl_rad, shape.cyl_hgh * 0.5, 16)
        finally:
            bgl.glPopMatrix()
            bgl.glLineWidth(prev_line_width[0])
Пример #23
0
    def view_draw(self, context):

        verco = [(1.0, 1.0), (-1.0, 1.0), (-1.0, -1.0), (1.0, -1.0)]
        texco = [(1.0, 1.0), (0.0, 1.0), (0.0, 0.0), (1.0, 0.0)]

        viewport = bgl.Buffer(bgl.GL_INT, [4])

        bgl.glDisable(bgl.GL_DEPTH_TEST)

        bgl.glGetIntegerv(bgl.GL_VIEWPORT, viewport)

        bgl.glViewport(viewport[0], viewport[1], viewport[2], viewport[3])

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

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

        bgl.glUseProgram(self.program)
        wind = glGetUniformLocation(self.program, "u_wind")
        res = glGetUniformLocation(self.program, "u_resolution")
        size = glGetUniformLocation(self.program, "u_size")

        glUniform2fv(wind, 1, [150.0, 150.0])
        glUniform1f(size, 250.0)
        glUniform1f(res, 512.0)

        bgl.glBegin(bgl.GL_QUADS)
        for i in range(4):
            bgl.glTexCoord3f(texco[i][0], texco[i][1], 1.0)
            bgl.glVertex2f(verco[i][0], verco[i][1])
        bgl.glEnd()

        bgl.glUseProgram(0)

        bgl.glMatrixMode(bgl.GL_PROJECTION)
        bgl.glPopMatrix()

        bgl.glMatrixMode(bgl.GL_MODELVIEW)
        bgl.glPopMatrix()
Пример #24
0
def draw_axes(self, context, angle):
    bgl.glEnable(bgl.GL_BLEND)
    bgl.glLineWidth(2)

    bgl.glPushMatrix()

    transforms = []
    strips = bpy.context.selected_sequences
    for strip in strips:
        if strip.type == 'TRANSFORM':
            transforms.append(strip)

    group_box = get_group_box(transforms)
    min_left, max_right, min_bottom, max_top = group_box
    group_width = max_right - min_left
    group_height = max_top - min_bottom

    group_pos_x = min_left + (group_width / 2)
    group_pos_y = min_bottom + (group_height / 2)

    offset_x, offset_y, fac, preview_zoom = get_preview_offset()

    x = (group_pos_x * fac * preview_zoom) + offset_x
    y = (group_pos_y * fac * preview_zoom) + offset_y

    bgl.glTranslatef(x, y, 0)
    bgl.glRotatef(angle, 0, 0, 1)

    bgl.glBegin(bgl.GL_LINES)
    bgl.glColor4f(1.0, 0.0, 0.0, 0.2 * self.choose_axis + self.axis_x * 0.8)
    bgl.glVertex2f(-10000, 0)
    bgl.glVertex2f(10000, 0)
    bgl.glColor4f(0.0, 1.0, 0.0, 0.2 * self.choose_axis + self.axis_y * 0.8)
    bgl.glVertex2f(0, -10000)
    bgl.glVertex2f(0, 10000)
    bgl.glEnd()

    bgl.glPopMatrix()

    bgl.glLineWidth(1)
    bgl.glDisable(bgl.GL_BLEND)
    bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
Пример #25
0
 def draw(self, opts=None):
     if self.is_dirty:
         # make not dirty first in case bad things happen while drawing
         self.is_dirty = False
         
         bgl.glNewList(self.calllist, bgl.GL_COMPILE)
         # do not change attribs if they're not set
         glSetDefaultOptions(opts=opts)
         if self.mx:
             bgl.glPushMatrix()
             bgl.glMultMatrixf(self.bglMatrix)
         glDrawBMFaces(self.bmesh.faces, opts=opts)
         glDrawBMEdges(self.bmesh.edges, opts=opts)
         glDrawBMVerts(self.bmesh.verts, opts=opts)
         bgl.glDepthRange(0, 1)
         if self.mx:
             bgl.glPopMatrix()
         bgl.glEndList()
     
     bgl.glCallList(self.calllist)
Пример #26
0
    def draw(self, renderer, obj):
        if self.update:
            self.cache(renderer, obj)

        data = obj.data
        if data:
            mesh = renderer.mesh_cache.get(hash(obj.data))
            if mesh is None:
                mesh = LineMeshCache()
                renderer.mesh_cache[hash(obj.data)] = mesh

            if obj.select:
                bgl.glLineWidth(2)
                bgl.glLineStipple(1, 0xAAAA)
                bgl.glEnable(bgl.GL_LINE_STIPPLE)

            bgl.glPushMatrix()
            bgl.glMultMatrixf(self.m)

            mesh.draw(renderer, obj)

            bgl.glPopMatrix()
Пример #27
0
def draw_callback_view():
    context = bpy.context
    if context.mode != "EDIT_MESH":
        return
    ob = context.active_object
    if ob is None:
        return
    if ob.type != "MESH":
        return
    if ob.mode != "EDIT":
        return
    if False:
        # Respects modifiers, but not hidden edges
        ob.update_from_editmode()
        bm = bmesh.new()
        bm.from_object(ob, context.scene)
    else:
        # Faster bmesh access, but doesn't respect modifiers
        bm = bmesh.from_edit_mesh(ob.data)
    layer = get_edgecolor_layer(bm)
    if layer is None:
        return
    bgl.glLineWidth(3.0)
    bgl.glPushMatrix()
    b = bgl.Buffer(GL_FLOAT, [16], list(itertools.chain(*ob.matrix_world.col)))
    bgl.glMultMatrixf(b)
    for edge in bm.edges:
        if edge.hide: continue
        color_int = edge[layer]
        if color_int == 0: continue
        bgl.glColor3f(*colors[color_int])
        bgl.glBegin(GL_LINES)
        for v in edge.verts:
            bgl.glVertex3f(*v.co)
        bgl.glEnd()
    bgl.glPointSize(1.0)
    bgl.glLineWidth(1.0)
    bgl.glPopMatrix()
Пример #28
0
def draw_callback_view():
    context = bpy.context
    if context.mode != "EDIT_MESH":
        return
    ob = context.active_object
    if ob is None:
        return
    if ob.type != "MESH":
        return
    if ob.mode != "EDIT":
        return
    if False:
        # Respects modifiers, but not hidden edges
        ob.update_from_editmode()
        bm = bmesh.new()
        bm.from_object(ob, context.scene)
    else:
        # Faster bmesh access, but doesn't respect modifiers
        bm = bmesh.from_edit_mesh(ob.data)
    layer = get_edgecolor_layer(bm)
    if layer is None:
        return
    bgl.glLineWidth(3.0)
    bgl.glPushMatrix()
    b = bgl.Buffer(GL_FLOAT, [16], list(itertools.chain(*ob.matrix_world.col)))
    bgl.glMultMatrixf(b)
    for edge in bm.edges:
        if edge.hide: continue
        color_int = edge[layer]
        if color_int == 0: continue
        bgl.glColor3f(*colors[color_int])
        bgl.glBegin(GL_LINES)
        for v in edge.verts:
            bgl.glVertex3f(*v.co)
        bgl.glEnd()
    bgl.glPointSize(1.0)
    bgl.glLineWidth(1.0)
    bgl.glPopMatrix()
Пример #29
0
def drawText(context, text, location):
    v3d = context.space_data;
    rv3d = v3d.region_3d;
    text_scale = TEXT_SCALE_VALUE * ((max(min(MAX_ZOOM_DISTANCE, rv3d.view_distance), MIN_ZOOM_DISTANCE)) / FRIENDLY_ZOOM_DISTANCE);
#     print("RV3D PARAMETERS ::: " , rv3d.view_location, rv3d.view_distance);
#     print('TEXT SCALE USED :::: ', text_scale);
    
    
    font_id = 0;
    
    axis, angle = getScreenLookAxis(context);
    
    bgl.glPushMatrix();
    bgl.glTranslatef(location.x, location.y , location.z);
    
    bgl.glPushMatrix();
    bgl.glRotatef(angle, axis.x, axis.y, axis.z);
    
    bgl.glPushMatrix();
    bgl.glScalef(text_scale,text_scale,text_scale);
    
    bgl.glPushMatrix();
    bgl.glRotatef(90.0, 1.0, 0.0, 0.0);
    
    blf.position(font_id, 0.0, 0.0 , 0.0);
    blf.size(font_id, 72, 72);
    bgl.glColor4f(0.0, 0.0, 0.0, 1.0);
    blf.draw(0, text);
#     blf.rotation(0, 1.57);
    bgl.glPopMatrix();
    
    bgl.glPopMatrix();
    
    bgl.glPopMatrix();
    
    bgl.glPopMatrix();
Пример #30
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()
Пример #31
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()
Пример #32
0
def generate_icon(name, verts=None, faces=None):
    pcoll = preview_collections["shape_types"]
    if name in pcoll:
        thumb = pcoll.get(name)
    else:
        thumb = pcoll.new(name)
    thumb.image_size = (200, 200)

    if verts is not None:
        import bgl

        polygon_color = bpy.context.user_preferences.themes[0].view_3d.edge_facesel
        edge_color = bpy.context.user_preferences.themes[0].view_3d.edge_select
        vertex_color = bpy.context.user_preferences.themes[0].view_3d.vertex_select
        clear_color = bpy.context.user_preferences.themes[0].user_interface.wcol_menu.inner

        viewport_info = bgl.Buffer(bgl.GL_INT, 4)
        bgl.glGetIntegerv(bgl.GL_VIEWPORT, viewport_info)
        buffer = bgl.Buffer(bgl.GL_FLOAT, 200 * 200 * 4)

        bgl.glDisable(bgl.GL_SCISSOR_TEST)
        bgl.glBlendFunc(bgl.GL_SRC_ALPHA, bgl.GL_ONE_MINUS_SRC_ALPHA)
        bgl.glEnable(bgl.GL_LINE_SMOOTH)
        bgl.glEnable(bgl.GL_POINT_SMOOTH)
        bgl.glViewport(0, 0, 200, 200)

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

        bgl.glMatrixMode(bgl.GL_PROJECTION)
        bgl.glPushMatrix()
        bgl.glLoadIdentity()
        bgl.gluOrtho2D(0, 0, 0, 0)

        bgl.glLineWidth(4.0)
        bgl.glPointSize(10.0)

        bgl.glClearColor(*clear_color)
        bgl.glClear(bgl.GL_COLOR_BUFFER_BIT | bgl.GL_DEPTH_BUFFER_BIT)

        if faces is None:
            bgl.glBegin(bgl.GL_POLYGON)
            bgl.glColor3f(*polygon_color)
            for vert in verts:
                bgl.glVertex2f(*vert)
            bgl.glEnd()
        else:
            bgl.glBegin(bgl.GL_TRIANGLES)
            bgl.glColor3f(*polygon_color)
            for face in faces:
                bgl.glVertex2f(*verts[face[0]])
                bgl.glVertex2f(*verts[face[1]])
                bgl.glVertex2f(*verts[face[2]])
            bgl.glEnd()

        bgl.glBegin(bgl.GL_LINE_LOOP)
        bgl.glColor3f(*edge_color)
        for vert in verts:
            bgl.glVertex2f(*vert)
        bgl.glEnd()

        bgl.glBegin(bgl.GL_POINTS)
        bgl.glColor3f(*vertex_color)
        for vert in verts:
            bgl.glVertex2f(*vert)
        bgl.glEnd()

        bgl.glReadPixels(0, 0, 200, 200, bgl.GL_RGBA, bgl.GL_FLOAT, buffer)
        bgl.glEnable(bgl.GL_SCISSOR_TEST)
        bgl.glLineWidth(1.0)
        bgl.glPointSize(1.0)

        buffer = buffer[:]
        for idx in range(0, 200 * 200 * 4, 4):
            if (
                buffer[idx] == clear_color[0]
                and buffer[idx + 1] == clear_color[1]
                and buffer[idx + 2] == clear_color[2]
            ):
                buffer[idx + 3] = 0.0

        thumb.image_pixels_float = buffer
Пример #33
0
    def draw(self, context):
        """
        Draw vector icon on position of shared object
        """

        if self.locked is True:
            # When object is locked by current client, then visualize it by green color.
            # Otherwise visualize it by red color
            if self.locked_by_me is True:
                color = (0.0, 1.0, 0.0, 1.0)
            else:
                color = (1.0, 0.0, 0.0, 1.0)
        else:
            color = (0.0, 1.0, 1.0, 1.0)

        # Store Line width
        line_width_prev = bgl.Buffer(bgl.GL_FLOAT, [1])
        bgl.glGetFloatv(bgl.GL_LINE_WIDTH, line_width_prev)
        line_width_prev = line_width_prev[0]

        # Store glColor4f
        col_prev = bgl.Buffer(bgl.GL_FLOAT, [4])
        bgl.glGetFloatv(bgl.GL_COLOR, col_prev)

        pos = self.transform.pos.value
        if pos is not None:
            new_pos = location_3d_to_region_2d(
                context.region,
                context.space_data.region_3d,
                pos)
        else:
            # When position of object is not set atm, then draw
            # icon with stipple line
            new_pos = mathutils.Vector((0.0, 0.0, 0.0, 1.0))
            bgl.glEnable(bgl.GL_LINE_STIPPLE)

        verts = (
            (0.20000000298023224, 0.0),
            (0.19318519532680511, 0.051763709634542465),
            (0.17320513725280762, 0.09999989718198776),
            (0.14142143726348877, 0.14142127335071564),
            (0.10000012069940567, 0.17320501804351807),
            (0.13000015914440155, 0.22516652941703796),
            (0.06729313731193542, 0.25114068388938904),
            (0.0, 0.2600000202655792),
            (-0.0672929584980011, 0.2511407434940338),
            (-0.1300000101327896, 0.22516663372516632),
            (-0.1000000014901161, 0.17320509254932404),
            (-0.1414213627576828, 0.1414213627576828),
            (-0.1732050925493240, 0.09999999403953552),
            (-0.1931851655244827, 0.05176381394267082),
            (-0.2000000029802322, 0.0),
            (-0.2600000202655792, 0.0),
            (-0.2511407434940338, -0.06729292124509811),
            (-0.2251666486263275, -0.12999996542930603),
            (-0.1838478147983551, -0.18384772539138794),
            (-0.1300000697374344, -0.22516658902168274),
            (-0.1000000461935997, -0.17320506274700165),
            (-0.0517638735473156, -0.19318515062332153),
            (0.0, -0.20000000298023224),
            (0.05176372453570366, -0.19318519532680511),
            (0.09999991953372955, -0.17320513725280762),
            (0.12999990582466125, -0.2251666933298111),
            (0.18384768068790436, -0.18384787440299988),
            (0.22516657412052155, -0.13000008463859558),
            (0.25114068388938904, -0.06729305535554886),
            (0.26000002026557920, 0.0)
        )

        bgl.glLineWidth(1)
        bgl.glColor4f(color[0], color[1], color[2], color[3])

        bgl.glPushMatrix()

        bgl.glTranslatef(new_pos[0], new_pos[1], 0)

        # TODO: Rotate this icon, when some other user change something (tranformation, mesh)
        # bgl.glRotatef(self.icon_angle, 0, 0, 1)

        # Draw icon
        bgl.glBegin(bgl.GL_LINE_LOOP)
        for vert in verts:
            bgl.glVertex2f(100.0 * vert[0], 100.0 * vert[1])
        bgl.glEnd()

        # When object is locked by someone else or it can not be selected, then draw cross over icon
        if self.locked is True and self.locked_by_me is False or \
                self.can_be_selected is False:
            bgl.glBegin(bgl.GL_LINES)
            bgl.glVertex2f(100.0 * verts[3][0], 100.0 * verts[3][1])
            bgl.glVertex2f(100.0 * verts[18][0], 100.0 * verts[18][1])
            bgl.glVertex2f(100.0 * verts[11][0], 100.0 * verts[11][1])
            bgl.glVertex2f(100.0 * verts[27][0], 100.0 * verts[27][1])
            bgl.glEnd()

        bgl.glPopMatrix()

        bgl.glDisable(bgl.GL_LINE_STIPPLE)
        bgl.glLineWidth(line_width_prev)
        bgl.glColor4f(col_prev[0], col_prev[1], col_prev[2], col_prev[3])

        # # Try to draw mesh IDs
        # if self.mesh_node is not None:
        #     self.mesh_node.draw_IDs(context, self.obj)