Thanks for the pointer to Cairo, that looks like a very useful tool, and 
I'm definitely going to try and learn it as I find a need for more 
graphical capabilities.  Right now I'm working on a roguelike, so it's 
mostly sprites, and I just want to make a rectangle for 
background/whitespace.
 
Unfortunately I am still too dense to understand your code in the example.  
Perhaps what I should really be asking for is some kind of introduction or 
tutorial to help me understand how OpenGL works.  Anybody know of such a 
resource?
 
One thing I've already figured out is how to import images from external 
files, and even how to write new images by manipulating the ImageData 
object.  I wonder, is it possible to "stretch out" an image by arbitrarily 
changing its height and width parameters?  If so, I could quickly create 
rectangles at least by stretching a one-pixel resource image.  I know 
that'd be a hack, but would it work?
 
joe
 

On Tuesday, March 5, 2013 2:12:36 AM UTC-6, chup wrote:

> Hi
>
> Pyglet lacks a surface like pygame has so it doesn't support 2D primitives 
> out of the box (unless you draw the polygons directly in openGL). One 
> alternative I quite like is to use a pycairo surface to draw primitives and 
> then use that as a texture in pyglet. 
> See below for an example.
>
> Regards
> Martin
>
> import pyglet
> import ctypes
> import cairo
>
> WIDTH = 800
> HEIGHT = 600
>
> window = pyglet.window.Window(width=WIDTH, height=HEIGHT)
>
> #cairo
> data = (ctypes.c_ubyte * WIDTH * HEIGHT * 4)()
> stride = WIDTH * 4
> surface = cairo.ImageSurface.create_for_data (data, cairo.FORMAT_RGB24, 
> WIDTH, HEIGHT, stride);
> ctx = cairo.Context(surface)
> ctx.translate(200, 200)
>
> #pyglet
> texture = pyglet.image.Texture.create_for_size(pyglet.gl.GL_TEXTURE_2D, 
> WIDTH, HEIGHT, pyglet.gl.GL_RGB)
>
> @window.event
> def on_draw():
>     ctx.set_source_rgb(0, 1, 0)
>     ctx.rectangle(5, 5, 50, 50)
>     ctx.fill()
>     
>     window.clear()
>     
>     pyglet.gl.glEnable(pyglet.gl.GL_TEXTURE_2D)
>     pyglet.gl.glBindTexture(pyglet.gl.GL_TEXTURE_2D, texture.id)
>     
>     pyglet.gl.glTexImage2D(pyglet.gl.GL_TEXTURE_2D, 0, pyglet.gl.GL_RGBA, 
> WIDTH, HEIGHT, 1, pyglet.gl.GL_BGRA, pyglet.gl.GL_UNSIGNED_BYTE, data)
>     
>     pyglet.gl.glBegin(pyglet.gl.GL_QUADS)
>     pyglet.gl.glTexCoord2f(0.0, 1.0)
>     pyglet.gl.glVertex2i(0, 0)
>     pyglet.gl.glTexCoord2f(1.0, 1.0)
>     pyglet.gl.glVertex2i(WIDTH, 0)
>     pyglet.gl.glTexCoord2f(1.0, 0.0)
>     pyglet.gl.glVertex2i(WIDTH, HEIGHT)
>     pyglet.gl.glTexCoord2f(0.0, 0.0)
>     pyglet.gl.glVertex2i(0, HEIGHT)
>     pyglet.gl.glEnd()
>     
>     ctx.set_source_rgb(0, 0, 0)
>     ctx.paint()
>
> pyglet.app.run()
>
>
> On Tue, Mar 5, 2013 at 1:44 AM, Joseph Clark <[email protected]<javascript:>
> > wrote:
>
>> I know this is a newbie question, but can anybody shed light on how to 
>> use Pyglet draw a simple primitive like a filled rectangle?  I can't 
>> believe that a web search didn't turn up any examples, but it didn't.  And 
>> the OpenGL documentation is impenetrable to me.
>>  
>> One article I found (http://www.akeric.com/blog/?p=1510) points to a '2d 
>> drawing primitives module' apparently uploaded to this Google group some 
>> years ago, but the link is dead now.  That's as close as I've got.
>>  
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "pyglet-users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to [email protected] <javascript:>.
>> To post to this group, send email to [email protected]<javascript:>
>> .
>> Visit this group at http://groups.google.com/group/pyglet-users?hl=en.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>  
>>  
>>
>
>
>
> -- 
> to do is to be. dobedobedo 

-- 
You received this message because you are subscribed to the Google Groups 
"pyglet-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/pyglet-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to