GLTools

ColorRGBA

class gltools.ColorRGBA

ColorRGBA(GLubyte red=255, GLubyte green=255, GLubyte blue=255, GLubyte alpha=255)

RGBA color with components stored as unsigned bytes.

static __new__(S, ...) → a new object with type S, a subtype of T
copy(self, int red=-1, int green=-1, int blue=-1, alpha=-1) → ColorRGBA

Create copy with optional changes.

fromInt(self, unsigned int value)

Unpack color from unsigned int

toFloatVector(self) → tuple

Return color as float normalized [0.0 - 1.0]

toInt(self) → unsigned int

Pack color to a single unsigned int

__getitem__

x.__getitem__(y) <==> x[y]

__init__

x.__init__(...) initializes x; see help(type(x)) for signature

__len__

x.__len__() <==> len(x)

__mul__

Scale color components and leaves alpha unchanged

__repr__

x.__repr__() <==> repr(x)

__rmul__

x.__rmul__(y) <==> y*x

__str__

x.__str__() <==> str(x)

alpha

alpha: ‘unsigned char’

blue

blue: ‘unsigned char’

green

green: ‘unsigned char’

red

red: ‘unsigned char’

Material

class gltools.Material

Material(int mode=GL_FRONT_AND_BACK, **kwargs)

Abstraction of OpenGL material

static __new__(S, ...) → a new object with type S, a subtype of T
enable(self)

Set OpenGL material state

__init__

x.__init__(...) initializes x; see help(type(x)) for signature

__repr__

x.__repr__() <==> repr(x)

__str__

x.__str__() <==> str(x)

ambient

ambient: gltools.ColorRGBA

diffuse

diffuse: gltools.ColorRGBA

emissive

emissive: gltools.ColorRGBA

mode

mode: ‘int’

shininess

shininess: ‘float’

specular

specular: gltools.ColorRGBA

Light

class gltools.Light

Light(int index=0, Material material=None, Point position=None, directional=True, Vector direction=None)

Abstraction of OpenGL light

static __new__(S, ...) → a new object with type S, a subtype of T
disable(self)

Disable light

enable(self)

Enable light and set OpenGL state

__init__

x.__init__(...) initializes x; see help(type(x)) for signature

__repr__

x.__repr__() <==> repr(x)

__str__

x.__str__() <==> str(x)

direction

direction: geotools.Vector

directional

directional: ‘int’

index

index: ‘int’

material

material: gltools.Material

position

position: geotools.Point

Image

class gltools.Image

Image(int width, int height, int format)

Image buffer containing either an RGB/RGBA 8bit channel image.

Width :image width
Height :image height
Format :gl.RGB or gl.RGBA
static __new__(S, ...) → a new object with type S, a subtype of T
flipY(self)

Flip inplace the image in the vertical direction

writePNG(self, char *filename, int stride=0)

Write image to PNG file. Note that the file will be overwritten if not locked.

Filename :image file name
Stride :stride into buffer

Raises GLError on failure.

__init__

x.__init__(...) initializes x; see help(type(x)) for signature

__len__

x.__len__() <==> len(x)

bytesPerPixel

bytesPerPixel: ‘int’

height

height: ‘int’

width

width: ‘int’

TextureRect2D

class gltools.TextureRect2D

TextureRect2D(int width, int height, int depth=3)

Abstraction of OpenGL 2d rectangular texture used for keeping a buffer of the screen content.

static __new__(S, ...) → a new object with type S, a subtype of T
blit(self, float x=0.0, float y=0.0)

Blit content of the texture to the back buffer.

copy(self, int mode=GL_BACK)

Copy buffer content to texture.

static fromImage(type cls, Image img)

Create texture from existing image

__init__

x.__init__(...) initializes x; see help(type(x)) for signature

__repr__

x.__repr__() <==> repr(x)

__str__

x.__str__() <==> str(x)

ClientBuffer

class gltools.ClientBuffer

ClientBuffer(target=GL_ARRAY_BUFFER)

Abstraction of OpenGL vertex buffer

The class initialize a single buffer object. The target argument is either gl.ARRAY_BUFFER or gl.ELEMENT_ARRAY_BUFFER.

static __new__(S, ...) → a new object with type S, a subtype of T
bind(self)

Bind the buffer object and possible set the attribute pointers ig the target is gl.ARRAY_BUFFER and the datatype is defined

loadData(self, data, Py_ssize_t size, Py_ssize_t offset=0, int usage=GL_STATIC_DRAW)

Upload data to client side buffer. Passing None for data will reserve capacity.

Data :None, or any python python object with buffer interface
Size :size of data to upload.
Offset :offset into buffer object
setDataType(self, int type, int dataType, int dataTypeSize, int stride, size_t pointer)

Set datatye for data in buffer. Only makes sense when target is gl.ARRAY_BUFFER.

Type :gl.VERTEX_ARRAY, gl.NORMAL_ARRAY or gl.COLOR_ARRAY.
Datatype :gl.FLOAT, gl.INT etc.
Datatypesize :size of datatype.
Stride :stride between data
Pointer :pointer into buffer object (offser from index 0)
example::
buffer.setDataType(gl.VERTEX_ARRAY, gl.FLOAT, 3, 0, 0)
unBind(self)

Unbind the buffer object

__init__

x.__init__(...) initializes x; see help(type(x)) for signature

__repr__

x.__repr__() <==> repr(x)

__str__

x.__str__() <==> str(x)

ShaderProgram

class gltools.ShaderProgram

ShaderProgram()

Class to encapsulate compiled GLSL shaders

static __new__(S, ...) → a new object with type S, a subtype of T
begin(self)

Set program as current

build(self, vertex_src=None, fragment_src=None)

Compile program source. If no argument is given the default program simulating the fixed pipeline is loaded.

Raises GLError if failed.

end(self)

Unset program. This will enable the fixed openGL pipeline

static flat(type cls)
isValid(self) → int

Return status

loadUniform1f(self, char *name, float value)

Load named uniform float value

loadUniform1i(self, char *name, int value)

Load named uniform integer value

loadUniform4f(self, char *name, float v0, float v1, float v2, float v3)

Load named uniform float vector

loadUniformMatrix4vf(self, char *name, __Pyx_memviewslice value, int count=1)

Load named uniform matrix value

static pongDiffuse(type cls, int lights)
static pongSpecular(type cls, int lights)
__init__

x.__init__(...) initializes x; see help(type(x)) for signature

__repr__

x.__repr__() <==> repr(x)

__str__

x.__str__() <==> str(x)

GLFW

gltools.Init()

Initialize GLFW.

Raise GLError on failure

gltools.Terminate()

Terminate GLFW

gltools.GetTime() → double

Get current time since call to Init as float value

gltools.SetTime(double time)

Sets current time

gltools.SetGamma(float gamma)

Set gamma value

gltools.GetDesktopSize() → tuple

Return desktop size

Window

class gltools.Window

Window(int width=-1, int height=-1, title=None, int fullscreen=False)

GLFW based window

If width and height are not set then the window is sized to the current desktop size

static __new__(S, ...) → a new object with type S, a subtype of T
close(self)

Stop main loop and close window

getClipboard(self)

Get clipboard text

getSize(self) → tuple

Get window size

hide(self)

Hide window

iconify(self)

Iconify window

mainLoop(self)

Run main loop.

The main loops waits for events. Mouse move events are special handled to avoid to quick update.

makeContextCurrent(self)

Make window openGL context current

onChar(self, ch)

Callback non-special key pressed

onClose(self) → int

Callback on close request.

onCursorPos(self, int x, int y)

Callback on change of mouse cursor position

onEnter(self, int status)

Callback on mouse pointer enter/leave event

onFocus(self, int status)

Callback on windows focus change

onIconify(self, int status)

Callback on iconify status change

onKey(self, int key, int action)

Callback on key press or relase.

onMouseButton(self, int button, int action)

Callback on mouse button press or release

onRefresh(self)

Callback when refresh of content is requested

onScroll(self, double dx, double dy)

Callback on mouse scroll wheel

onSize(self, int w, int h)

Callback when size changes

restore(self)

Restore window from iconification

setClipboard(self, content)

Set clipboard text

setSize(self, int width, int height)

Set window size

setTitle(self, title)

Set window title

show(self)

Show window

swapBuffers(self)

Swap front and back buffers

__init__

x.__init__(...) initializes x; see help(type(x)) for signature

running

running: ‘int’

UI

class gltools.UI

UI()

Draw UI elements

static __new__(S, ...) → a new object with type S, a subtype of T
anyActive(self) → int

Return true if any ui element is active

beginArea(self, name, int x, int y, int w, int h) → int

Begin fixed area

beginFrame(self, int mx, int my, char mbut, int scroll)

Start frame

beginScrollArea(self, name, int x, int y, int w, int h) → int

Begin scroll area

Up to 10 scroll areas can be used, but not nested.

button(self, text, int enabled, int x=-1, int y=-1, int w=-1, int h=-1) → int

Button element

check(self, text, int checked, int enabled) → int

Check box element

collapse(self, text, subtext, int checked, int enabled) → int

Collapse element

drawLine(self, float x0, float y0, float x1, float y1, float r, ColorRGBA color)

Draw single line

drawRect(self, float x, float y, float w, float h, ColorRGBA color)

Draw rectangle

drawRoundedRect(self, float x, float y, float w, float h, float r, ColorRGBA color)

Draw rounded rectangle

drawText(self, int x, int y, int align, text, ColorRGBA color)

Draw text

endArea(self)

End fixed area

endFrame(self)

End frame

endScrollArea(self)

End scroll area

flush(self)

Flush drawing pipeline

indent(self)

Indent current x position

item(self, text, int enabled) → int

Item element

label(self, text)

Text label (left aligned)

separator(self)

Add horisontal separator space

separatorLine(self)

Add horisontal separator line

slider(self, text, float val, float vmin, float vmax, float vinc, int enabled) → float

Horisontal slider

unindent(self)

Unindent current x position

value(self, text)

Text label (right aligned)

__init__

x.__init__(...) initializes x; see help(type(x)) for signature

GLFW Constants

ACTION

gltools.ACTION.PRESS
gltools.ACTION.RELEASE

MOUSE

gltools.MOUSE.LEFT
gltools.MOUSE.RIGHT
gltools.MOUSE.MIDDLE

KEY

gltools.KEY.SPACE
gltools.KEY.ESCAPE
gltools.KEY.ENTER
gltools.KEY.TAB
gltools.KEY.BACKSPACE
gltools.KEY.INSERT
gltools.KEY.DELETE
gltools.KEY.RIGHT
gltools.KEY.LEFT
gltools.KEY.DOWN
gltools.KEY.UP
gltools.KEY.PAGE_UP
gltools.KEY.PAGE_DOWN
gltools.KEY.HOME
gltools.KEY.END
gltools.KEY.CAPS_LOCK
gltools.KEY.SCROLL_LOCK
gltools.KEY.NUM_LOCK
gltools.KEY.PRINT_SCREEN
gltools.KEY.PAUSE
gltools.KEY.F1
gltools.KEY.F2
gltools.KEY.F3
gltools.KEY.F4
gltools.KEY.F5
gltools.KEY.F6
gltools.KEY.F7
gltools.KEY.F8
gltools.KEY.F9
gltools.KEY.F10
gltools.KEY.F11
gltools.KEY.F12
gltools.KEY.LEFT_SHIFT
gltools.KEY.LEFT_CONTROL
gltools.KEY.LEFT_ALT
gltools.KEY.RIGHT_SHIFT
gltools.KEY.RIGHT_CONTROL
gltools.KEY.RIGHT_ALT

OpenGL

gltools.InitGLExt()

Initialize OpenGL 2.1 extension

Raise GLError if extensions not found

gltools.Check() → int

Check for OpenGL errors.

Raises GLError.

gltools.BeginText()

Start text drawing

gltools.DrawText(size, float x, float y, text) → float

Draw text

Size :font size
X :x coordinate
Y :y coordinate
Text :text (must encode to UTF-8)
gltools.EndText()

Finish text drawing. This will flush any pending text drawing operations.

gltools.AmbientLight(ColorRGBA col)

Set global ambient light color.

gltools.BlendFunc(unsigned int sfactor, unsigned int dfactor)

Specify pixel arithmetic

Sfactor :Specifies how the red, green, blue, and alpha source blending factors are computed. The initial value is GL_ONE.
Dfactor :Specifies how the red, green, blue, and alpha destination blending factors are computed. gl.ONE_MINUS_SRC_COLOR etc.
gltools.Clear(unsigned int mask)

Clear selected buffers to preset values.

Mask :bit flags are gl.COLOR_BUFFER_BIT, gl.DEPTH_BUFFER_BIT, and gl.STENCIL_BUFFER_BIT
gltools.ClearColor(ColorRGBA col)

Specify clear values for the color buffers

gltools.ClearDepth(double depth)

Specify the clear value for the depth buffer

gltools.Color(ColorRGBA col)

Sets the current color.

gltools.Disable(unsigned int cap)

Disable server-side GL capabilities

gltools.DrawArrays(unsigned int mode, int first, int count)

Render primitives from array data

Mode :Primitive type gl.POINTS, gl.LINE_STRIP, etc.
First :Specifies the starting index in the enabled arrays.
Count :Specifies the number of indices to be rendered.
gltools.DrawElements(unsigned int mode, int count, int type, indices)

Render primitives from array data with indices.

Mode :Primitive type gl.POINTS, gl.LINE_STRIP, etc.
Count :Specifies the number of indices to be rendered.
Type :Indices data type. One of gl.UNSIGNED_BYTE, gl.UNSIGNED_SHORT, or gl.UNSIGNED_INT
Indices :Either a python object with valid buffer interface or and integer as a pointer into a already bound ClientBuffer of element array type.
gltools.Hint(int target, int mode)

specify implementation-specific hints

gltools.Enable(unsigned int cap)

Enable server-side GL capabilities

gltools.LineWidth(float width)

Specify the width of rasterized lines

gltools.LightModeli(int pname, int param)

Sets lighting model parameters.

Example::
gl.LightModeli(gl.LIGHT_MODEL_TWO_SIDE, gl.TRUE)
gltools.LoadIdentity()

Replace the current matrix with the identity matrix

gltools.LoadMatrixd(Transform tr)

Replace the current matrix with given matrix.

gltools.MatrixMode(unsigned int mode)

Specify which matrix is the current matrix

Mode :gl.MODELVIEW, gl.PROJECTION, or gl.TEXTURE
gltools.Ortho(double left, double right, double bottom, double top, double zNear, double zFar)

Multiply the current matrix with an orthographic matrix

Left :Specify the coordinates for the left vertical clipping plane.
Right :Specify the coordinates for the vertical clipping plane.
Bottom :Specify the coordinates for the bottom horizontal clipping plane.
Top :Specify the coordinates for the top horizontal clipping plane.
Znear :Specify the distances to the nearer clipping plane.
Zfar :Specify the distances to the farther depth clipping plane.
gltools.PolygonMode(unsigned int face, unsigned int mode)

Select a polygon rasterization mode

Example::
gl.PolygonMode(gl.FRONT_AND_BACK, gl.FILL)
gltools.PolygonOffset(float factor, float units)

Set the scale and units used to calculate depth values

Factor :Specifies a scale factor that is used to create a variable depth offset for each polygon.
Units :Is multiplied by an implementation-specific value to create a constant depth offset.
gltools.ReadPixel(int x, int y) → ColorRGBA

Read a sigle pixel from the frame buffer.

gltools.ReadPixels(int x, int y, Image img)

Read a block of pixels from the frame buffer

gltools.Viewport(int x, int y, int width, int height)

Set the viewport

X :x coordiante of lower left corner.
Y :y coordiante of lower left corner.
Width :viewport width
Height :viewport height

OpenGL Constants

AlphaFunction

gltools.NEVER
gltools.LESS
gltools.EQUAL
gltools.LEQUAL
gltools.GREATER
gltools.NOTEQUAL
gltools.GEQUAL
gltools.ALWAYS

AttribMask

gltools.CURRENT_BIT
gltools.POINT_BIT
gltools.LINE_BIT
gltools.POLYGON_BIT
gltools.POLYGON_STIPPLE_BIT
gltools.PIXEL_MODE_BIT
gltools.LIGHTING_BIT
gltools.FOG_BIT
gltools.DEPTH_BUFFER_BIT
gltools.ACCUM_BUFFER_BIT
gltools.STENCIL_BUFFER_BIT
gltools.VIEWPORT_BIT
gltools.TRANSFORM_BIT
gltools.ENABLE_BIT
gltools.COLOR_BUFFER_BIT
gltools.HINT_BIT
gltools.EVAL_BIT
gltools.LIST_BIT
gltools.TEXTURE_BIT
gltools.SCISSOR_BIT
gltools.ALL_ATTRIB_BITS

BeginMode

gltools.POINTS
gltools.LINES
gltools.LINE_LOOP
gltools.LINE_STRIP
gltools.TRIANGLES
gltools.TRIANGLE_STRIP
gltools.TRIANGLE_FAN
gltools.QUADS
gltools.QUAD_STRIP
gltools.POLYGON

Vertex Arrays

gltools.VERTEX_ARRAY
gltools.NORMAL_ARRAY
gltools.COLOR_ARRAY
gltools.INDEX_ARRAY
gltools.TEXTURE_COORD_ARRAY
gltools.EDGE_FLAG_ARRAY

BlendingFactorDest

gltools.ZERO
gltools.ONE
gltools.SRC_COLOR
gltools.ONE_MINUS_SRC_COLOR
gltools.SRC_ALPHA
gltools.ONE_MINUS_SRC_ALPHA
gltools.DST_ALPHA
gltools.ONE_MINUS_DST_ALPHA

BlendingFactorSrc

gltools.DST_COLOR
gltools.ONE_MINUS_DST_COLOR
gltools.SRC_ALPHA_SATURATE

Boolean values

gltools.FALSE
gltools.TRUE

Datatypes

gltools.BYTE
gltools.UNSIGNED_BYTE
gltools.SHORT
gltools.UNSIGNED_SHORT
gltools.INT
gltools.UNSIGNED_INT
gltools.FLOAT
gltools.DOUBLE

DrawBufferMode

gltools.NONE
gltools.FRONT_LEFT
gltools.FRONT_RIGHT
gltools.BACK_LEFT
gltools.BACK_RIGHT
gltools.FRONT
gltools.BACK
gltools.LEFT
gltools.RIGHT
gltools.FRONT_AND_BACK
gltools.AUX0
gltools.AUX1
gltools.AUX2
gltools.AUX3
gltools.CW
gltools.CCW

GetTarget

gltools.DEPTH_TEST
gltools.BLEND
gltools.DITHER
gltools.CULL_FACE

MatrixMode

gltools.MODELVIEW
gltools.PROJECTION
gltools.TEXTURE

Lines

gltools.LINE_SMOOTH

PolygonMode

gltools.POINT
gltools.LINE
gltools.FILL
gltools.POLYGON_OFFSET_LINE
gltools.POLYGON_OFFSET_FILL

ShadingModel

gltools.FLAT
gltools.SMOOTH

Hints

gltools.PERSPECTIVE_CORRECTION_HINT
gltools.POINT_SMOOTH_HINT
gltools.LINE_SMOOTH_HINT
gltools.POLYGON_SMOOTH_HINT
gltools.FOG_HINT
gltools.DONT_CARE
gltools.FASTEST
gltools.NICEST

Lighting

gltools.LIGHTING
gltools.LIGHT0
gltools.LIGHT1
gltools.LIGHT2
gltools.LIGHT3
gltools.LIGHT4
gltools.LIGHT5
gltools.LIGHT6
gltools.LIGHT7
gltools.LIGHT_MODEL_TWO_SIDE

Images

gltools.RGB
gltools.RGBA

Texture

gltools.TEXTURE_2D

GLEXT

gltools.MULTISAMPLE
gltools.STATIC_DRAW
gltools.ARRAY_BUFFER
gltools.ELEMENT_ARRAY_BUFFER