Skip to content
Snippets Groups Projects
Select Git revision
  • 9c54e9507a0a305e5702f392e119ebec32c3f102
  • CyclesPhi-dev default
  • blenderphi-v4.5-v1
  • main protected
  • blender-v4.5-release
  • cycles-v4.5-aurora
  • anari-v4.5
  • anari3
  • anari2
  • anari
  • blender-v4.4-release
  • anary-cycles-device
  • xml-exporter-main
  • blender-v4.3-release
  • temp-sculpt-dyntopo
  • blender-v3.3-release
  • brush-assets-project
  • pr-extensions-tidy-space
  • blender-v4.0-release
  • universal-scene-description
  • blender-v4.1-release
  • v4.4.0
  • v4.2.8
  • v3.6.21
  • v4.2.7
  • v3.6.20
  • v4.2.6
  • v4.3.2
  • v4.2.5
  • v3.6.19
  • v4.3.1
  • v4.3.0
  • v3.6.18
  • v4.2.4
  • v3.6.17
  • v4.2.3
  • v3.6.16
  • v4.2.2
  • v4.2.1
  • v3.6.15
  • v4.2.0
41 results

testbgl.py

Blame
  • user avatar
    Willian Padovani Germano authored
    * Documentation and a simple test for BGL.
    dd8f2166
    History
    testbgl.py 1.63 KiB
    # Testing the BGL module
    
    import Blender
    from Blender.BGL import *
    from Blender import Draw
    
    R = G = B = 0
    A = 1
    
    instructions = "Hold mouse buttons to change the background color."
    quitting = " Press ESC or q to quit."
    
    def show_win():
      glClearColor(R,G,B,A)                # define color used to clear buffers 
      glClear(GL_COLOR_BUFFER_BIT)         # use it to clear the color buffer
      glColor3f(1,1,1)                     # change default color
      glRasterPos2i(50,100)                # move cursor to x = 50, y = 100
      Draw.Text("Testing BGL  + Draw")     # draw this text there
      glRasterPos2i(350,20)                # move cursor again
      Draw.Text(instructions + quitting)   # draw another msg
      glBegin(GL_LINE_LOOP)                # begin a vertex-data list
      glVertex2i(46,92)
      glVertex2i(120,92)
      glVertex2i(120,115)
      glVertex2i(46,115)
      glEnd()                              # close this list
      glColor3f(0.35,0.18,0.92)            # change default color again
      glBegin(GL_POLYGON)                  # another list, for a polygon
      glVertex2i(315, 292)
      glVertex2i(412, 200)
      glVertex2i(264, 256)
      glEnd()
      Draw.Redraw(1)                       # make changes visible.
    
    def ev(evt, val):                      # this is a callback for Draw.Register()
      global R,G,B,A                       # it handles input events
      if evt == Draw.ESCKEY or evt == Draw.QKEY:
        Draw.Exit()                        # this quits the script
      elif evt == Draw.LEFTMOUSE: R = 1 - R
      elif evt == Draw.MIDDLEMOUSE: G = 1 - G
      elif evt == Draw.RIGHTMOUSE: B = 1 - B
      else:
        Draw.Register(show_win, ev, None)
    
    Draw.Register(show_win, ev, None)      # start the main loop