99. opengl.canvas
— This implements an OpenGL drawing widget for painting 3D scenes.¶
99.1. Classes defined in module opengl.canvas¶
-
class
opengl.canvas.
Canvas
(settings={})[source]¶ A canvas for OpenGL rendering.
The Canvas is a class holding all global data of an OpenGL scene rendering. It always contains a Scene with the actors and decorations that are drawn on the canvas. The canvas has a Camera holding the viewing parameters needed to project the scene on the canvas. Settings like colors, line types, rendering mode and the lighting information are gathered in a CanvasSettings object. There are attributes for some special purpose decorations (Triade, Grid) that can not be handled by the standard drawing and Scene changing functions.
The Canvas class does not however contain the viewport size and position. The class is intended as a mixin to be used by some OpenGL widget class that will hold this information (such as the QtCanvas class).
Important note: the Camera object is not initalized by the class initialization. The derived class initialization should therefore explicitely call the initCamera method before trying to draw anything to the canvas. This is because initializing the camera requires a working OpenGL format, which is only established by the derived OpenGL widget.
99.2. Functions defined in module opengl.canvas¶
-
opengl.canvas.
drawLine
(x1, y1, x2, y2)[source]¶ Draw a straight line from (x1,y1) to (x2,y2) in canvas coordinates.
-
opengl.canvas.
drawGrid
(x1, y1, x2, y2, nx, ny)[source]¶ Draw a rectangular grid of lines
The rectangle has (x1,y1) and and (x2,y2) as opposite corners. There are (nx,ny) subdivisions along the (x,y)-axis. So the grid has (nx+1) * (ny+1) lines. nx=ny=1 draws a rectangle. nx=0 draws 1 vertical line (at x1). nx=-1 draws no vertical lines. ny=0 draws 1 horizontal line (at y1). ny=-1 draws no horizontal lines.