Replace bgl by gpu

blender3.6
ChristopheSeux 2023-10-03 11:49:21 +02:00
parent b48dbdbeef
commit e3158da0fc
3 changed files with 23 additions and 24 deletions

View File

@ -1,6 +1,6 @@
import bpy
import bgl
import blf
import gpu
from mathutils import Vector
from .func_picker import *
@ -16,7 +16,7 @@ def draw_polygon_2d(verts, indices, loops, color, contour, width=None):
dpi = int(bpy.context.user_preferences.system.pixel_size)
bgl.glColor4f(*color)
bgl.glEnable(bgl.GL_BLEND)
gpu.state.blend_set('ALPHA')
#bgl.glEnable(bgl.GL_LINE_SMOOTH)
bgl.glColor4f(*color)
@ -28,7 +28,7 @@ def draw_polygon_2d(verts, indices, loops, color, contour, width=None):
bgl.glEnd()
if width:
bgl.glLineWidth(width*dpi)
gpu.state.line_width_set(width*dpi)
bgl.glColor4f(*contour)
for loop in loops:
@ -41,14 +41,14 @@ def draw_polygon_2d(verts, indices, loops, color, contour, width=None):
bgl.glVertex2f(coord[0],coord[1])
bgl.glEnd()
bgl.glDisable(bgl.GL_BLEND)
gpu.state.blend_set('NONE')
#bgl.glDisable(bgl.GL_LINE_SMOOTH)
bgl.glEnd()
return
def draw_border(border):
bgl.glEnable(bgl.GL_BLEND)
gpu.state.blend_set('ALPHA')
bgl.glColor4f(1,1,1,0.2)
bgl.glBegin(bgl.GL_POLYGON)
for v in border:
@ -57,7 +57,7 @@ def draw_border(border):
bgl.glEnd()
bgl.glColor4f(0.0, 0.0, 0.0, 0.5)
bgl.glLineWidth(2)
gpu.state.line_width_set(2.0)
bgl.glLineStipple(3, 0xAAAA)
bgl.glEnable(bgl.GL_LINE_STIPPLE)
@ -69,19 +69,19 @@ def draw_border(border):
bgl.glEnd()
bgl.glColor4f(1.0, 1.0, 1.0, 1)
bgl.glLineWidth(1)
gpu.state.line_width_set(1.0)
bgl.glBegin(bgl.GL_LINE_LOOP)
for v in border:
bgl.glVertex2f(v[0],v[1])
bgl.glEnd()
bgl.glDisable(bgl.GL_LINE_STIPPLE)
bgl.glDisable(bgl.GL_BLEND)
gpu.state.blend_set('NONE')
def draw_text(mouse,text,color):
dpi = int(bpy.context.user_preferences.system.pixel_size)
bgl.glEnable(bgl.GL_BLEND)
gpu.state.blend_set('ALPHA')
font_id =0 # XXX, need to find out how best to get this.
# draw some text
bgl.glColor4f(0,0,0,0.75)
@ -94,7 +94,7 @@ def draw_text(mouse,text,color):
bgl.glColor4f(*color)
blf.blur(font_id,0)
blf.draw(font_id, text)
bgl.glDisable(bgl.GL_BLEND)
gpu.state.blend_set('NONE')
def select_bone(self,context,event):

View File

@ -5,7 +5,6 @@ from .constants import PICKERS
#from .func_picker import *
#from .utils import is_over_region
import gpu
import bgl
from mathutils import Vector
from gpu_extras.batch import batch_for_shader
from pathlib import Path
@ -59,7 +58,7 @@ def draw_callback(self):
if not self.draw_border:
return
bgl.glEnable(bgl.GL_BLEND)
gpu.state.blend_set('ALPHA')
#print('DRAW BORDER')
@ -77,7 +76,7 @@ def draw_callback(self):
self.contour_batch.draw(self.dash_shader)
bgl.glDisable(bgl.GL_BLEND)
gpu.state.blend_set('NONE')
def is_picker_space(context):

View File

@ -2,8 +2,7 @@
import bpy
import gpu
from gpu_extras.batch import batch_for_shader
import bgl
import blf
import gpu
from mathutils import bvhtree, Vector
from mathutils.geometry import intersect_point_quad_2d, intersect_point_tri_2d, intersect_tri_tri_2d
from .constants import PICKERS
@ -196,7 +195,7 @@ class BoneShape(Shape):
return self.bone_colors['normal']
def draw(self):
bgl.glEnable(bgl.GL_BLEND)
gpu.state.blend_set('ALPHA')
if self.hide:
self.shader.uniform_float("color", (*self.color[:3], 0.4))
@ -232,14 +231,15 @@ class BoneShape(Shape):
#print(self.bone_color)
if self.select or self.active:
bgl.glLineWidth(2)
gpu.state.line_width_set(2.0)
#if not self.hide:
self.shader.uniform_float("color", self.bone_color)
#for b in self.contour_batches:
self.e_batch.draw(self.shader)
bgl.glLineWidth(1)
bgl.glDisable(bgl.GL_BLEND)
gpu.state.line_width_set(1.0)
gpu.state.blend_set('NONE')
def assign_bone_event(self):
@ -377,10 +377,10 @@ class OperatorShape(Shape):
else:
return
bgl.glEnable(bgl.GL_BLEND)
gpu.state.blend_set('ALPHA')
self.shader.uniform_float("color", color)
self.p_batch.draw(self.shader)
bgl.glDisable(bgl.GL_BLEND)
gpu.state.blend_set('NONE')
@ -578,7 +578,7 @@ class Picker:
self.batch.draw(self.shader)
bgl.glDisable(bgl.GL_BLEND)
gpu.state.blend_set('NONE')
'''
@ -628,7 +628,7 @@ def draw_callback_px():
font_id = 0
#blf.dimensions(font_id, text)
blf.enable(font_id, blf.SHADOW)
#bgl.glEnable(bgl.GL_BLEND)
#gpu.state.blend_set('ALPHA')
# BLF drawing routine
@ -642,7 +642,7 @@ def draw_callback_px():
blf.draw(font_id, text)
blf.disable(font_id, blf.SHADOW)
#bgl.glDisable(bgl.GL_BLEND)
#gpu.state.blend_set('NONE')
handle_view = None
handle_pixel = None