Skip to main content

A 2D Graphics Library for PyGame and PyOpenGL.

Project description


A 2D Graphics Library for PyGame using PyOpenGL.


- Python v2.5.2 -
- PyGame v1.8.1 -
- PyOpenGL v3.0.0b5 -



PyGL2D's draw module lets you render graphics primitives, including
lines, polygons, circles, and rects. It supports antialiasing,
alpha/transparency, and coloring. Remember colors in this module
are based on an RGB scale of 0-255.

draw.line(point1, point2, color, width=1, aa=True, alpha=255.0)

Draw a line from point1 to point2. color is the color of the line on an RGB
scale, width is the width of the line, aa is whether or not to antialias the
lines, and alpha is the alpha of the line.

draw.lines(points, color, width=1, aa=True, closed=0, alpha=255.0)

Draw a series of lines. Note that the edges of the lines with thick widths are

draw.polygon(points, color, aa=True, alpha=255.0)

Draw a filled polygon. This does not suffer from the "blocky" artifact.

draw.rect(rectstyle, color, width=0, alpha=255.0)

Draw a rect. rectstyle should be a tuple or list in the style of
(x, y, width, height). You can use width to set the width of the rect's edges
(and take out it's color filling), radius, color, alpha=255.0)

Draw a circle at pos. radius should be the radius of the angle. Note that this
function is VERY slow, as it is just a series of lines drawn at an angle.


The PyGL2D RenderText class allows you to render text with pygame fonts.
It also allows you to perform transformations to it, such as rotation,
scaling, and coloring.

class RenderText(object)

__init__(text, color, font)

create a text to be rendered.

change_text(text, color='default') <- return None

change the text string. Leave color at 'default' if you want to use the previous color.


draw the text at 'pos'. Note that pos is the topleft of the text.


rotate the text to 'rotation', on a scale of 0-360 degrees.


scale the text to 'scale', where 1.0 is the default scale of the text.

colorize(r, g, b, a)

color the text on an RGBA scale. Remember this uses numeral from 0-255.


Delete the text rendering from the memory, including it's opengl textures.

get_width(), get_height()

return the text's width and height.


return a rect the size of the text.


PyGL2D's geometry module lets you execute some simple geometry functions, such
as circle collisions and line collisions. It has some other functions, but
they're not working correctly right now. Sorry!

geometry.line_collision(a, b) <- return bool

Detects a collision between line a, and line b.

geometry.poly_collision(poly1, poly2) <- return bool

Detects a collision between two polys.

geometry.circle_collision(p1, p2, r1, r2) <- return bool

Detects a collision between 2 circles. p1 and r1 should be the position and
radius of the first circle, respectively. p2 and r2 should be the position and
radius of the second circle, respectively.


The Image object for PyGL2D allows you to load images and draw them. It also
lets you perform transformations, such as scaling, rotating, and coloring.
Remember when drawing the image that (0, 0) is the topleft corner of the screen.

class Image(object)

__init__(filename) <- return None

initialise the Image. filename should be a path to the image file. Note that it
CAN also be a pygame Surface.

delete() <- return None

delete the image from the memory, including it's OpenGL texture.

draw(pos) <- return None

draws the image to the main screen at pos. Currently does not support drawing
to other images.

scale(scale) <- return None

scale the image where 1.0 is the image's default size.

rotate(rotation) <- return None

rotate the image to the angle (rotation) given in degrees. e.g. image.scale(45)

colorize(r, g, b, a) <- return None

color the image on an RGBA scale of 0-255. If you want to make your image
transparent, use the "a" value.

get_width(self) <- return int

returns the width of the original image. Does not provide alterations when the
image is rotated, but it does support alterations in scaling.

get_height(self) <- return int

functions the same as get_width(), only it returns the image's height instead
of width

get_rect(self) <- return rect.Rect

returns a rect the size of the image.


PyGL2D's rect module provides a class similar to pygame's rect. It supports
floating point numbers, but it misses alot of pygame's rect functions.

class rect.Rect(object)

__init__(self, x, y, w, h)

init the Rect. x and y should be its topleft position, and w and h should be
its width and height.

move(dx, dy) <- return Rect

Create a new rect moved the amount of dx and dy.

move_ip(dx, dy)

Move the rect the amount of dx and dy.


Check for a collision between another rect.


Check for a collision between the rect and a point.


PyGL2D's window module is for setting up the window for drawing.

window.init(size, caption="", flags=DOUBLEBUF)

Initialise the SDL/PyGame window.


Call this right before you begin drawing your objects.


And always call this after you're done drawing.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for PyGL2D, version 0.3.7
Filename, size File type Python version Upload date Hashes
Filename, size PyGL2D-0.3.7.tar.gz (8.8 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page