コード例 #1
0
def write():
    """
    Write the name of all active objects on Screen
    """
    # OpenGL setup
    bgl.glMatrixMode(bgl.GL_PROJECTION)
    bgl.glLoadIdentity()
    bgl.gluOrtho2D(0, windowWidth, 0, windowHeight)
    bgl.glMatrixMode(bgl.GL_MODELVIEW)
    bgl.glLoadIdentity()

    cam = scene.active_camera

    for obj in passive_objects.active_objects():
        # test if the object is in the view frustum
        if cam.pointInsideFrustum(obj.worldPosition):
            pos = cam.getScreenPosition(obj)

            blf.size(font_id, int(windowWidth * 0.02), 72)
            # draw a black shadow to increase contrast with white parts
            blf.enable(font_id, blf.SHADOW)
            blf.shadow(font_id, 5, 0.0, 0.0, 0.0, 1.0)
            blf.position(font_id, pos[0] * windowWidth,
                         (1 - pos[1]) * windowHeight, 0)
            blf.draw(font_id, obj.name)
コード例 #2
0
    def redraw(self):

        drawregion = bpy.context.region

        rv3d = self.rv3ds[drawregion]
        vec = self.originvert.co.copy()
        vec.rotate(self.selobj.matrix_world)
        vec.rotate(self.selobj.matrix_world)
        self.space3d.cursor_location = vec * self.selobj.matrix_world + self.selobj.matrix_world.to_translation(
        )

        bgl.glColor3f(1.0, 1.0, 0)
        bgl.glBegin(bgl.GL_POLYGON)
        x, y = self.getscreencoords(Vector(self.originvert.co), drawregion,
                                    rv3d)
        bgl.glVertex2f(x - 2, y - 2)
        bgl.glVertex2f(x - 2, y + 2)
        bgl.glVertex2f(x + 2, y + 2)
        bgl.glVertex2f(x + 2, y - 2)
        bgl.glEnd()

        bgl.glColor3f(1, 1, 0.7)
        bgl.glMatrixMode(bgl.GL_PROJECTION)
        bgl.glLoadIdentity()
        bgl.gluOrtho2D(0, self.region.width, 0, self.region.height)
        bgl.glMatrixMode(bgl.GL_MODELVIEW)
        bgl.glLoadIdentity()
        blf.position(0, self.region.width / 2 - 80, self.region.height - 20, 0)
        blf.size(0, 12, 72)
        blf.draw(0, "FastOrigin :  Enter confirms - ESC cancels")
コード例 #3
0
    def draw(self):
        self.allocate(
            Rect(self.margin.x, self.margin.y,
                 self._render.getWindowWidth() - self.margin.sx,
                 self._render.getWindowHeight() - self.margin.sy))
        self.layout()

        bgl.glMatrixMode(bgl.GL_PROJECTION)
        bgl.glLoadIdentity()
        bgl.gluOrtho2D(0, self._render.getWindowWidth(), 0,
                       self._render.getWindowHeight())
        bgl.glMatrixMode(bgl.GL_MODELVIEW)
        bgl.glLoadIdentity()

        bgl.glPushMatrix()
        bgl.glTranslatef(self.margin.x, self.margin.h, 0)

        bgl.glEnable(bgl.GL_TEXTURE_2D)
        bgl.glEnable(bgl.GL_BLEND)
        bgl.glDisable(bgl.GL_DEPTH)
        bgl.glDisable(bgl.GL_LIGHTING)

        Widget.draw(self)

        bgl.glPopMatrix()
コード例 #4
0
	def redraw(self):

		drawregion = bpy.context.region

		rv3d = self.rv3ds[drawregion]
		vec = self.originvert.co.copy()
		vec.rotate(self.selobj.matrix_world)
		vec.rotate(self.selobj.matrix_world)
		self.space3d.cursor_location =  vec * self.selobj.matrix_world + self.selobj.matrix_world.to_translation()

		bgl.glColor3f(1.0, 1.0, 0)
		bgl.glBegin(bgl.GL_POLYGON)
		x, y = self.getscreencoords(Vector(self.originvert.co), drawregion, rv3d)
		bgl.glVertex2f(x-2, y-2)
		bgl.glVertex2f(x-2, y+2)
		bgl.glVertex2f(x+2, y+2)
		bgl.glVertex2f(x+2, y-2)
		bgl.glEnd()

		bgl.glColor3f(1, 1, 0.7)
		bgl.glMatrixMode(bgl.GL_PROJECTION)
		bgl.glLoadIdentity()
		bgl.gluOrtho2D(0, self.region.width, 0, self.region.height)
		bgl.glMatrixMode(bgl.GL_MODELVIEW)
		bgl.glLoadIdentity()
		blf.position(0, self.region.width/2 - 80, self.region.height - 20, 0)
		blf.size(0, 12, 72)
		blf.draw(0, "FastOrigin :  Enter confirms - ESC cancels")
コード例 #5
0
    def unbind(self):
        bgl.glBindTexture(bgl.GL_TEXTURE_2D, 0)

        if not self.region is None:
            bgl.glMatrixMode(bgl.GL_TEXTURE)
            bgl.glLoadIdentity()
            bgl.glMatrixMode(bgl.GL_MODELVIEW)
コード例 #6
0
def render_offscreen(self, context, width, height, imgname=''):
    assert context.area.type == 'NODE_EDITOR' and context.space_data.tree_type == 'CompositorNodeTree'

    gos = gpu.offscreen.new(width,height)
    gos.bind(True)
    try:
        bgl.glMatrixMode(bgl.GL_PROJECTION)
        bgl.glLoadIdentity()
        bgl.glScalef(1/width*2,1/height*2,1.0)
        bgl.glTranslatef(-width/2,-height/2,0)

        draw_callback(self, context, {
                  'center': Vector((width/2, height/2))
                , 'zoom': 1.0
                , 'back_image_alpha': 1.0
                , 'image_size': (width, height)
                })

        buffer = bgl.Buffer(bgl.GL_FLOAT, width * height * 4)
        x,y = 0,0
        bgl.glReadPixels(x, y, width, height , bgl.GL_RGBA, bgl.GL_FLOAT, buffer)

        out = prepare_blimage(width, height, imgname or Pref.default_output_image_name)
        out.pixels = buffer[:]
    finally:
        gos.unbind(True)
コード例 #7
0
ファイル: effect.py プロジェクト: TripleSnail/blender-zombie
    def fx():
        width = bge.render.getWindowWidth()
        height = bge.render.getWindowHeight()

        bgl.glMatrixMode(bgl.GL_PROJECTION)
        bgl.glLoadIdentity()
        bgl.gluOrtho2D(0, width, 0, height)
        bgl.glMatrixMode(bgl.GL_MODELVIEW)
        bgl.glLoadIdentity()


        bgl.glEnable(bgl.GL_BLEND)
        bgl.glColor4f(0.8, 0.0, 0.0, 0.1)
        bgl.glRecti(0, 0, width, height)
        # bgl.glBegin(bgl.GL_QUADS)
        # bgl.glVertex2i(0, 0)
        # bgl.glVertex2i(width, 0)
        # bgl.glVertex2i(width, height)
        # bgl.glVertex2i(0, height)

        # bgl.glVertex2f(0.0, 0.0)
        # bgl.glVertex2f(1.0, 0.0)
        # bgl.glVertex2f(1.0, 1.0)
        # bgl.glVertex2f(0.0, 1.0)



        # bgl.glEnd()
        bgl.glDisable(bgl.GL_BLEND)
コード例 #8
0
def write():
    """write on screen"""
    width = render.getWindowWidth()
    height = render.getWindowHeight()

    # OpenGL setup
    bgl.glMatrixMode(bgl.GL_PROJECTION)
    bgl.glLoadIdentity()
    bgl.gluOrtho2D(0, width, 0, height)
    #bgl.glColor(1,1,1,1)
    bgl.glMatrixMode(bgl.GL_MODELVIEW)
    bgl.glLoadIdentity()

    # BLF drawing routine
    font_id = logic.font_id
    RED = (1, 0, 0, 1)
    pcol = ("Blue ", RED)
    #blf.color(font_id, 1, 1, 0, 0.5)
    blf.blur(font_id, 500)
    blf.rotation(font_id, 90)
    blf.position(font_id, (width * 0.5), (height * 0.5), 0.5)
    blf.size(font_id, 20, 100)
    blf.draw(font_id, "Hello World1")
    blf.size(font_id, 50, 72)
    blf.position(font_id, (width * 0.0), (height * 0.5), 0.5)
    blf.draw(font_id, "Hello World2")
コード例 #9
0
def writeMessageOnScreen():
    """write on screen"""
    width = render.getWindowWidth()
    height = render.getWindowHeight()

    bgl.glMatrixMode(bgl.GL_PROJECTION)
    bgl.glLoadIdentity()
    bgl.gluOrtho2D(0, width, 0, height)
    bgl.glMatrixMode(bgl.GL_MODELVIEW)
    bgl.glLoadIdentity()

    font_id = logic.font_id
    blf.position(font_id, (width * 0.02), (height * 0.05), 0)
    blf.size(font_id, 35, 50)
    bgl.glColor4f(1, 0, 0, 1)
    blf.draw(font_id, "Hello World!")

    bgl.glColor4f(0, 1, 0, 1)
    blf.position(font_id, (width * 0.02), (height * 0.15), 0)
    blf.size(font_id, 25, 50)
    blf.draw(font_id, "Hello World!")

    bgl.glColor4f(0, 0, 1, 1)
    blf.position(font_id, (width * 0.02), (height * 0.20), 0)
    blf.size(font_id, 25, 50)
    blf.draw(font_id, "Hello World!")
コード例 #10
0
def writeMessageOnScreen():
    """write on screen"""
    width = render.getWindowWidth()
    height = render.getWindowHeight()

    bgl.glMatrixMode(bgl.GL_PROJECTION)
    bgl.glLoadIdentity()
    bgl.gluOrtho2D(0, width, 0, height)
    bgl.glMatrixMode(bgl.GL_MODELVIEW)
    bgl.glLoadIdentity()

    font_id = logic.font_id
    blf.position(font_id, (width * 0.02), (height * 0.05), 0)
    blf.size(font_id, 35, 50)
    bgl.glColor4f(1, 0, 0, 1)
    blf.draw(font_id, "Hello World!")

    bgl.glColor4f(0, 1, 0, 1)
    blf.position(font_id, (width * 0.02), (height * 0.15), 0)
    blf.size(font_id, 25, 50)
    blf.draw(font_id, "Hello World!")

    bgl.glColor4f(0, 0, 1, 1)
    blf.position(font_id, (width * 0.02), (height * 0.20), 0)
    blf.size(font_id, 25, 50)
    blf.draw(font_id, "Hello World!")
コード例 #11
0
ファイル: interaction.py プロジェクト: sylvestre/morse
def write_interaction_status():
    """
    Write the interaction status on Screen
    The status is stored in a property
    """
    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]
    
    # OpenGL setup
    bgl.glMatrixMode(bgl.GL_PROJECTION)
    bgl.glLoadIdentity()
    bgl.gluOrtho2D(0, windowWidth, 0, windowHeight)
    bgl.glMatrixMode(bgl.GL_MODELVIEW)
    bgl.glLoadIdentity()
    
    blf.size(font_id, int(windowHeight*0.04), 72)
    # draw a black shadow around the text
    blf.enable(font_id, blf.SHADOW)
    blf.shadow(font_id, 5, 0.0, 0.0, 0.0, 1.0)
    blf.position(font_id, windowWidth*0.4, windowHeight*0.4,0)
    blf.draw(font_id, hand['Status'])
def write_interaction_status():
    """
    Write the interaction status on Screen
    The status is stored in a property
    """
    cam = blenderapi.scene().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]

    # OpenGL setup
    bgl.glMatrixMode(bgl.GL_PROJECTION)
    bgl.glLoadIdentity()
    bgl.gluOrtho2D(0, windowWidth, 0, windowHeight)
    bgl.glMatrixMode(bgl.GL_MODELVIEW)
    bgl.glLoadIdentity()

    blf.size(font_id, int(windowHeight * 0.04), 72)
    # draw a black shadow around the text
    blf.enable(font_id, blf.SHADOW)
    blf.shadow(font_id, 5, 0.0, 0.0, 0.0, 1.0)
    blf.position(font_id, windowWidth * 0.4, windowHeight * 0.4, 0)
    blf.draw(font_id, hand['Status'])
コード例 #13
0
ファイル: PManager.py プロジェクト: PlumpMath/pgui-1
    def draw(self):
        width = render.getWindowWidth()
        height = render.getWindowHeight()

        # 2D Projection
        bgl.glMatrixMode(bgl.GL_PROJECTION)
        bgl.glLoadIdentity()
        bgl.glOrtho(0, width, height, 0, -1, 1)
        bgl.glMatrixMode(bgl.GL_MODELVIEW)
        bgl.glLoadIdentity()

        # 2D Shading
        bgl.glDisable(bgl.GL_CULL_FACE)
        bgl.glDisable(bgl.GL_LIGHTING)
        bgl.glDisable(bgl.GL_DEPTH_TEST)
        bgl.glShadeModel(bgl.GL_SMOOTH)

        # Line antialias
        bgl.glEnable(bgl.GL_LINE_SMOOTH)
        bgl.glHint(bgl.GL_LINE_SMOOTH_HINT, bgl.GL_NICEST)

        # 2D Blending (Alpha)
        bgl.glEnable(bgl.GL_BLEND)
        bgl.glBlendFunc(bgl.GL_SRC_ALPHA, bgl.GL_ONE_MINUS_SRC_ALPHA)

        if len(self.controls.values()) <= 0: return

        ctrls = sorted(self.controls.values(), key=lambda x: x.zorder)
        for c in ctrls:
            c.draw()
コード例 #14
0
ファイル: hud.py プロジェクト: flossmanualsfr/peril-en-daiza
def write():
    """write on screen"""
    # retrieve timer
    global game_timer
    scene = logic.getCurrentScene()
    game_timer = int(active_camera["Timer"])
    catched = bamboo_counter["catched"]
    total = bamboo_counter["total"]
    vortex = panda.power
    width = render.getWindowWidth()
    height = render.getWindowHeight()

    # OpenGL setup
    bgl.glMatrixMode(bgl.GL_PROJECTION)
    bgl.glLoadIdentity()
    bgl.gluOrtho2D(0, width, 0, height)
    bgl.glMatrixMode(bgl.GL_MODELVIEW)
    bgl.glLoadIdentity()
    
    bgl.glColor4f(1, 1, 1, 1)
    
    # BLF drawing routine
    font_id = logic.font_id
    blf.size(font_id, int(18 * (width/dpi) * 0.06), dpi)
    blf.position(font_id, width*0.02, height*0.95, 0)
    if game_timer < 60:
        blf.draw(font_id, "{0} : {1:02d}".format(l_timer,game_timer))
    else:
        blf.draw(font_id, "{0} : {1}:{2:02d}".format(l_timer,game_timer//60,game_timer%60))
    blf.position(font_id, width*0.02, height*0.90, 0)
    blf.draw(font_id, "{0} : {1}".format(l_level, level))
    blf.position(font_id, width*0.02, height*0.85, 0)
    blf.draw(font_id, "{0} : {1} / {2}".format(l_score, catched, total))
    blf.position(font_id, width*0.02, height*0.80, 0)
    blf.draw(font_id, "{0} : {1}".format(l_vortex, vortex))
コード例 #15
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)
コード例 #16
0
ファイル: PManager.py プロジェクト: jdpillon/pgui
 def draw(self):
     width = render.getWindowWidth()
     height = render.getWindowHeight()
     
     # 2D Projection
     bgl.glMatrixMode(bgl.GL_PROJECTION)
     bgl.glLoadIdentity()
     bgl.glOrtho(0, width, height, 0, -1, 1)
     bgl.glMatrixMode(bgl.GL_MODELVIEW)
     bgl.glLoadIdentity()
     
     # 2D Shading
     bgl.glDisable(bgl.GL_CULL_FACE)
     bgl.glDisable(bgl.GL_LIGHTING)
     bgl.glDisable(bgl.GL_DEPTH_TEST)
     bgl.glShadeModel(bgl.GL_SMOOTH)
     
     # Line antialias
     bgl.glEnable(bgl.GL_LINE_SMOOTH)
     bgl.glHint(bgl.GL_LINE_SMOOTH_HINT, bgl.GL_NICEST)
     
     # 2D Blending (Alpha)
     bgl.glEnable(bgl.GL_BLEND)
     bgl.glBlendFunc(bgl.GL_SRC_ALPHA, bgl.GL_ONE_MINUS_SRC_ALPHA)
     
     if len(self.controls.values()) <= 0: return
     
     ctrls = sorted(self.controls.values(), key=lambda x: x.zorder)
     for c in ctrls:
         c.draw()
コード例 #17
0
ファイル: effect.py プロジェクト: theirishduck/blender-zombie
    def fx():
        width = bge.render.getWindowWidth()
        height = bge.render.getWindowHeight()

        bgl.glMatrixMode(bgl.GL_PROJECTION)
        bgl.glLoadIdentity()
        bgl.gluOrtho2D(0, width, 0, height)
        bgl.glMatrixMode(bgl.GL_MODELVIEW)
        bgl.glLoadIdentity()

        bgl.glEnable(bgl.GL_BLEND)
        bgl.glColor4f(0.8, 0.0, 0.0, 0.1)
        bgl.glRecti(0, 0, width, height)
        # bgl.glBegin(bgl.GL_QUADS)
        # bgl.glVertex2i(0, 0)
        # bgl.glVertex2i(width, 0)
        # bgl.glVertex2i(width, height)
        # bgl.glVertex2i(0, height)

        # bgl.glVertex2f(0.0, 0.0)
        # bgl.glVertex2f(1.0, 0.0)
        # bgl.glVertex2f(1.0, 1.0)
        # bgl.glVertex2f(0.0, 1.0)

        # bgl.glEnd()
        bgl.glDisable(bgl.GL_BLEND)
コード例 #18
0
    def bind(self):
        bgl.glBindTexture(bgl.GL_TEXTURE_2D, self.glid[0])

        if not self.region is None:
            bgl.glMatrixMode(bgl.GL_TEXTURE)
            bgl.glLoadIdentity()
            bgl.glTranslatef(self.region.x, self.region.y, 0)
            bgl.glScalef(self.region.w, self.region.h, 1)
            bgl.glMatrixMode(bgl.GL_MODELVIEW)
コード例 #19
0
ファイル: vagl.py プロジェクト: yazici/blenderpython
 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
コード例 #20
0
ファイル: vagl.py プロジェクト: JT-a/blenderpython
 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
コード例 #21
0
ファイル: display.py プロジェクト: merlinwu/phobos
def draw_callback_px(self, context):
    # define common variables
    region, rv3d = getRegionData()
    active = context.object
    selected = context.selected_objects
    wm = context.window_manager

    # ----- 3D Drawing -----
    bgl.glEnable(bgl.GL_BLEND)

    if active:
        if 'submechanism/spanningtree' in context.object:
            draw_submechanism(context.object['submechanism/spanningtree'])

    if len(selected) > 0:
        for j in [o for o in selected if o.phobostype == 'link']:
            draw_joint(j)

    # restore opengl defaults
    bgl.glLineWidth(1)
    bgl.glDisable(bgl.GL_BLEND)
    bgl.glColor4f(0.0, 0.0, 0.0, 1.0)

    # ----- 2D Drawing -----
    bgl.glMatrixMode(bgl.GL_PROJECTION)
    bgl.glLoadIdentity()
    bgl.gluOrtho2D(0, bpy.context.region.width, 0, bpy.context.region.height)
    bgl.glMatrixMode(bgl.GL_MODELVIEW)
    bgl.glLoadIdentity()
    bgl.glEnable(bgl.GL_BLEND)

    # progress bar
    if context.window_manager.progress not in [0, 1]:
        draw_progressbar(wm.progress)
    # log messages
    for m in range(wm.phobos_msg_count):
        opacity = 1.0
        if 1 >= m <= wm.phobos_msg_offset - 1 or m >= wm.phobos_msg_count - 2:
            opacity = 0.5
        if wm.phobos_msg_offset > 1 > m or m >= wm.phobos_msg_count - 1:
            opacity = 0.1
        try:
            msg = messages[m + wm.phobos_msg_offset]
            draw_message(msg['text'],
                         msg['type'],
                         m,
                         opacity,
                         offset=wm.phobos_msg_offset)
        except IndexError:
            pass

    bgl.glDisable(bgl.GL_BLEND)
コード例 #22
0
 def text(self, text):
     if self.configured is True:
         width = bge.render.getWindowWidth()
         height = bge.render.getWindowHeight()
         bgl.glMatrixMode(bgl.GL_PROJECTION)
         bgl.glLoadIdentity()
         bgl.gluOrtho2D(0, width, 0, height)
         bgl.glMatrixMode(bgl.GL_MODELVIEW)
         bgl.glLoadIdentity()
         font_id = self.font_id
         blf.position(font_id, 20, 20, 0)
         blf.size(font_id, 300, 300)
         blf.draw(font_id, "Hello World")
コード例 #23
0
	def text( self, text ):
		if self.configured is True:
			width = bge.render.getWindowWidth()
			height = bge.render.getWindowHeight()
			bgl.glMatrixMode(bgl.GL_PROJECTION)
			bgl.glLoadIdentity()
			bgl.gluOrtho2D(0, width, 0, height)
			bgl.glMatrixMode(bgl.GL_MODELVIEW)
			bgl.glLoadIdentity()
			font_id = self.font_id
			blf.position( font_id, 20, 20, 0)
			blf.size( font_id, 300, 300)
			blf.draw( font_id, "Hello World")
コード例 #24
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()
コード例 #25
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()
コード例 #26
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()
コード例 #27
0
    def draw_preview(self):
        bgl.glEnable(bgl.GL_MULTISAMPLE)
        bgl.glEnable(bgl.GL_LINE_SMOOTH)
        bgl.glHint(bgl.GL_LINE_SMOOTH_HINT, bgl.GL_NICEST)
        bgl.glEnable(bgl.GL_BLEND)
        bgl.glEnable(bgl.GL_POINT_SMOOTH)
        bgl.glDisable(bgl.GL_DEPTH_TEST)

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

        # add background gradient
        bgl.glBegin(bgl.GL_TRIANGLES)
        for i in range(0, 360, 10):
            r0, r1 = i * math.pi / 180.0, (i + 10) * math.pi / 180.0
            x0, y0 = math.cos(r0) * 2, math.sin(r0) * 2
            x1, y1 = math.cos(r1) * 2, math.sin(r1) * 2
            bgl.glColor4f(0, 0, 0.01, 0.0)
            bgl.glVertex2f(0, 0)
            bgl.glColor4f(0, 0, 0.01, 0.8)
            bgl.glVertex2f(x0, y0)
            bgl.glVertex2f(x1, y1)
        bgl.glEnd()

        bgl.glMatrixMode(bgl.GL_PROJECTION)
        bgl.glPopMatrix()
        bgl.glMatrixMode(bgl.GL_MODELVIEW)
        bgl.glPopMatrix()
コード例 #28
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()
コード例 #29
0
def draw_console_gl():
    '''draw console with bgl and blf, line by line'''
    # OpenGL setup
    bgl.glMatrixMode(bgl.GL_PROJECTION)
    bgl.glLoadIdentity()
    bgl.gluOrtho2D(0, render.getWindowWidth(), 0, render.getWindowHeight())
    bgl.glMatrixMode(bgl.GL_MODELVIEW)
    bgl.glLoadIdentity()
    # text BLF drawing routine
    for r in logic.rows:
        bgl.glColor4f(r['color'][0], r['color'][1], r['color'][2],
                      1 - r['alpha'])
        blf.position(r['id'], *r['pos'])
        blf.size(r['id'], *r['size'])
        blf.draw(r['id'], r['text'])
コード例 #30
0
ファイル: text.py プロジェクト: TripleSnail/blender-zombie
def write():
    width = bge.render.getWindowWidth()
    height = bge.render.getWindowHeight()

    bgl.glMatrixMode(bgl.GL_PROJECTION)
    bgl.glLoadIdentity()
    bgl.gluOrtho2D(0, width, 0, height)
    bgl.glMatrixMode(bgl.GL_MODELVIEW)
    bgl.glLoadIdentity()

    font_id = bge.logic.font_id

    for text_obj in text_objects:
        blf.position(font_id, width * text_obj.px , height * text_obj.py, 0)
        blf.size(font_id, text_obj.size, DPI)
        blf.draw(font_id, text_obj.text)
コード例 #31
0
    def _drawSelectionBox(self):

        quad = self._getScreenQuad()

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

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

        bgl.glColor3f(1, 0, 0)
        bgl.glBegin(bgl.GL_LINE_LOOP)
        for p in quad:
            bgl.glVertex2f(p.x, p.y)
        bgl.glEnd()
コード例 #32
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()
コード例 #33
0
def write():
    width = bge.render.getWindowWidth()
    height = bge.render.getWindowHeight()

    bgl.glMatrixMode(bgl.GL_PROJECTION)
    bgl.glLoadIdentity()
    bgl.gluOrtho2D(0, width, 0, height)
    bgl.glMatrixMode(bgl.GL_MODELVIEW)
    bgl.glLoadIdentity()

    font_id = bge.logic.font_id

    for text_obj in text_objects:
        blf.position(font_id, width * text_obj.px, height * text_obj.py, 0)
        blf.size(font_id, text_obj.size, DPI)
        blf.draw(font_id, text_obj.text)
コード例 #34
0
def write():
    """write on screen - it runs every frame"""
    width = render.getWindowWidth()
    height = render.getWindowHeight()

    # OpenGL setup
    bgl.glMatrixMode(bgl.GL_PROJECTION)
    bgl.glLoadIdentity()
    bgl.gluOrtho2D(0, width, 0, height)
    bgl.glMatrixMode(bgl.GL_MODELVIEW)
    bgl.glLoadIdentity()

    # BLF fun
    font_id = logic.font_id
    blf.position(font_id, (width*0.2), (height*0.3), 0)
    blf.size(font_id, 50, 72)
    blf.draw(font_id, logic.text["text"])
コード例 #35
0
ファイル: rfmode.py プロジェクト: brendanaaa/Learnbgame
 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()
コード例 #36
0
ファイル: rfmode.py プロジェクト: CGCookie/retopoflow
 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()
コード例 #37
0
def write():
    """write on screen"""
    width = render.getWindowWidth()
    height = render.getWindowHeight()

    # OpenGL setup
    bgl.glMatrixMode(bgl.GL_PROJECTION)
    bgl.glLoadIdentity()
    bgl.gluOrtho2D(0, width, 0, height)
    bgl.glMatrixMode(bgl.GL_MODELVIEW)
    bgl.glLoadIdentity()

    # BLF drawing routine
    font_id = logic.font_id
    blf.position(font_id, (width * 0.2), (height * 0.3), 0)
    blf.size(font_id, 50, 72)
    blf.draw(font_id, "Hello World")
コード例 #38
0
    def draw(self):
        if self.visible == False: return

        module.post_draw_step += 1

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

        bgl.glMatrixMode(bgl.GL_PROJECTION)
        bgl.glLoadIdentity()
        bgl.gluOrtho2D(0, width, 0, height)
        bgl.glMatrixMode(bgl.GL_MODELVIEW)
        bgl.glLoadIdentity()

        # Enable textures
        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)
        bgl.glAlphaFunc(bgl.GL_SRC_ALPHA, 1)

        # Bind the texture
        bgl.glBindTexture(bgl.GL_TEXTURE_2D, self._tex_id)

        # Fix position
        w, h = self._size
        bgl.glTranslatef(0, -h, 1)

        #MipLevel
        bgl.glTexParameteri(bgl.GL_TEXTURE_2D, bgl.GL_TEXTURE_BASE_LEVEL, 0)
        bgl.glTexParameteri(bgl.GL_TEXTURE_2D, bgl.GL_TEXTURE_MAX_LEVEL, 0)
        bgl.glTexParameteri(bgl.GL_TEXTURE_2D, bgl.GL_TEXTURE_MIN_FILTER,
                            bgl.GL_LINEAR)
        bgl.glTexParameteri(bgl.GL_TEXTURE_2D, bgl.GL_TEXTURE_MAG_FILTER,
                            bgl.GL_LINEAR)

        # Draw the textured quad
        bgl.glColor4f(*self.color)

        bgl.glBegin(bgl.GL_QUADS)
        self.calculate_glposition()
        for i in range(4):
            bgl.glTexCoord2f(self.texco[i][0], self.texco[i][1])
            bgl.glVertex2f(self.gl_position[i][0], self.gl_position[i][1])
        bgl.glEnd()

        bgl.glBindTexture(bgl.GL_TEXTURE_2D, 0)

        bgl.glDisable(bgl.GL_BLEND)
        bgl.glDisable(bgl.GL_TEXTURE_2D)

        bgl.glMatrixMode(bgl.GL_PROJECTION)
        bgl.glPopMatrix()
        bgl.glMatrixMode(bgl.GL_MODELVIEW)
コード例 #39
0
ファイル: base.py プロジェクト: mistajuliax/blender-vr
    def _setModelViewMatrix(self, camera, matrix):
        from bgl import (
                Buffer,
                GL_FLOAT,
                GL_MODELVIEW,
                glMatrixMode,
                glLoadMatrixf,
                )

        matrix *= camera.modelview_matrix
        buf = Buffer(GL_FLOAT, [4, 4])
        for i in range(4):
            for j in range(4):
                # transposed
                buf[i][j] = matrix[j][i]

        glMatrixMode(GL_MODELVIEW)
        glLoadMatrixf(buf)
コード例 #40
0
def write():
	''' Uses text buffer for rendering stuff on screen
	
	Text buffer can be found from logic.text_buffer
	Each value in buffer is a hash, containing text, timeout and start_time
	start time is set by me, not you
	'''

	"""write on screen"""
	width = render.getWindowWidth()
	height = render.getWindowHeight()

	# OpenGL setup
	bgl.glMatrixMode(bgl.GL_PROJECTION)
	bgl.glLoadIdentity()
	bgl.gluOrtho2D(0, width, 0, height)
	bgl.glMatrixMode(bgl.GL_MODELVIEW)
	bgl.glLoadIdentity()

	show_das_points()

	if logic.text_buffer == None or len(logic.text_buffer) == 0:
		return
	
	text = ''
	
	# has the current value start time
	if 'start_time' in logic.text_buffer[0]:
		start_time = logic.text_buffer[0]['start_time']
		current_time = current_milli_time()
		timeout = logic.text_buffer[0]['timeout']
		if start_time + timeout < current_milli_time():
			logic.text_buffer.pop(0)
		else:
			text = logic.text_buffer[0]['text']
	else:
		logic.text_buffer[0]['start_time'] = current_milli_time()
		text = logic.text_buffer[0]['text']

	# BLF drawing routine
	font_id = logic.font_id
	blf.position(font_id, (width * 0.25), (height * 0.5), 0)
	blf.size(font_id, 24, 72)
	blf.draw(font_id, text)
コード例 #41
0
ファイル: window.py プロジェクト: Hubber116sx/BGECore
	def draw(self):
		if self.visible == False: return
		
		module.post_draw_step += 1
		
		height = render.getWindowHeight()
		width = render.getWindowWidth()
	
		bgl.glMatrixMode(bgl.GL_PROJECTION)
		bgl.glLoadIdentity()
		bgl.gluOrtho2D(0, width, 0, height)
		bgl.glMatrixMode(bgl.GL_MODELVIEW)
		bgl.glLoadIdentity()
	
		# Enable textures
		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)
		bgl.glAlphaFunc(bgl.GL_SRC_ALPHA, 1)

		# Bind the texture
		bgl.glBindTexture(bgl.GL_TEXTURE_2D, self._tex_id)

		# Fix position
		w, h = self._size
		bgl.glTranslatef(0, -h, 1)

		#MipLevel
		bgl.glTexParameteri(bgl.GL_TEXTURE_2D, bgl.GL_TEXTURE_BASE_LEVEL, 0);
		bgl.glTexParameteri(bgl.GL_TEXTURE_2D, bgl.GL_TEXTURE_MAX_LEVEL, 0);
		bgl.glTexParameteri(bgl.GL_TEXTURE_2D, bgl.GL_TEXTURE_MIN_FILTER, bgl.GL_LINEAR);
		bgl.glTexParameteri(bgl.GL_TEXTURE_2D, bgl.GL_TEXTURE_MAG_FILTER, bgl.GL_LINEAR);
		
		# Draw the textured quad
		bgl.glColor4f(*self.color)

		bgl.glBegin(bgl.GL_QUADS)
		self.calculate_glposition()
		for i in range(4):
			bgl.glTexCoord2f(self.texco[i][0], self.texco[i][1])
			bgl.glVertex2f(self.gl_position[i][0], self.gl_position[i][1])
		bgl.glEnd()

		bgl.glBindTexture(bgl.GL_TEXTURE_2D, 0)
		
		bgl.glDisable(bgl.GL_BLEND)
		bgl.glDisable(bgl.GL_TEXTURE_2D)

		bgl.glMatrixMode(bgl.GL_PROJECTION)
		bgl.glPopMatrix()
		bgl.glMatrixMode(bgl.GL_MODELVIEW)
コード例 #42
0
ファイル: text.py プロジェクト: leomuona/RBS2013
def write():
    ''' Uses text buffer for rendering stuff on screen
	
	Text buffer can be found from logic.text_buffer
	Each value in buffer is a hash, containing text, timeout and start_time
	start time is set by me, not you
	'''
    """write on screen"""
    width = render.getWindowWidth()
    height = render.getWindowHeight()

    # OpenGL setup
    bgl.glMatrixMode(bgl.GL_PROJECTION)
    bgl.glLoadIdentity()
    bgl.gluOrtho2D(0, width, 0, height)
    bgl.glMatrixMode(bgl.GL_MODELVIEW)
    bgl.glLoadIdentity()

    show_das_points()

    if logic.text_buffer == None or len(logic.text_buffer) == 0:
        return

    text = ''

    # has the current value start time
    if 'start_time' in logic.text_buffer[0]:
        start_time = logic.text_buffer[0]['start_time']
        current_time = current_milli_time()
        timeout = logic.text_buffer[0]['timeout']
        if start_time + timeout < current_milli_time():
            logic.text_buffer.pop(0)
        else:
            text = logic.text_buffer[0]['text']
    else:
        logic.text_buffer[0]['start_time'] = current_milli_time()
        text = logic.text_buffer[0]['text']

    # BLF drawing routine
    font_id = logic.font_id
    blf.position(font_id, (width * 0.25), (height * 0.5), 0)
    blf.size(font_id, 24, 72)
    blf.draw(font_id, text)
コード例 #43
0
def write_interaction_status():
    """
    Write the interaction status on Screen
    The status is stored in a property
    """
    hand = objects["Hand_Grab.R"]

    # OpenGL setup
    bgl.glMatrixMode(bgl.GL_PROJECTION)
    bgl.glLoadIdentity()
    bgl.gluOrtho2D(0, windowWidth, 0, windowHeight)
    bgl.glMatrixMode(bgl.GL_MODELVIEW)
    bgl.glLoadIdentity()

    blf.size(font_id, int(windowHeight * 0.04), 72)
    # draw a black shadow around the text
    blf.enable(font_id, blf.SHADOW)
    blf.shadow(font_id, 5, 0.0, 0.0, 0.0, 1.0)
    blf.position(font_id, windowWidth * 0.4, windowHeight * 0.4, 0)
    blf.draw(font_id, hand["Status"])
コード例 #44
0
    def afficher(self):
        """Affiche l'image"""
        VT = __class__.VT
        gl = __class__.gl
        bgl = __class__.bgl
        math = __class__.math

        if self.ok:

            id = self.VT_img.bindId

            if id:
                bgl.glMatrixMode(bgl.GL_PROJECTION)
                bgl.glLoadIdentity()
                vp = self.viewport
                bgl.glOrtho(vp[0], vp[1], vp[2], vp[3], -1.0, 1.0)

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

                bgl.glEnable(bgl.GL_TEXTURE_2D)
                bgl.glEnable(bgl.GL_BLEND)
                bgl.glBindTexture(bgl.GL_TEXTURE_2D, id)

                bgl.glTranslatef(self.bary[0], self.bary[1], 0)
                bgl.glRotatef(math.degrees(self.angle), 0.0, 0.0, 1.0)
                bgl.glTranslatef(-self.bary[0], -self.bary[1], 0)

                bgl.glBegin(bgl.GL_QUADS)
                col = self.couleur
                for i in range(len(self.texco)):
                    bgl.glColor4f(col[0], col[1], col[2], col[3])
                    bgl.glTexCoord2f(self.texco[i][0], self.texco[i][1])
                    bgl.glVertex2f(self.verco[i][0], self.verco[i][1])
                bgl.glEnd()

                bgl.glBindTexture(bgl.GL_TEXTURE_2D, 0)
            else:
                self.ok = False

        return
コード例 #45
0
def write():
    """write on screen"""
    width = render.getWindowWidth()
    height = render.getWindowHeight()

    # OpenGL setup
    bgl.glMatrixMode(bgl.GL_PROJECTION)
    bgl.glLoadIdentity()
    bgl.gluOrtho2D(0, width, 0, height)
    bgl.glMatrixMode(bgl.GL_MODELVIEW)
    bgl.glLoadIdentity()
    
    bgl.glColor4f(1, 1, 1, 1)
    
    cam = logic.getCurrentScene().active_camera
    t = cam["Timer"]
    c = timer - t
    bgl.glColor4f(1, 1, 1, c)
    if cam["Switch"]:
        cam["Index"] += 1
        cam["Timer"] = 0
        cam["Switch"] = False
    # BLF drawing routine
    font_id = logic.font_id
    font_id_italic = logic.font_id_italic
    blf.position(font_id, width*0.03, height * 0.05, 0)
    blf.position(font_id_italic, width*0.03, height * 0.05, 0)
    blf.size(font_id, int(18 * (width/dpi) * 0.062), dpi)
    blf.size(font_id_italic, int(18 * (width/dpi) * 0.062), dpi)
    if cam["Index"] < 4:
        blf.draw(font_id, text[cam["Index"]])
    elif cam["Index"] < len(text):
        blf.draw(font_id_italic, text[cam["Index"]])
    
    # skip
    if cam["Index"] < 1:
        bgl.glColor4f(0.5, 0.5, 0.5, c)
        blf.position(font_id, width*0.02, height*0.9, 0)

        blf.draw(font_id, skip)
コード例 #46
0
ファイル: vagl.py プロジェクト: yazici/blenderpython
    def window_pixel_space(self):
        """with文、又はデコレータとして使用
        :rtype: GCM
        """

        win_width, win_height = self.window_size

        modelview_mat = Buffer('double', (4, 4), bgl.GL_MODELVIEW_MATRIX)
        projection_mat = Buffer('double', (4, 4), bgl.GL_PROJECTION_MATRIX)
        matrix_mode = Buffer('int', 1, bgl.GL_MATRIX_MODE)
        viewport = Buffer('int', 4, bgl.GL_VIEWPORT)

        bgl.glViewport(0, 0, win_width, win_height)
        bgl.glMatrixMode(bgl.GL_PROJECTION)
        bgl.glLoadIdentity()
        ofs = -0.01
        bgl.glOrtho(ofs, win_width + ofs, ofs, win_height + ofs, -100, 100)
        bgl.glMatrixMode(bgl.GL_MODELVIEW)
        bgl.glLoadIdentity()
        bgl.glMatrixMode(matrix_mode[0])

        try:
            yield
        finally:
            bgl.glViewport(*viewport)
            self._load_matrix(modelview_mat, projection_mat)
コード例 #47
0
ファイル: vagl.py プロジェクト: JuhaW/blender_ctools
    def region_pixel_space(self):
        """with文、又はデコレータとして使用

        NOTE: Z値の範囲: near 〜 far
        perspective_matrix * vec4d / w: -1.0 〜 +1.0
        gluProject: 0.0 〜 +1.0
        POST_PIXEL: +100 〜 -100
        Z-Buffer: 0.0 〜 +1.0
        :rtype: GCM
        """

        modelview_mat = Buffer('double', (4, 4), bgl.GL_MODELVIEW_MATRIX)
        projection_mat = Buffer('double', (4, 4), bgl.GL_PROJECTION_MATRIX)
        matrix_mode = Buffer('int', 1, bgl.GL_MATRIX_MODE)

        bgl.glMatrixMode(bgl.GL_PROJECTION)
        bgl.glLoadIdentity()  # 必須
        w, h = self.region_size
        # wmOrtho2_region_pixelspace(), wmOrtho2() 参照
        ofs = -0.01
        bgl.glOrtho(ofs, w + ofs, ofs, h + ofs, -100, 100)

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

        bgl.glMatrixMode(matrix_mode[0])

        try:
            yield
        finally:
            self._load_matrix(modelview_mat, projection_mat)
コード例 #48
0
ファイル: vagl.py プロジェクト: JuhaW/blender_ctools
    def window_pixel_space(self):
        """with文、又はデコレータとして使用
        :rtype: GCM
        """

        win_width, win_height = self.window_size

        modelview_mat = Buffer('double', (4, 4), bgl.GL_MODELVIEW_MATRIX)
        projection_mat = Buffer('double', (4, 4), bgl.GL_PROJECTION_MATRIX)
        matrix_mode = Buffer('int', 1, bgl.GL_MATRIX_MODE)
        viewport = Buffer('int', 4, bgl.GL_VIEWPORT)

        bgl.glViewport(0, 0, win_width, win_height)
        bgl.glMatrixMode(bgl.GL_PROJECTION)
        bgl.glLoadIdentity()
        ofs = -0.01
        bgl.glOrtho(ofs, win_width + ofs, ofs, win_height + ofs, -100, 100)
        bgl.glMatrixMode(bgl.GL_MODELVIEW)
        bgl.glLoadIdentity()
        bgl.glMatrixMode(matrix_mode[0])

        try:
            yield
        finally:
            bgl.glViewport(*viewport)
            self._load_matrix(modelview_mat, projection_mat)
コード例 #49
0
ファイル: vagl.py プロジェクト: yazici/blenderpython
    def region_pixel_space(self):
        """with文、又はデコレータとして使用

        NOTE: Z値の範囲: near 〜 far
        perspective_matrix * vec4d / w: -1.0 〜 +1.0
        gluProject: 0.0 〜 +1.0
        POST_PIXEL: +100 〜 -100
        Z-Buffer: 0.0 〜 +1.0
        :rtype: GCM
        """

        modelview_mat = Buffer('double', (4, 4), bgl.GL_MODELVIEW_MATRIX)
        projection_mat = Buffer('double', (4, 4), bgl.GL_PROJECTION_MATRIX)
        matrix_mode = Buffer('int', 1, bgl.GL_MATRIX_MODE)

        bgl.glMatrixMode(bgl.GL_PROJECTION)
        bgl.glLoadIdentity()  # 必須
        w, h = self.region_size
        # wmOrtho2_region_pixelspace(), wmOrtho2() 参照
        ofs = -0.01
        bgl.glOrtho(ofs, w + ofs, ofs, h + ofs, -100, 100)

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

        bgl.glMatrixMode(matrix_mode[0])

        try:
            yield
        finally:
            self._load_matrix(modelview_mat, projection_mat)
コード例 #50
0
ファイル: vagl.py プロジェクト: JT-a/blenderpython
    def prepare_2d(self):
        """PRE_VIEW,POST_VIEWのcallbackでscreen座標系を用いて描画する場合に
        使用する。
        参照: ED_region_do_draw() -> ED_region_pixelspace() ->
        wmOrtho2_region_pixelspace()

        """
        self._modelview_bak_2d = Buffer('double', (4, 4),
                                        bgl.GL_MODELVIEW_MATRIX)
        self._projection_bak_2d = Buffer('double', (4, 4),
                                         bgl.GL_PROJECTION_MATRIX)
        matrix_mode = Buffer('int', 0, bgl.GL_MATRIX_MODE)

        bgl.glMatrixMode(bgl.GL_PROJECTION)
        bgl.glLoadIdentity()  # 必須
        w, h = self.region_size
        # wmOrtho2_region_pixelspace(), wmOrtho2() 参照
        ofs = -0.01
        bgl.glOrtho(ofs, w + ofs, ofs, h + ofs, -100, 100)
        # bgl.glTranslated(GLA_PIXEL_OFS, GLA_PIXEL_OFS, 0.0)

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

        bgl.glMatrixMode(matrix_mode)
コード例 #51
0
ファイル: interaction.py プロジェクト: sylvestre/morse
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()
コード例 #52
0
ファイル: show_objects.py プロジェクト: DefaultUser/morse
def write():
    """
    Write the name of all active objects on Screen
    """
    # OpenGL setup
    bgl.glMatrixMode(bgl.GL_PROJECTION)
    bgl.glLoadIdentity()
    bgl.gluOrtho2D(0, windowWidth, 0, windowHeight)
    bgl.glMatrixMode(bgl.GL_MODELVIEW)
    bgl.glLoadIdentity()
    
    cam = scene.active_camera

    for obj in passive_objects.active_objects():
        # test if the object is in the view frustum
        if cam.pointInsideFrustum(obj.worldPosition):
            pos = cam.getScreenPosition(obj)
    
            blf.size(font_id, int(windowWidth * 0.02), 72)
            # draw a black shadow to increase contrast with white parts
            blf.enable(font_id, blf.SHADOW)
            blf.shadow(font_id, 5, 0.0, 0.0, 0.0, 1.0)
            blf.position(font_id, pos[0]*windowWidth, (1 - pos[1])*windowHeight,0)
            blf.draw(font_id, obj.name)
コード例 #53
0
ファイル: Tutorial_Script.py プロジェクト: DefaultUser/morse
def write():
    """write on screen"""
    width = render.getWindowWidth()
    height = render.getWindowHeight()

    # OpenGL setup
    bgl.glMatrixMode(bgl.GL_PROJECTION)
    bgl.glLoadIdentity()
    bgl.gluOrtho2D(0, width, 0, height)
    bgl.glMatrixMode(bgl.GL_MODELVIEW)
    bgl.glLoadIdentity()

    # BLF drawing routine
    blf.size(font_id, height//40, 72)
    data = parse_file.read_file()
    data = data.splitlines()
    linePosition = height * 0.8
    for str in data:
        str_len = len(str)
        blf.position(font_id, (width * 0.05), linePosition, 0)
        blf.enable(font_id, blf.SHADOW)
        blf.shadow(font_id, 0, 1.0, 0.2, 0.0, 1.0)
        blf.draw(font_id,str)
        linePosition -= height * 0.05
コード例 #54
0
ファイル: vagl.py プロジェクト: JT-a/blenderpython
 def _load_matrix(self, modelview=None, projection=None):
     matrix_mode = Buffer('int', 0, bgl.GL_MATRIX_MODE)
     if modelview:
         bgl.glMatrixMode(bgl.GL_MODELVIEW)
         bgl.glLoadIdentity()  # glLoadMatrix()にも必須
         if isinstance(modelview, bgl.Buffer):
             bgl.glLoadMatrixd(modelview)
     if projection:
         bgl.glMatrixMode(bgl.GL_PROJECTION)
         bgl.glLoadIdentity()  # glLoadMatrix()にも必須
         if isinstance(projection, bgl.Buffer):
             bgl.glLoadMatrixd(projection)
     bgl.glMatrixMode(matrix_mode)
コード例 #55
0
ファイル: interaction.py プロジェクト: sylvestre/morse
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()
コード例 #56
0
ファイル: TextEffect.py プロジェクト: griusfux/conceptrpg2
	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()
コード例 #57
0
def draw_measurements_callback(self, context):
    sce = context.scene

    draw = 0
    if hasattr(sce, "measure_panel_draw"):
        draw = sce.measure_panel_draw

    # 2D drawing code example
    #bgl.glBegin(bgl.GL_LINE_STRIP)
    #bgl.glVertex2i(0, 0)
    #bgl.glVertex2i(80, 100)
    #bgl.glEnd()

    # Get measured 3D points and colors.
    line = getMeasurePoints(context)
    if (line and draw):
        p1, p2, color = line

        # Get and convert the Perspective Matrix of the current view/region.
        view3d = bpy.context
        region = view3d.region_data
        perspMatrix = region.perspective_matrix
        tempMat = [perspMatrix[i][j] for i in range(4) for j in range(4)]
        perspBuff = bgl.Buffer(bgl.GL_FLOAT, 16, tempMat)

        # ---
        # Store previous OpenGL settings.
        # Store MatrixMode
        MatrixMode_prev = bgl.Buffer(bgl.GL_INT, [1])
        bgl.glGetIntegerv(bgl.GL_MATRIX_MODE, MatrixMode_prev)
        MatrixMode_prev = MatrixMode_prev[0]

        # Store projection matrix
        ProjMatrix_prev = bgl.Buffer(bgl.GL_DOUBLE, [16])
        bgl.glGetFloatv(bgl.GL_PROJECTION_MATRIX, ProjMatrix_prev)

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

        # Store GL_BLEND
        blend_prev = bgl.Buffer(bgl.GL_BYTE, [1])
        bgl.glGetFloatv(bgl.GL_BLEND, blend_prev)
        blend_prev = blend_prev[0]

        line_stipple_prev = bgl.Buffer(bgl.GL_BYTE, [1])
        bgl.glGetFloatv(bgl.GL_LINE_STIPPLE, line_stipple_prev)
        line_stipple_prev = line_stipple_prev[0]

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

        # ---
        # Prepare for 3D drawing
        bgl.glLoadIdentity()
        bgl.glMatrixMode(bgl.GL_PROJECTION)
        bgl.glLoadMatrixf(perspBuff)

        bgl.glEnable(bgl.GL_BLEND)
        bgl.glEnable(bgl.GL_LINE_STIPPLE)

        # ---
        # Draw 3D stuff.
        width = 1
        bgl.glLineWidth(width)
        # X
        bgl.glColor4f(1, 0, 0, 0.8)
        bgl.glBegin(bgl.GL_LINE_STRIP)
        bgl.glVertex3f(p1[0], p1[1], p1[2])
        bgl.glVertex3f(p2[0], p1[1], p1[2])
        bgl.glEnd()
        # Y
        bgl.glColor4f(0, 1, 0, 0.8)
        bgl.glBegin(bgl.GL_LINE_STRIP)
        bgl.glVertex3f(p1[0], p1[1], p1[2])
        bgl.glVertex3f(p1[0], p2[1], p1[2])
        bgl.glEnd()
        # Z
        bgl.glColor4f(0, 0, 1, 0.8)
        bgl.glBegin(bgl.GL_LINE_STRIP)
        bgl.glVertex3f(p1[0], p1[1], p1[2])
        bgl.glVertex3f(p1[0], p1[1], p2[2])
        bgl.glEnd()

        # Dist
        width = 2
        bgl.glLineWidth(width)
        bgl.glColor4f(color[0], color[1], color[2], color[3])
        bgl.glBegin(bgl.GL_LINE_STRIP)
        bgl.glVertex3f(p1[0], p1[1], p1[2])
        bgl.glVertex3f(p2[0], p2[1], p2[2])
        bgl.glEnd()

        # ---
        # Restore previous OpenGL settings
        bgl.glLoadIdentity()
        bgl.glMatrixMode(MatrixMode_prev)
        bgl.glLoadMatrixf(ProjMatrix_prev)
        bgl.glLineWidth(lineWidth_prev)
        if not blend_prev:
            bgl.glDisable(bgl.GL_BLEND)
        if not line_stipple_prev:
            bgl.glDisable(bgl.GL_LINE_STIPPLE)
        bgl.glColor4f(color_prev[0],
            color_prev[1],
            color_prev[2],
            color_prev[3])

        # ---
        # Draw (2D) text
        # We do this after drawing the lines so
        # we can draw it OVER the line.
        coord_2d = location_3d_to_region_2d(context.region,
                                            context.space_data.region_3d,
                                            p1.lerp(p2, 0.5),
                                            )
        OFFSET_LINE = 10   # Offset the text a bit to the right.
        OFFSET_Y = 15      # Offset of the lines.
        OFFSET_VALUE = 30  # Offset of value(s) from the text.
        dist = (p1 - p2).length

        # Write distance value into the scene property,
        # so we can display it in the panel & refresh the panel.
        if hasattr(sce, "measure_panel_dist"):
            sce.measure_panel_dist = dist
            context.area.tag_redraw()

        texts = [("Dist:", round(dist, PRECISION)),
            ("X:", round(abs(p1[0] - p2[0]), PRECISION)),
            ("Y:", round(abs(p1[1] - p2[1]), PRECISION)),
            ("Z:", round(abs(p1[2] - p2[2]), PRECISION))]

        # Draw all texts
        # @todo Get user pref for text color in 3D View
        bgl.glColor4f(1.0, 1.0, 1.0, 1.0)
        blf.size(0, 12, 72)  # Prevent font size to randomly change.

        loc_x = coord_2d[0] + OFFSET_LINE
        loc_y = coord_2d[1]
        for t in texts:
            text = t[0]
            value = str(t[1]) + " BU"

            blf.position(0, loc_x, loc_y, 0)
            blf.draw(0, text)
            blf.position(0, loc_x + OFFSET_VALUE, loc_y, 0)
            blf.draw(0, value)

            loc_y -= OFFSET_Y

    # Handle mesh surface area calulations
    if (sce.measure_panel_calc_area):
        # Get a single selected object (or nothing).
        obj = getSingleObject(context)

        if (context.mode == 'EDIT_MESH'):
            obj = context.active_object

            if (obj and obj.type == 'MESH' and obj.data):
                # "Note: a Mesh will return the selection state of the mesh
                # when EditMode was last exited. A Python script operating
                # in EditMode must exit EditMode before getting the current
                # selection state of the mesh."
                # http://www.blender.org/documentation/249PythonDoc/
                # /Mesh.MVert-class.html#sel
                # We can only provide this by existing & re-entering EditMode.
                # @todo: Better way to do this?

                # Get mesh data from Object.
                mesh = obj.data

                # Get transformation matrix from object.
                ob_mat = obj.matrix_world
                # Also make an inversed copy! of the matrix.
                ob_mat_inv = ob_mat.copy()
                Matrix.invert(ob_mat_inv)

                # Get the selected vertices.
                # @todo: Better (more efficient) way to do this?
                verts_selected = [v for v in mesh.vertices if v.select == 1]

                if len(verts_selected) >= 3:
                    # Get selected faces
                    # @todo: Better (more efficient) way to do this?
                    faces_selected = [f for f in mesh.faces
                        if f.select == 1]

                    if len(faces_selected) > 0:
                        area, normal = objectSurfaceArea(obj, True,
                            measureGlobal(sce))
                        if (area >= 0):
                            sce.measure_panel_area1 = area
                            sce.measure_panel_normal1 = normal

        elif (context.mode == 'OBJECT'):
            # We are working in object mode.

            if len(context.selected_objects) > 2:
                return
# @todo Make this work again.
#                # We have more that 2 objects selected...
#
#                mesh_objects = [o for o in context.selected_objects
#                    if (o.type == 'MESH')]

#                if (len(mesh_objects) > 0):
#                    # ... and at least one of them is a mesh.
#
#                    for o in mesh_objects:
#                        area = objectSurfaceArea(o, False,
#                            measureGlobal(sce))
#                        if (area >= 0):
#                            #row.label(text=o.name, icon='OBJECT_DATA')
#                            #row.label(text=str(round(area, PRECISION))
#                            #    + " BU^2")

            elif len(context.selected_objects) == 2:
                # 2 objects selected.

                obj1, obj2 = context.selected_objects

                # Calculate surface area of the objects.
                area1, normal1 = objectSurfaceArea(obj1, False,
                    measureGlobal(sce))
                area2, normal2 = objectSurfaceArea(obj2, False,
                    measureGlobal(sce))
                sce.measure_panel_area1 = area1
                sce.measure_panel_area2 = area2
                sce.measure_panel_normal1 = normal1
                sce.measure_panel_normal2 = normal2

            elif (obj):
                # One object selected.

                # Calculate surface area of the object.
                area, normal = objectSurfaceArea(obj, False,
                    measureGlobal(sce))

                if (area >= 0):
                    sce.measure_panel_area1 = area
                    sce.measure_panel_normal1 = normal

    if (sce.measure_panel_calc_volume):
        obj = getSingleObject(context)

        if (context.mode == 'OBJECT'):
            # We are working in object mode.

            #if len(context.selected_objects) > 2:       # TODO

            #el
            if len(context.selected_objects) == 2:
                # 2 objects selected.

                obj1, obj2 = context.selected_objects

                # Calculate surface area of the objects.
                volume1 = objectVolume(obj1, measureGlobal(sce))
                volume2 = objectVolume(obj2, measureGlobal(sce))

                sce.measure_panel_volume1 = volume1
                sce.measure_panel_volume2 = volume2

            elif (obj):
                # One object selected.

                # Calculate surface area of the object.
                volume1 = objectVolume(obj, measureGlobal(sce))

                sce.measure_panel_volume1 = volume1
コード例 #58
0
ファイル: __init__.py プロジェクト: JuhaW/blender_ctools
def window_space(win):
    modelview_mat = bgl.Buffer(bgl.GL_DOUBLE, 16)
    projection_mat = bgl.Buffer(bgl.GL_DOUBLE, 16)
    bgl.glGetDoublev(bgl.GL_MODELVIEW_MATRIX, modelview_mat)
    bgl.glGetDoublev(bgl.GL_PROJECTION_MATRIX, projection_mat)

    matrix_mode = bgl.Buffer(bgl.GL_INT, 1)
    bgl.glGetIntegerv(bgl.GL_MATRIX_MODE, matrix_mode)

    viewport = bgl.Buffer(bgl.GL_INT, 4)
    bgl.glGetIntegerv(bgl.GL_VIEWPORT, viewport)

    bgl.glViewport(0, 0, win.width, win.height)
    bgl.glMatrixMode(bgl.GL_PROJECTION)
    bgl.glLoadIdentity()
    ofs = -0.01
    bgl.glOrtho(ofs, win.width + ofs, ofs, win.height + ofs, -100, 100)
    bgl.glMatrixMode(bgl.GL_MODELVIEW)
    bgl.glLoadIdentity()
    bgl.glMatrixMode(matrix_mode[0])

    yield

    bgl.glViewport(*viewport)

    bgl.glMatrixMode(bgl.GL_PROJECTION)
    bgl.glLoadMatrixd(projection_mat)
    bgl.glMatrixMode(bgl.GL_MODELVIEW)
    bgl.glLoadMatrixd(modelview_mat)
    bgl.glMatrixMode(matrix_mode[0])
コード例 #59
0
    def render(self, context):
        # needed???
        if context.region.id == self.region_id:
            # just hide the cursor...
            context.space_data.cursor_location = [0.0, 0.0, 10.0]
            context.space_data.region_3d.view_matrix = Matrix.Identity(4)
            
            w = context.region.width
            h = context.region.height
            
            x1, x2, x3, x4, y1, y2, y3, y4 = self.grid(w, h)
                       
            bgl.glMatrixMode(bgl.GL_PROJECTION)
            bgl.glLoadIdentity()
            bgl.gluOrtho2D(0, w, 0, h)
            bgl.glMatrixMode(bgl.GL_MODELVIEW)
            bgl.glLoadIdentity()
            
            bgl.glColor3f(*self.COLOR_BOARD)
            bgl.glLineWidth(2.0)
            bgl.glBegin(bgl.GL_LINES)
            for x in (x1, x2, x3, x4):
                bgl.glVertex3f(x, y1, 0.0)
                bgl.glVertex3f(x, y4, 0.0)
            for y in (y1, y2, y3, y4):
                bgl.glVertex3f(x1, y, 0.0)
                bgl.glVertex3f(x4, y, 0.0)
            bgl.glEnd()

            xs = (x1, x2, x3, x4)
            ys = (y1, y2, y3, y4)
            
            bgl.glLineWidth(8.0)
            bgl.glBegin(bgl.GL_LINES)
            for i in range(3):
                for j in range(3):
                    c = self.board[i][j]
                    xa = xs[i]
                    xb = xs[i + 1]
                    ya = ys[j]
                    yb = ys[j + 1]

                    if c == self.PLAYER:
                        if self.computer_has_x:
                            self.drawO(xa, xb, ya, yb)
                        else:
                            self.drawX(xa, xb, ya, yb)
                    elif c == self.COMPUTER:
                        if self.computer_has_x:
                            self.drawX(xa, xb, ya, yb)
                        else:
                            self.drawO(xa, xb, ya, yb)
            bgl.glEnd()

            bgl.glLineWidth(1.0)
            bgl.glColor3f(*self.COLOR_FONT)

            xp, yp = self.fontPosition(w, h)
            blf.position(0, xp, yp, 0)
            blf.size(0, 50, 72)

            if self.winner == self.COMPUTER:
                blf.draw(0, "You loose!")

            elif self.winner == self.PLAYER:
                blf.draw(0, "You win!")

            elif self.round == self.NONE:
                blf.draw(0, "Draw.")