Re: [PyOpenGL-Users] glVertexAttribPointer(); loading platform-specific functions
Brought to you by:
mcfletch
From: Mike C. F. <mcf...@vr...> - 2009-08-13 16:10:45
|
Joshua Davis wrote: > I have some questions that probably boil down to my inexperience with > Python. My setup is PyOpenGL-3.0.0c1 on Python 2.5.x on Mac OS X. I'm > trying to modernize my OpenGL to use VBOs and vertex attributes, > working through the tutorials at http://bazaar.launchpad.net/ > ~mcfletch/openglcontext/trunk/annotate/head:/tests/shader_4.py. When > I execute code like this: > > vertexBufferObject = vbo.VBO(...) > gl.glVertexAttribPointer(positionLocation, 3, GL_FLOAT, False, 24, > vertexBufferObject) > The "gl." should not be necessary, PyOpenGL 3.x includes full access to the OpenGL 2.x functionality. The wiki sample you are looking at is *very* old, unfortunately, the wiki editor seems broken, so I can't update it without completely hashing the page :( . The vbo.VBO object uses PyOpenGL's wrapping functionality to appear as though it is a data-array pointer, but that behaviour is not available in raw ctypes wrappers (such as the wiki recipe is creating). from OpenGL.GL import * should get you a copy of glVertexAttribPointer without needing to do anything else (particularly, without using any ctypes code explicitly). If you need the ARB versions, they are available via: from OpenGL.GL.ARB.vertex_buffer_object import * I'd also *strongly* suggest going for PyOpenGL 3.0.0 final or even a PyOpenGL 3.0.1 alpha, as there were quite a number of bug-fixes and enhancements. The latest 3.0.1 alpha has an OpenGL.GL.shaders module which provides "alternate" wrapped versions of the shader functions which allow for using either core or ARB-provided versions of the functions depending on what's available on the final machine. That isn't necessary, but it should make it easier to work with shaders in PyOpenGL. The tutorials you're following through were written against PyOpenGL 3.0.1 alpha (actually bzr head), so operations such as "compileShader()" are not going to be available in your older PyOpenGL release. If you're working on a Linux machine where 3.0.0c1 is the current PyOpenGL package, you may want to set up a "virtualenv" environment and install the more recent version there (virtualenv creates a separate Python package namespace where you can work in isolation from system packages). I'll update the tutorial introduction page to mention the version of PyOpenGL that it is written against. The wiki sample code, rewritten for PyOpenGL 3.0.1's shader convenience module (which is, via a number of levels of indirection, loosely based on that wiki recipe, I think) is included below... HTH, Mike #! /usr/bin/env python from pygame import * import pygame from OpenGL.GL import * from OpenGL.GLU import * from OpenGL.GLUT import * from OpenGL.GL.shaders import * if __name__ == '__main__': glutInit(sys.argv) width, height = 640, 480 pygame.init() pygame.display.set_mode((width, height), OPENGL | DOUBLEBUF) program = compileProgram( compileShader( ''' // Vertex program varying vec3 pos; void main() { pos = gl_Vertex.xyz; gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; } ''', GL_VERTEX_SHADER, ), compileShader( ''' // Fragment program varying vec3 pos; void main() { gl_FragColor.rgb = pos.xyz; } ''', GL_FRAGMENT_SHADER ), ) glMatrixMode(GL_PROJECTION) glLoadIdentity() gluPerspective(90.0, width/float(height), 1.0, 100.0) glMatrixMode(GL_MODELVIEW) glEnable(GL_DEPTH_TEST) quit = False angle = 0 while not quit: for e in pygame.event.get(): if e.type in (QUIT, KEYDOWN): quit = True glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glLoadIdentity() glTranslate(0.0, 0.0, -2.5) glRotate(angle, 0.0, 1.0, 0.0) glUseProgram(program) glutSolidTeapot(1.0) angle += 0.1 pygame.display.flip() -- ________________________________________________ Mike C. Fletcher Designer, VR Plumber, Coder http://www.vrplumber.com http://blog.vrplumber.com |