VertexArray - Rabbyt Reference

Documentation Index | From module rabbyt.vertexarrays.

# VertexArray

`VertexArray(mode="QUADS", use_colors=True)`

OpenGL vertex arrays provide a way to push a large amount of data to the video hardware, very fast. `VertexArray` provides an easy to use class to take advantage of this speed.

`VertexArray` supports both item access and assignment using `VertexInfo` objects. For example, this would work as expected:

>     vertex_array[0].x += 1

You can also assign using tuples, just like as documented in the append method:

>     vertex_array[0] = (x, y, u, v, red, green, blue, alpha)

## Methods

### append

`append(vertex)`

Appends a vertex to the array.

vertex should be a tuple of the form `(x,y,u,v,red,green,blue,alpha)`. (You can also make the tuple shorter; any missing values will be left at the default.)

Note that `vertex` doesn't need to be a tuple, but anything supporting item access. This includes `VertexInfo` instances.

### enable_arrays

`enable_arrays()`

Calls the `glEnableClientState` and `gl*Pointer` functions to set up this `VertexArray` for usage. This is automatically called when you call `render()`.

If you use vertex arrays with PyOpenGL elsewhere in your program, you should always wrap this method in `glPushClientAttrib`/`glPopClientAttrib`.

### extend

`extend(vertexes)`

Iterates over vertexes, calling `append(vertex)` on each one.

### render

`render([start,] [end])`

Renders the array!

`start` and `end` can be specified to only render part of the array.

### set_size

`set_size(size)`

Sets the size explicitly.

This is an alternative to using `append` and `extend`. (It should be a little faster.)

## Properties

### mode

The default primitive drawing mode.

Valid modes are "QUADS", "QUAD_STRIP", "TRIANGLES", "TRIANGLE_STRIP", "TRIANGLE_FAN", "LINES", "LINE_STRIP", "LINE_LOOP", or "POINTS". These corrispond directly to the OpenGL privitive drawing modes. (In fact, you can also use the OpenGL enumerations instead of the strings, if you prefer.)

### texture_id

The texture used when `render()` is called.

If `None` (the default) texturing isn't touched. This is useful if you want to bind the texture yourself.

If `0`, texturing is disabled.

If it is a positive integer (other than 0,) the given texture will be bound when rendering.

### use_colors

If `True`, (the default,) the color data in the vertex array will be used. Otherwise, the previous color will be used for all vertexes. (such as set by `rabbyt.set_gl_color()`.)