Draw a 2d box using Bgl in viewport I have been trying read up a lot on opengl drawing using python and have been trying to create a script which display a text and a 2d shape on the viewport (a rectangle or square). From reading the blender docs I could only find little to no information about it and only got me to display text. The 2d shape drawing is still out of my knowledge. In this code I'm trying to draw a text and a draw a 2d quad in a modal operator but unfortunately the quad doesn't show up but the text is working properly.
How do I draw a 2d shape in a modal operator using bgl ?
import bpy
import blf
import bgl

def draw_textandbox(self, context):

    font_id = 0  
    x_offset = 0
    y_offset = 0

    #The Text-------------------------
    bgl.glColor4f(1,1,1,0.8)
    blf.position(font_id, 80, 500, 0)
    blf.size(font_id, 27, 70)
    blf.draw(font_id, &quot;LEVELS:&quot; )

    #The Box, This is the part i wanted to work but unfortunately it doesnt
    bgl.glColor4f(1,0,0,0.8)  
    bgl.glBegin(bgl.GL_QUADS)

    bgl.glVertex2f(200, 400)
    bgl.glEnd()
It's a quadrilateral, you need to define 4 verts.

Test method, x and y are pixel coordinates of bottom left corner of rectangle, h and w the height and width (in pixels) respectively. 

def draw_box(self, x, y, w, h, color=(0.0, 0.0, 0.0, 1.0)):
    #bgl.glDepthRange (0.1, 1.0)
    bgl.glColor4f(*color)
    bgl.glBegin(bgl.GL_QUADS)

    bgl.glVertex2f(x + w, y + h)
    bgl.glVertex2f(x, y + h)
    bgl.glVertex2f(x, y)
    bgl.glVertex2f(x + w, y)
    bgl.glEnd()


Run-able Example