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 ?

enter image description here

The code:-

def draw_poly(points):
  for i in range(len(points)):

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)

# draw outline
  bgl.glColor4f(0.1, 0.1, 0.1, 1.0)

  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.glColor4f(0.0, 0.0, 0.0, 1.0)
  • $\begingroup$ Look at example pointed out here $\endgroup$
    – batFINGER
    Oct 25, 2017 at 4:38
  • $\begingroup$ If anything is static in example above it's your coordinates. The screen has a resolution of how many pixels by pixels. Each area region has a width and height in pixels The origin is the bottom left corner. If you statically draw a "widget" at y=550 do you expect to see it when the area height is less than 550? Have a nice day. $\endgroup$
    – batFINGER
    Oct 25, 2017 at 11:02
  • $\begingroup$ That's why I asked the question, I want the widget to be relative to the window size and move or resize dynamically every time the window is resized. I am completely lost here because of the lack of documentation. $\endgroup$
    – Retrax
    Oct 25, 2017 at 11:21
  • $\begingroup$ Doubt it's the lack of docs that has you lost. Do you really need documentation to scale into a region context.region.width by context.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$
    – batFINGER
    Oct 25, 2017 at 12:12


You must log in to answer this question.

Browse other questions tagged .