23
25
from Blender import Draw
26
instructions = "Hold mouse buttons to change the background color."
28
title = "Testing BGL + Draw"
29
instructions = "Use mouse buttons or wheel to change the background color."
27
30
quitting = " Press ESC or q to quit."
31
len1 = Draw.GetStringWidth(title)
32
len2 = Draw.GetStringWidth(instructions + quitting)
30
35
glClearColor(R,G,B,A) # define color used to clear buffers
31
36
glClear(GL_COLOR_BUFFER_BIT) # use it to clear the color buffer
32
glColor3f(1,1,1) # change default color
37
glColor3f(0.35,0.18,0.92) # define default color
38
glBegin(GL_POLYGON) # begin a vertex data list
43
glColor3f(0.4,0.4,0.4) # change default color
44
glRecti(40, 96, 60+len1, 113)
33
46
glRasterPos2i(50,100) # move cursor to x = 50, y = 100
34
Draw.Text("Testing BGL + Draw") # draw this text there
35
glRasterPos2i(350,20) # move cursor again
47
Draw.Text(title) # draw this text there
48
glRasterPos2i(350,40) # move cursor again
36
49
Draw.Text(instructions + quitting) # draw another msg
37
50
glBegin(GL_LINE_LOOP) # begin a vertex-data list
40
53
glVertex2i(120,115)
42
55
glEnd() # close this list
43
glColor3f(0.35,0.18,0.92) # change default color again
44
glBegin(GL_POLYGON) # another list, for a polygon
49
Draw.Redraw(1) # make changes visible.
51
def ev(evt, val): # this is a callback for Draw.Register()
57
def ev(evt, val): # event callback for Draw.Register()
52
58
global R,G,B,A # ... it handles input events
53
59
if evt == Draw.ESCKEY or evt == Draw.QKEY:
54
60
Draw.Exit() # this quits the script
55
62
elif evt == Draw.LEFTMOUSE: R = 1 - R
56
63
elif evt == Draw.MIDDLEMOUSE: G = 1 - G
57
64
elif evt == Draw.RIGHTMOUSE: B = 1 - B
65
elif evt == Draw.WHEELUPMOUSE:
68
elif evt == Draw.WHEELDOWNMOUSE:
59
Draw.Register(show_win, ev, None)
72
return # don't redraw if nothing changed
73
Draw.Redraw(1) # make changes visible.
61
Draw.Register(show_win, ev, None) # start the main loop
75
Draw.Register(show_win, ev, None) # start the main loop
77
@note: you can use the L{Image} module and L{Image.Image} bpy object to load
78
and set textures. See L{Image.Image.glLoad} and L{Image.Image.glFree},
63
80
@see: U{www.opengl.org}
64
81
@see: U{nehe.gamedev.net}
68
84
def glAccum(op, value):
70
86
Operate on the accumulation buffer
71
@see: U{http://www.opengl.org/developers/documentation/man_pages/hardcopy/GL/html/gl/accum.html}
87
@see: U{www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/accum.html}
73
89
@type op: Enumerated constant
74
90
@param op: The accumulation buffer operation.
1592
1608
is first attached to a window, width and height are set to the dimensions of that window.
1611
def gluPerspective(fovY, aspect, zNear, zFar):
1613
Set up a perspective projection matrix.
1614
@see: U{http://biology.ncsa.uiuc.edu/cgi-bin/infosrch.cgi?cmd=getdoc&coll=0650&db=bks&fname=/SGI_Developer/OpenGL_RM/ch06.html#id5577288}
1617
@param fovY: Specifies the field of view angle, in degrees, in the y direction.
1618
@type aspect: double
1619
@param aspect: Specifies the aspect ratio that determines the field of view in the x direction.
1620
The aspect ratio is the ratio of x (width) to y (height).
1622
@param zNear: Specifies the distance from the viewer to the near clipping plane (always positive).
1624
@param zFar: Specifies the distance from the viewer to the far clipping plane (always positive).
1627
def gluLookAt(eyex, eyey, eyez, centerx, centery, centerz, upx, upy, upz):
1629
Define a viewing transformation
1630
@see: U{http://biology.ncsa.uiuc.edu/cgi-bin/infosrch.cgi?cmd=getdoc&coll=0650&db=bks&fname=/SGI_Developer/OpenGL_RM/ch06.html#id5573042}
1632
@type eyex, eyey, eyez: double
1633
@param eyex, eyey, eyez: Specifies the position of the eye point.
1634
@type centerx, centery, centerz: double
1635
@param centerx, centery, centerz: Specifies the position of the reference point.
1636
@type upx, upy, upz: double
1637
@param upx, upy, upz: Specifies the direction of the up vector.
1640
def gluOrtho2D(left, right, bottom, top):
1642
Define a 2-D orthographic projection matrix
1643
@see: U{http://biology.ncsa.uiuc.edu/cgi-bin/infosrch.cgi?cmd=getdoc&coll=0650&db=bks&fname=/SGI_Developer/OpenGL_RM/ch06.html#id5578074}
1645
@type left, right: double
1646
@param left, right: Specify the coordinates for the left and right vertical clipping planes.
1647
@type bottom, top: double
1648
@param bottom, top: Specify the coordinates for the bottom and top horizontal clipping planes.
1651
def gluPickMatrix(x, y, width, height, viewport):
1653
Define a picking region
1654
@see: U{http://biology.ncsa.uiuc.edu/cgi-bin/infosrch.cgi?cmd=getdoc&coll=0650&db=bks&fname=/SGI_Developer/OpenGL_RM/ch06.html#id5578074}
1657
@param x, y: Specify the center of a picking region in window coordinates.
1658
@type width, height: double
1659
@param width, height: Specify the width and height, respectively, of the picking region in window coordinates.
1660
@type viewport: Buffer object. [int]
1661
@param viewport: Specifies the current viewport.
1664
def gluProject(objx, objy, objz, modelMatrix, projMatrix, viewport, winx, winy, winz):
1666
Map object coordinates to window coordinates.
1667
@see: U{http://biology.ncsa.uiuc.edu/cgi-bin/infosrch.cgi?cmd=getdoc&coll=0650&db=bks&fname=/SGI_Developer/OpenGL_RM/ch06.html#id5578074}
1669
@type objx, objy, objz: double
1670
@param objx, objy, objz: Specify the object coordinates.
1671
@type modelMatrix: Buffer object. [double]
1672
@param modelMatrix: Specifies the current modelview matrix (as from a glGetDoublev call).
1673
@type projMatrix: Buffer object. [double]
1674
@param projMatrix: Specifies the current projection matrix (as from a glGetDoublev call).
1675
@type viewport: Buffer object. [int]
1676
@param viewport: Specifies the current viewport (as from a glGetIntegerv call).
1677
@type winx, winy, winz: Buffer object. [double]
1678
@param winx, winy, winz: Return the computed window coordinates.
1681
def gluUnProject(winx, winy, winz, modelMatrix, projMatrix, viewport, objx, objy, objz):
1683
Map object coordinates to window
1685
@see: U{http://biology.ncsa.uiuc.edu/cgi-bin/infosrch.cgi?cmd=getdoc&coll=0650&db=bks&fname=/SGI_Developer/OpenGL_RM/ch06.html#id5582204}
1687
@type winx, winy, winz: double
1688
@param winx, winy, winz: Specify the window coordinates to be mapped.
1689
@type modelMatrix: Buffer object. [double]
1690
@param modelMatrix: Specifies the current modelview matrix (as from a glGetDoublev call).
1691
@type projMatrix: Buffer object. [double]
1692
@param projMatrix: Specifies the current projection matrix (as from a glGetDoublev call).
1693
@type viewport: Buffer object. [int]
1694
@param viewport: Specifies the current viewport (as from a glGetIntegerv call).
1695
@type objx, objy, objz: Buffer object. [double]
1696
@param objx, objy, objz: Return the computed object coordinates.
1597
The Buffer object is simply a block of memory that is delineated and initalized by the
1701
The Buffer object is simply a block of memory that is delineated and initialized by the
1598
1702
user. Many OpenGL funtions return data to a C-style pointer, however, because this
1599
1703
is not possible in python the Buffer object can be used to this end. Wherever pointer
1600
1704
notation is used in the OpenGL functions the Buffer object can be used in it's BGL