예제 #1
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()
예제 #2
0
    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)
예제 #3
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)
예제 #4
0
    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()
예제 #5
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")
예제 #6
0
    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)
예제 #7
0
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))
예제 #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")
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'])
예제 #10
0
    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)
예제 #11
0
    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)
예제 #12
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()
예제 #13
0
    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)
예제 #14
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)
예제 #15
0
    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)
예제 #16
0
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])
예제 #17
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")
예제 #18
0
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])
예제 #19
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()
예제 #20
0
    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)
예제 #21
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()
예제 #22
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)
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()
예제 #24
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!")
예제 #25
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()
예제 #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 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!")
예제 #28
0
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'])
예제 #29
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)
예제 #30
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)
예제 #31
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()
예제 #32
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()
예제 #33
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)
예제 #34
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)
예제 #35
0
def draw_names():
    # Get font id to use
    font_id = logic.font_id

    # Collect viewport information
    width = render.getWindowWidth()
    height = render.getWindowHeight()

    # Setup the OpenGL matrices
    bgl.glMatrixMode(bgl.GL_PROJECTION)
    bgl.glPushMatrix()
    bgl.glLoadIdentity()
    bgl.gluOrtho2D(0, width, 0, height)

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

    # Get the camera
    scene = logic.getCurrentScene()
    camera = scene.active_camera

    # draw the name only for objects (not for lamps or camera)
    for object in [
            i for i in scene.objects if i.__class__ == types.KX_GameObject
    ]:
        # Calculate x and y
        screen_coord = camera.getScreenPosition(object)
        x = screen_coord[0] * render.getWindowWidth()
        y = render.getWindowHeight() - (screen_coord[1] *
                                        render.getWindowHeight())

        # Center the x
        text_width, text_height = blf.dimensions(0, object.name)
        x -= text_width / 2

        # Calculate the amount to scale the font
        distance = camera.getDistanceTo(object)

        if FAR - distance > 0:
            scale = (FAR - distance) / FAR
        else:
            scale = 0

        # Only draw if we'll be able to see it
        if scale:
            blf.size(font_id, int(FONT_SIZE * scale), 72)
            blf.position(font_id, x, y, 0)
            blf.draw(font_id, object.name)

    # Reset the matrices
    bgl.glPopMatrix()
    bgl.glMatrixMode(bgl.GL_PROJECTION)
    bgl.glPopMatrix()
예제 #36
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)
예제 #37
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)
예제 #38
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)
예제 #39
0
 def _load_matrix(cls, 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)
예제 #40
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")
 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")
def color_placing():
    """
    Draw the green rectangle via OpenGL-Wrapper
    """
    imageHeight = windowHeight * 0.05
    imageWidth = imageHeight

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

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

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

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

    bgl.glPopMatrix()
    bgl.glMatrixMode(bgl.GL_PROJECTION)
    bgl.glPopMatrix()
    bgl.glPopAttrib()
예제 #43
0
def 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()
예제 #44
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'])
예제 #45
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)
예제 #46
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()
예제 #47
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()
예제 #48
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)
예제 #49
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()
예제 #50
0
파일: blf.py 프로젝트: 3DGEOM/Blender
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")
예제 #51
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)
예제 #52
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"])
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)
예제 #54
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
    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
예제 #55
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)
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
    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.")
예제 #58
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
예제 #59
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()
예제 #60
0
    def draw(self, area, region_data):
        """
        Draw avatar view in given context
        """
        # TODO: Add this color to addon option
        color = (1.0, 1.0, 0.5, 1.0)
        alpha = 2.0*math.atan((18.0/2.0)/self.lens.value[0])
        dist = 0.5/(math.tan(alpha/2.0))
        height = 1.0
        if self.height.value[0] == 0:
            width = 0.7
        else:
            width = self.width.value[0]/self.height.value[0]
                    
        points = {}
        points['border'] = [None, None, None, None]
        points['center'] = [None]
        
        # Points of face
        points['right_eye'] = [mathutils.Vector((0.25, 0.25, self.distance.value[0] - dist)), \
            mathutils.Vector((0.3, 0.25, self.distance.value[0] - dist)), \
            mathutils.Vector((0.3, 0.0, self.distance.value[0] - dist)), \
            mathutils.Vector((0.25, 0.0, self.distance.value[0] - dist)), \
            mathutils.Vector((0.25, 0.25, self.distance.value[0] - dist))]
        points['left_eye'] = [mathutils.Vector((-0.25, 0.25, self.distance.value[0] - dist)), \
            mathutils.Vector((-0.3, 0.25, self.distance.value[0] - dist)), \
            mathutils.Vector((-0.3, 0.0, self.distance.value[0] - dist)), \
            mathutils.Vector((-0.25, 0.0, self.distance.value[0] - dist)), \
            mathutils.Vector((-0.25, 0.25, self.distance.value[0] - dist))]
        
        points['mouth'] = [mathutils.Vector((-0.40912365913391113, -0.11777058243751526, self.distance.value[0] - dist)), \
            mathutils.Vector((-0.3441678285598755, -0.15873458981513977, self.distance.value[0] - dist)), \
            mathutils.Vector((-0.2563667893409729, -0.1998385488986969, self.distance.value[0] - dist)), \
            mathutils.Vector((-0.18191590905189514, -0.22385218739509583, self.distance.value[0] - dist)), \
            mathutils.Vector((-0.10375960171222687, -0.23957833647727966, self.distance.value[0] - dist)), \
            mathutils.Vector((0.0, -0.2464955747127533, self.distance.value[0] - dist)), \
            mathutils.Vector((0.10375960171222687, -0.23957833647727966, self.distance.value[0] - dist)), \
            mathutils.Vector((0.18191590905189514, -0.22385218739509583, self.distance.value[0] - dist)), \
            mathutils.Vector((0.2563667893409729, -0.1998385488986969, self.distance.value[0] - dist)), \
            mathutils.Vector((0.3441678285598755, -0.15873458981513977, self.distance.value[0] - dist)), \
            mathutils.Vector((0.40912365913391113, -0.11777058243751526, self.distance.value[0] - dist))]            
                
        # Put border points of camera to basic position
        points['border'][0] = mathutils.Vector((-width/2.0, \
            -0.5, \
            self.distance.value[0] - dist,
            1.0))
        points['border'][1] = mathutils.Vector((width/2.0, \
            -0.5, \
            self.distance.value[0] - dist,
            1.0))
        points['border'][2] = mathutils.Vector((width/2.0, \
            0.5, \
            self.distance.value[0] - dist, \
            1.0))
        points['border'][3] = mathutils.Vector((-width/2.0, \
            0.5, \
            self.distance.value[0] - dist, \
            1.0))
        
        # Center of view
        points['center'][0] = mathutils.Vector((0.0, \
            0.0, \
            self.distance.value[0], \
            1.0))        
        
        # Create transformation (rotation) matrix
        rot_matrix = mathutils.Quaternion(self.rotation.value).to_matrix().to_4x4()
        
        # Transform points in all point groups
        for point_group in points.values():
            for index in range(len(point_group)):
                # Rotate points
                point_group[index] = (rot_matrix*point_group[index]).to_3d()
                # Move points
                point_group[index] += mathutils.Vector(self.location.value)
        
        # Get & convert the Perspective Matrix of the current view/region.
        perspMatrix = region_data.perspective_matrix
        tempMat = [perspMatrix[j][i] 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]
        
        # Store GL_DEPTH_TEST
        depth_test_prev = bgl.Buffer(bgl.GL_BYTE, [1])
        bgl.glGetFloatv(bgl.GL_DEPTH_TEST, depth_test_prev)
        depth_test_prev = depth_test_prev[0]
            
        # Store GL_LINE_STIPPLE
        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
        col_prev = bgl.Buffer(bgl.GL_FLOAT, [4])
        bgl.glGetFloatv(bgl.GL_COLOR, col_prev)
        
        # Prepare for 3D drawing
        bgl.glLoadIdentity()
        bgl.glMatrixMode(bgl.GL_PROJECTION)
        bgl.glLoadMatrixf(perspBuff)
        bgl.glEnable(bgl.GL_BLEND)
        bgl.glEnable(bgl.GL_DEPTH_TEST)
                
        # Draw "Look At" point
        bgl.glLineWidth(1)
        bgl.glBegin(bgl.GL_LINES)
        bgl.glColor4f(color[0], color[1], color[2], color[3])
        
        bgl.glVertex3f(self.location.value[0]+0.1, \
            self.location.value[1], \
            self.location.value[2])
        bgl.glVertex3f(self.location.value[0]-0.1, \
            self.location.value[1], \
            self.location.value[2])
        
        bgl.glVertex3f(self.location.value[0], \
            self.location.value[1]+0.1, \
            self.location.value[2])
        bgl.glVertex3f(self.location.value[0], \
            self.location.value[1]-0.1, \
            self.location.value[2])
        
        bgl.glVertex3f(self.location.value[0], \
            self.location.value[1], \
            self.location.value[2]+0.1)
        bgl.glVertex3f(self.location.value[0], \
            self.location.value[1], \
            self.location.value[2]-0.1)
        
        bgl.glEnd()
        
        border = points['border']
        center = points['center']
        
        # Draw border of camera
        bgl.glBegin(bgl.GL_LINE_STRIP)
        bgl.glVertex3f(border[0][0], border[0][1], border[0][2])
        bgl.glVertex3f(border[1][0], border[1][1], border[1][2])
        bgl.glVertex3f(border[2][0], border[2][1], border[2][2])
        bgl.glVertex3f(border[3][0], border[3][1], border[3][2])
        bgl.glVertex3f(border[0][0], border[0][1], border[0][2])
        bgl.glEnd()
        
        # Draw left eye
        bgl.glBegin(bgl.GL_LINE_STRIP)
        for point in points['left_eye']:
            bgl.glVertex3f(point[0], point[1], point[2])
        bgl.glEnd()

        # Draw right eye
        bgl.glBegin(bgl.GL_LINE_STRIP)
        for point in points['right_eye']:
            bgl.glVertex3f(point[0], point[1], point[2])
        bgl.glEnd()
        
        # Draw mouth
        bgl.glBegin(bgl.GL_LINE_STRIP)
        for point in points['mouth']:
            bgl.glVertex3f(point[0], point[1], point[2])
        bgl.glEnd()
        
        # Draw dashed lines from center of "camera" to border of camera        
        bgl.glEnable(bgl.GL_LINE_STIPPLE)
        bgl.glBegin(bgl.GL_LINES)
        bgl.glVertex3f(border[0][0], border[0][1], border[0][2])
        bgl.glVertex3f(center[0][0], center[0][1], center[0][2])
        bgl.glVertex3f(border[1][0], border[1][1], border[1][2])
        bgl.glVertex3f(center[0][0], center[0][1], center[0][2])
        bgl.glVertex3f(border[2][0], border[2][1], border[2][2])
        bgl.glVertex3f(center[0][0], center[0][1], center[0][2])
        bgl.glVertex3f(border[3][0], border[3][1], border[3][2])
        bgl.glVertex3f(center[0][0], center[0][1], center[0][2])
        bgl.glEnd()
        
        # Draw dashed line from Look At point and center of camera
        bgl.glBegin(bgl.GL_LINES)
        bgl.glVertex3f(self.location.value[0], \
            self.location.value[1], \
            self.location.value[2])
        bgl.glVertex3f(center[0][0], center[0][1], center[0][2])
        bgl.glEnd()
        bgl.glDisable(bgl.GL_LINE_STIPPLE)    

        # 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)
        if not depth_test_prev:
            bgl.glDisable(bgl.GL_DEPTH_TEST)

        # Draw username
        coord_2d = location_3d_to_region_2d(
            area.regions[4],
            region_data,
            center[0])
        font_id, font_size, my_dpi = 0, 12, 72 # TODO: add to addon options
        blf.size(font_id, font_size, my_dpi)
        text_width, text_height = blf.dimensions(font_id, self.username)
        blf.position(font_id, coord_2d[0], coord_2d[1], 0)
        blf.draw(font_id, self.username)

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