[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] getting setup to use PyOpenGL for 2D



On Monday 28 November 2005 22:57, Jasper fired a shotgun at the keyboard and 
the following appeared:
> Matt Bailey wrote:
> >Speaking of which....anyone got a barebones sample of how to get an
> >OpenGL-ready object from an image file using pygame.image? I'm using PIL
> >right now but only because the only examples I could find used it.
>
> OpenGL is C based state machine (and not object orientated), so I'm not
> exactly sure what you mean....  I'm guessing you want to convert your
> file into a texture for use by OpenGL, and have provided a stripped down
> version of what I use to do this.  This example assumes your image's
> size is a power of 2; you could probably also strip all the
> glTexParameteri() calls and just accept defaults.
>
>
> import pygame
> from OpenGL.GL import *
>
> surf          = pygame.image.load( filePath )
> imageStr      = pygame.image.tostring( surf, 'RGBA', 0 )
> width, height = surface.get_size()
<snip>

	Thanks Jasper, this is what I needed. I've got the OpenGL stuff ok, I just 
didn't know the exact method for using Pygame to load an image from disk and 
get it ready for OpenGL to use. As I suspected, it's simpler than I 
suspected, and slightly more straightforward than PIL. :)

	-Matt Bailey