Hi,
I've finally had a chance to write some code to try and do this and it
just
doesn't seem to display anything. I'm probably doing something
stupid, but
I can't see it. I've set up a minimal test case that replicates what
i'm
doing in my app (below), and it also fails to display anything. Is
there a
flag i'm missing? Gary, does this look similar to what you do in your
code?
It looks to be doing the same thing as your example too incantus
(thanks for that),
but i'm not using textures or colourpointers.
Thanks,
Jamie
from pyglet import window
from pyglet.gl import *
import pyglet
from pyglet.window import key
import random as rd
import ctypes
from numpy import *
class VertexArrayTest(pyglet.window.Window):
def __init__(self):
super(VertexArrayTest,self).__init__(800,600)
self.glInit()
self.setupVA()
def glInit(self):
glClearColor(0, 0, 0, 0.0)
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
glOrtho(0.0, 800.0, 0.0, 600.0, 0, 20.0)
glMatrixMode(GL_MODELVIEW)
glEnable(GL_DEPTH_TEST)
glEnable(GL_VERTEX_ARRAY)
glLoadIdentity()
def setupVA(self):
self.vertarray=array([])
for i in range(50):
self.vertarray=append(self.vertarray,[10,10])
self.vertarray=append(self.vertarray,[10,20])
self.vertarray=append(self.vertarray,[20,20])
self.vertarray=append(self.vertarray,[20,10])
#self.vertarray=self.vertarray.reshape(50*4,2)
def on_draw(self):
glClear(GL_COLOR_BUFFER_BIT)
glLoadIdentity()
glEnableClientState(GL_VERTEX_ARRAY)
glPushClientAttrib(GL_CLIENT_VERTEX_ARRAY_BIT)
self.cverts = ascontiguousarray(self.vertarray)
glColor4f(1,0,1,1)
glVertexPointer(2,GL_FLOAT,
0,self.cverts.ctypes.data_as(ctypes.POINTER(ctypes.c_float)))
glDrawArrays(GL_QUADS,0,50)
glPopClientAttrib()
vat=VertexArrayTest()
pyglet.app.run()
On Mar 28, 3:50 pm, Gary Herron <[EMAIL PROTECTED]> wrote:
> Jamie wrote:
> > Hi,
>
> > I'm just starting to have a play with pyglet as a warm-up for pyweek
> > next week and I really like it. At the moment i'm just playing around
> > with particles and I was wondering if it's possible to use a numpy
> > array with glVertexPointer. I want to can use numpy's fast
> > manipulation of arrays to move the particles in the array around, then
> > pass this array straight through as a vertex array. Is this possible
> > at all? I know glVertexPointer expects a ctypes array, but is there
> > any way to convert between the two? Numpy arrays now have a ctypes
> > property to allow their data to be accessed from C, but i'm guessing
> > it's not as simple as that as it probably doesn't contain GLFloats?
>
> > Is there any other way to quickly manipulate a large array without
> > using numpy that I should be looking at instead? I'm struggling with
> > frame-rates when doing it in pure python.
>
> > Thanks,
>
> > Jamie
>
> Yes, it is easily done, and the conversion is a one-liner that does
> *not* copy the array. Here's the several relevant lines of code pulled
> directly from my pyglet application. This works on Python2.5, Windows
> and Linux, with pyglet 1.0 and 1.1.
>
> def PointerToNumpy(a, ptype=ctypes.c_float):
> a = numpy.ascontiguousarray(a) # Probably a NO-OP, but
> perhaps not
> return a.ctypes.data_as(ctypes.POINTER(ptype)) # Ugly and undocumented!
>
> glVertexPointer(3, GL_FLOAT, 0, PointerToNumpy(VertexData))
>
> Hope that helps,
>
> Gary Herron
>
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"pyglet-users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/pyglet-users?hl=en
-~----------~----~----~----~------~----~------~--~---