[PyOpenGL-Users] vertex/texture arrays
Brought to you by:
mcfletch
|
From: Frank R. <cra...@gm...> - 2002-01-06 15:38:22
|
Hello,
I'm new to OpenGL and made some pretty good experiences with
PyOpenGL so far. But now I've hit vertex arrays and there are
some points I'm consistently appearing problems with.
I'm using PyOpenGL 2.0.0.44 with pygame-1.3.
I now created a list of (x,y,z) tuples for my vertices and
a list of (u,v) tuples for the texture coords. I first
ignored textures and used glVertexPointerf only which
worked perfectly. But I couldn't get it to work using the
older(?) glVertexPointer.
The second problem is a little bit more complicated. I tried
to use glTexCoordPointerf with my list of texture coords.
To be able to do that I enabled the appropriate states and
generated a texture. But the whole app crashed when calling
glTexCoordPointerf(list_of_texcoords)
giving me an OpenGL error: Invalid operation
The same happened when I used the glTexCoordPointer method.
Here's the problem code used:
8<======
# just enabling the arrays
glEnableClientState(GL_VERTEX_ARRAY)
glEnableClientState(GL_COLOR_ARRAY)
glEnableClientState(GL_TEXTURE_COORD_ARRAY)
# prepare texturing
glEnable(GL_TEXTURE_2D)
self.textures = glGenTextures(2) # only first texture used in this sample
# create dummy texture
surf = pygame.Surface((64,64))
surf.subsurface((32,0,32,32)).fill((255,255,255))
surfdata = pygame.image.tostring(surf,"RGBX",1)
# setup the texture
glBindTexture(GL_TEXTURE_2D,self.textures[0])
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST)
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST)
glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA, 64,64,0,GL_RGBA,GL_UNSIGNED_BYTE,surfdata)
vertices = [] # list of (x,y,z) tuples
mx,my = 50,50 # just a dimension to create 2601 vertices
colors = [] # list of (r,g,b) tuples
texcoords = [] # list of (u,v) tex coords
# a loop to get the appropriate values
for j in range(my+1):
for i in range(mx+1):
vertices.append((0.32*i,-0.32*j,0))
colors.append((random.random(),random.random(),random.random()))
texcoords.append( ( i%2, j%2 ) )
# prepare vertex arrays
# this works fine (also displays the expected output later)
glVertexPointerf(vertices)
# this doesn't work. leaves me with a blank screen
#glVertexPointer(3,GL_FLOAT,0,vertices)
# this works again (similar to the vertices)
glColorPointerf(colors)
# this line crashes with an invalid operation error
glTexCoordPointerf(texcoords)
# and this one crashes as well
#glTexCoordPointer(2,GL_FLOAT,0,texcoords)
=====>8
I appreciate any help I can get with this. I already tried RTFM and STFW
but couldn't find any fixes. Thanks.
|