Trees | Indices | Help |
---|
|
The Blender.BGL submodule (the OpenGL wrapper).
New: some GLU functions: gluLookAt, etc.
This module wraps OpenGL constants and functions, making them available from within Blender Python.
The complete list can be retrieved from the module itself, by listing its contents: dir(Blender.BGL). A simple search on the net can point to more than enough material to teach OpenGL programming, from books to many collections of tutorials.
The "red book": "OpenGL Programming Guide: The Official Guide to Learning OpenGL" and the online NeHe tutorials are two of the best resources.
Example:
import Blender from Blender.BGL import * from Blender import Draw R = G = B = 0 A = 1 title = "Testing BGL + Draw" instructions = "Use mouse buttons or wheel to change the background color." quitting = " Press ESC or q to quit." len1 = Draw.GetStringWidth(title) len2 = Draw.GetStringWidth(instructions + quitting) # 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(0.35,0.18,0.92) # define default color glBegin(GL_POLYGON) # begin a vertex data list glVertex2i(165, 158) glVertex2i(252, 55) glVertex2i(104, 128) glEnd() glColor3f(0.4,0.4,0.4) # change default color glRecti(40, 96, 60+len1, 113) glColor3f(1,1,1) glRasterPos2i(50,100) # move cursor to x = 50, y = 100 Draw.Text(title) # draw this text there glRasterPos2i(350,40) # 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 # def ev(evt, val): # event 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 not val: return elif evt == Draw.LEFTMOUSE: R = 1 - R elif evt == Draw.MIDDLEMOUSE: G = 1 - G elif evt == Draw.RIGHTMOUSE: B = 1 - B elif evt == Draw.WHEELUPMOUSE: R += 0.1 if R > 1: R = 1 elif evt == Draw.WHEELDOWNMOUSE: R -= 0.1 if R < 0: R = 0 else: return # don't redraw if nothing changed Draw.Redraw(1) # make changes visible. # Draw.Register(show_win, ev, None) # start the main loop
Note: you can use the Image module and Image.Image BPy object to load and set textures. See Image.Image.glLoad and Image.Image.glFree, for example.
|
|||
Buffer The Buffer object is simply a block of memory that is delineated and initialized by the user. |
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|
|||
__package__ = None
|
|
Operate on the accumulation buffer
|
Specify the alpha test function
|
Determine if textures are loaded in texture memory
|
Delimit the vertices of a primitive or a group of like primatives
|
Bind a named texture to a texturing target
|
Draw a bitmap
|
Specify pixel arithmetic
|
Execute a display list
|
Execute a list of display lists
|
Clear buffers to preset values
|
Specify clear values for the accumulation buffer
|
Specify clear values for the color buffers
|
Specify the clear value for the depth buffer
|
Specify the clear value for the color index buffers
|
Specify the clear value for the stencil buffer
|
Specify a plane against which all geometry is clipped
|
glColor3b, glColor3d, glColor3f, glColor3i, glColor3s, glColor3ub, glColor3ui, glColor3us, glColor4b, glColor4d, glColor4f, glColor4i, glColor4s, glColor4ub, glColor4ui, glColor4us, glColor3bv, glColor3dv, glColor3fv, glColor3iv, glColor3sv, glColor3ubv, glColor3uiv, glColor3usv, glColor4bv, glColor4dv, glColor4fv, glColor4iv, glColor4sv, glColor4ubv, glColor4uiv, glColor4usv Set a new color.
|
Enable and disable writing of frame buffer color components
|
Cause a material color to track the current color
|
Copy pixels in the frame buffer
|
Specify whether front- or back-facing facets can be culled
|
Delete a contiguous group of display lists
|
Delete named textures
|
Specify the value used for depth buffer comparisons
|
Enable or disable writing into the depth buffer
|
Specify mapping of depth values from normalized device coordinates to window coordinates
|
Disable server-side GL capabilities
|
Specify which color buffers are to be drawn into
|
Write a block of pixels to the frame buffer
|
glEdgeFlag, glEdgeFlagv Flag edges as either boundary or non-boundary
|
Enable server-side GL capabilities
|
Delimit the vertices of a primitive or group of like primitives |
Create or replace a display list |
glEvalCoord1d, glEvalCoord1f, glEvalCoord2d, glEvalCoord2f, glEvalCoord1dv, glEvalCoord1fv, glEvalCoord2dv, glEvalCoord2fv Evaluate enabled one- and two-dimensional maps
|
glEvalMesh1 or glEvalMesh2 Compute a one- or two-dimensional grid of points or lines
|
glEvalPoint1 and glEvalPoint2 Generate and evaluate a single point in a mesh
|
Controls feedback mode
|
Block until all GL execution is complete |
Force Execution of GL commands in finite time |
glFogf, glFogi, glFogfv, glFogiv Specify fog parameters
|
Define front- and back-facing polygons
|
Multiply the current matrix by a perspective matrix
|
Generate a contiguous set of empty display lists
|
Generate texture names
|
glGetBooleanv, glGetfloatv, glGetFloatv, glGetIntegerv Return the value or values of a selected parameter
|
Return the coefficients of the specified clipping plane
|
Return error information |
glGetLightfv and glGetLightiv Return light source parameter values
|
glGetMapdv, glGetMapfv, glGetMapiv Return evaluator parameters
|
glGetMaterialfv, glGetMaterialiv Return material parameters
|
glGetPixelMapfv, glGetPixelMapuiv, glGetPixelMapusv Return the specified pixel map
|
Return the polygon stipple pattern
|
Return a string describing the current GL connection
|
glGetTexEnvfv, glGetTexEnviv Return texture environment parameters
|
glGetTexGendv, glGetTexGenfv, glGetTexGeniv Return texture coordinate generation parameters
|
Return a texture image
|
glGetTexLevelParameterfv, glGetTexLevelParameteriv return texture parameter values for a specific level of detail
|
glGetTexParameterfv, glGetTexParameteriv Return texture parameter values
|
Specify implementation-specific hints
|
glIndexd, glIndexf, glIndexi, glIndexs, glIndexdv, glIndexfv, glIndexiv, glIndexsv Set the current color index
|
Initialize the name stack |
Test whether a capability is enabled
|
Determine if a name corresponds to a display-list
|
Determine if a name corresponds to a texture
|
glLightf,glLighti, glLightfv, glLightiv Set the light source parameters
|
glLightModelf, glLightModeli, glLightModelfv, glLightModeliv Set the lighting model parameters
|
Specify the line stipple pattern
|
Specify the width of rasterized lines.
|
Set the display-list base for glCallLists
|
Replace the current matrix with the identity matrix |
glLoadMatrixd, glLoadMatixf Replace the current matrix with the specified matrix
|
Load a name onto the name stack.
|
Specify a logical pixel operation for color index rendering
|
glMap1d, glMap1f Define a one-dimensional evaluator
|
glMap2d, glMap2f Define a two-dimensional evaluator
|
glMapGrid1d, glMapGrid1f, glMapGrid2d, glMapGrid2f Define a one- or two-dimensional mesh
|
Specify material parameters for the lighting model.
|
Specify which matrix is the current matrix.
|
glMultMatrixd, glMultMatrixf Multiply the current matrix with the specified matrix
|
Create or replace a display list
|
Normal3b, Normal3bv, Normal3d, Normal3dv, Normal3f, Normal3fv, Normal3i, Normal3iv, Normal3s, Normal3sv Set the current normal vector
|
Multiply the current matrix with an orthographic matrix
|
Place a marker in the feedback buffer
|
glPixelMapfv, glPixelMapuiv, glPixelMapusv Set up pixel transfer maps
|
glPixelStoref, glPixelStorei Set pixel storage modes
|
glPixelTransferf, glPixelTransferi Set pixel transfer modes
|
Specify the pixel zoom factors
|
Specify the diameter of rasterized points
|
Select a polygon rasterization mode
|
Set the scale and units used to calculate depth values
|
Set the polygon stippling pattern
|
Pop the server attribute stack |
Pop the client attribute stack |
Pop the current matrix stack |
Pop the name stack |
Set texture residence priority
|
Push the server attribute stack
|
Push the client attribute stack
|
Push the current matrix stack |
Push the name stack
|
glRasterPos2d, glRasterPos2f, glRasterPos2i, glRasterPos2s, glRasterPos3d, glRasterPos3f, glRasterPos3i, glRasterPos3s, glRasterPos4d, glRasterPos4f, glRasterPos4i, glRasterPos4s, glRasterPos2dv, glRasterPos2fv, glRasterPos2iv, glRasterPos2sv, glRasterPos3dv, glRasterPos3fv, glRasterPos3iv, glRasterPos3sv, glRasterPos4dv, glRasterPos4fv, glRasterPos4iv, glRasterPos4sv Specify the raster position for pixel operations
See Also: www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/gl/rasterpos.html Note: If you are drawing to the 3d view with a Scriptlink of a space handler the zoom level of the panels will scale the glRasterPos by the view matrix. so a X of 10 will not always offset 10 pixels as you would expect. To work around this get the scale value of the view matrix and use it to scale your pixel values. Workaround: import Blender from Blender.BGL import * xval, yval= 100, 40 # Get the scale of the view matrix viewMatrix = Buffer(GL_FLOAT, 16) glGetFloatv(GL_MODELVIEW_MATRIX, viewMatrix) f = 1/viewMatrix[0] glRasterPos2f(xval*f, yval*f) # Instead of the usual glRasterPos2i(xval, yval) |
Select a color buffer source for pixels.
|
Read a block of pixels from the frame buffer
|
glRectd, glRectf, glRecti, glRects, glRectdv, glRectfv, glRectiv, glRectsv Draw a rectangle
|
Set rasterization mode
|
glRotated, glRotatef Multiply the current matrix by a rotation matrix
|
glScaled, glScalef Multiply the current matrix by a general scaling matrix
|
Define the scissor box
|
Establish a buffer for selection mode values
|
Select flat or smooth shading
|
Set function and reference value for stencil testing
|
Control the writing of individual bits in the stencil planes
|
Set stencil test actions
|
glTexCoord1d, glTexCoord1f, glTexCoord1i, glTexCoord1s, glTexCoord2d, glTexCoord2f, glTexCoord2i, glTexCoord2s, glTexCoord3d, glTexCoord3f, glTexCoord3i, glTexCoord3s, glTexCoord4d, glTexCoord4f, glTexCoord4i, glTexCoord4s, glTexCoord1dv, glTexCoord1fv, glTexCoord1iv, glTexCoord1sv, glTexCoord2dv, glTexCoord2fv, glTexCoord2iv, glTexCoord2sv, glTexCoord3dv, glTexCoord3fv, glTexCoord3iv, glTexCoord3sv, glTexCoord4dv, glTexCoord4fv, glTexCoord4iv, glTexCoord4sv Set the current texture coordinates
|
glTextEnvf, glTextEnvi, glTextEnvfv, glTextEnviv Set texture environment parameters
|
glTexGend, glTexGenf, glTexGeni, glTexGendv, glTexGenfv, glTexGeniv Control the generation of texture coordinates
|
Specify a one-dimensional texture image
|
Specify a two-dimensional texture image
|
glTexParameterf, glTexParameteri, glTexParameterfv, glTexParameteriv Set texture parameters
|
glTranslatef, glTranslated Multiply the current matrix by a translation matrix
|
glVertex2d, glVertex2f, glVertex2i, glVertex2s, glVertex3d, glVertex3f, glVertex3i, glVertex3s, glVertex4d, glVertex4f, glVertex4i, glVertex4s, glVertex2dv, glVertex2fv, glVertex2iv, glVertex2sv, glVertex3dv, glVertex3fv, glVertex3iv, glVertex3sv, glVertex4dv, glVertex4fv, glVertex4iv, glVertex4sv Specify a vertex
|
Set the viewport
|
Set up a perspective projection matrix.
|
Define a viewing transformation
|
Define a 2-D orthographic projection matrix
|
Define a picking region
|
Map object coordinates to window coordinates.
|
Map object coordinates to window coordinates.
|
Trees | Indices | Help |
---|
Generated by Epydoc 3.0.1 on Fri Oct 24 10:23:50 2008 | http://epydoc.sourceforge.net |