So i drew a 2d polygon and some blf text using a modal operator. But a problem arised. The 2d shape and text wouldnt stay relavant to the screen size of the 3d viewport. I would seem as if the vertex coordinates are static to the screen coordinates and not to the 3d viewport. As you can see in the gif that dragging the screen completely hides the drawing. so my question is,
How do i make the 2d drawing coordinates stay relative to the 3d viewport so that resizing the window doesnt hide the 2d drawing ?
The code:-
def draw_poly(points):
for i in range(len(points)):
bgl.glVertex2f(points[i][0],points[i][1])
def draw_callback_px(self, context):
panel_points = [[10.0, 550.0], #[x, y]
[10.0, 685.0], #[x, y]
[150.0, 685.0], #[x, y]
[150.0, 550.0], #[x, y]
[120, 500],
[80, 490],
[40, 500],
]
# draw poly
bgl.glColor4f(1.0, 0.085, 0.0, 0.2)
bgl.glEnable(bgl.GL_BLEND)
bgl.glBegin(bgl.GL_POLYGON)
draw_poly(panel_points)
bgl.glEnd()
# draw outline
bgl.glColor4f(0.1, 0.1, 0.1, 1.0)
bgl.glLineWidth(4)
bgl.glBegin(bgl.GL_LINE_LOOP)
draw_poly(panel_points)
bgl.glEnd()
font_id = 0
# draw some text
bgl.glColor4f(1.0, 1.0, 1.0, 0.8)
blf.position(font_id, 15, 620, 0)
blf.size(font_id, 50, 100)
blf.draw(font_id, "BGL")
blf.position(font_id, 15, 580, 0)
blf.size(font_id, 30, 100)
blf.draw(font_id, "Widget")
# restore opengl defaults
bgl.glLineWidth(1)
bgl.glDisable(bgl.GL_BLEND)
bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
context.region.width
bycontext.region.height
? I understand what you want, here is your last question on this I answered .. what incentive do I have to answer another... some other kind soul on bse will I'm sure. $\endgroup$