Fast 2D Raster Rendering with GUI

Chris Mellon arkanes at gmail.com
Tue Mar 18 13:47:26 EDT 2008


On Tue, Mar 18, 2008 at 12:30 PM, sturlamolden <sturlamolden at yahoo.no> wrote:
> On 18 Mar, 17:48, Miki <miki.teb... at gmail.com> wrote:
>
>  > Apart from PIL, some other options are:
>  > 1. Most GUI frameworks (wxPython, PyQT, ...) give you a canvas object
>  > you can draw on
>
>  Yes, but at least on Windows you will get a GDI canvas. GDI is slow.

Of all the major platforms, GDI is probably the fastest for basic
pixel-level interaction with the screen. I have no idea why you think
it's slow.

>
>
>
>  > 2. A bit of an overkill, but you can use PyOpenGL
>
>  OpenGL gives you a fast 'bitblit' for drawing bitmaps to the fram
>  buffer (much faster than GDI). Here is some C code that does that (8-
>  bit color depth). Translating to Python is trivial. I prefer not to
>  use PyOpenGL as it has some unwanted overhead. It is better to use
>  ctypes.
>
>
>  void bitblt(void *frame, int w, int h)
>  {
>         glViewport(0,0,w,h);
>         glClearColor(0.0, 0.0, 0.0, 0.0);
>         glClear(GL_COLOR_BUFFER_BIT);
>         glMatrixMode(GL_PROJECTION);
>         glLoadIdentity();
>         gluOrtho2D(0.0, (GLfloat)w, 0.0, (GLfloat)h);
>         glMatrixMode(GL_MODELVIEW);
>         glLoadIdentity();
>         glRasterPos2i(0,0);
>         glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
>         glDrawPixels(w, h, GL_RGB, GL_UNSIGNED_BYTE_3_3_2, (GLvoid *)frame);
>         glFlush();
>
>
> }
>

OpenGL is totally unsuitable if the goal is to implement your own
pixel-level raster drawing.



More information about the Python-list mailing list