Re: [PyOpenGL-Users] glVertexAttribPointer(); loading platform-specific functions
Brought to you by:
mcfletch
From: Joshua D. <joshuardavis@q.com> - 2009-08-14 19:55:16
|
>> This is a bug in the shaders module. Turns out that >> glGetProgramivARB > and glGetProgramiv have different roles?! Basically it looks like > it's > glGetObjectParameteriv that's supposed to be used for the > glGetProgramiv > validity check call (at least, if I use that and disable core GL I get > the correct operation). Going to have to look into the function > definitions more to be sure that the alternate declaration works. Your changes to shaders.py have gotten me past that problem. Thanks very much. I now have two versions of my program. The first uses the legacy glVertexPointer() stuff and works perfectly. The second is altered, as little as possible, so that it uses the modern glVertexAttribPointer() stuff instead. It raises no errors but generates no fragments. Here is the glVertexPointer() version of the two crucial functions... def initializeShaders(): global shaderProgram vertexCode = """ void main() { gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; gl_FrontColor = gl_Color; }""" fragmentCode = """ void main() { gl_FragColor = gl_Color; }""" vertexShader = compileShader(vertexCode, GL_VERTEX_SHADER) fragmentShader = compileShader(fragmentCode, GL_FRAGMENT_SHADER) shaderProgram = compileProgram(vertexShader, fragmentShader) def handleDisplayEvent(): global vertexBufferObject, shaderProgram glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glUseProgram(shaderProgram) vertexBufferObject.bind() glEnableClientState(GL_VERTEX_ARRAY) glEnableClientState(GL_COLOR_ARRAY) glVertexPointer(3, GL_FLOAT, 24, vertexBufferObject) glColorPointer(3, GL_FLOAT, 24, vertexBufferObject + 12) glDrawArrays(GL_TRIANGLES, 0, 9) vertexBufferObject.unbind() glDisableClientState(GL_VERTEX_ARRAY) glDisableClientState(GL_COLOR_ARRAY) glUseProgram(0) glFlush() glutSwapBuffers() ...and here are those same functions, rewritten to use glVertexAttribPointer(). def initializeShaders(): global shaderProgram, positionLocation, colorLocation vertexCode = """ attribute vec3 position; attribute vec3 color; void main() { gl_Position = gl_ModelViewProjectionMatrix * vec4(position, 1.0); gl_FrontColor = vec4(color, 1.0); }""" fragmentCode = """ void main() { //gl_FragColor = gl_Color; gl_FragColor = vec4(1.0, 0.0, 1.0, 1.0); }""" vertexShader = compileShader(vertexCode, GL_VERTEX_SHADER) fragmentShader = compileShader(fragmentCode, GL_FRAGMENT_SHADER) shaderProgram = compileProgram(vertexShader, fragmentShader) positionLocation = glGetAttribLocation(shaderProgram, 'position') colorLocation = glGetAttribLocation(shaderProgram, 'color') def handleDisplayEvent(): global vertexBufferObject, shaderProgram, positionLocation, colorLocation glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glUseProgram(shaderProgram) vertexBufferObject.bind() glEnableVertexAttribArray(positionLocation) glEnableVertexAttribArray(colorLocation) glVertexAttribPointer(positionLocation, 3, GL_FLOAT, False, 24, vertexBufferObject) glVertexAttribPointer(colorLocation, 3, GL_FLOAT, False, 24, vertexBufferObject + 12) glDrawArrays(GL_TRIANGLES, 0, 9) vertexBufferObject.unbind() glDisableVertexAttribArray(positionLocation) glDisableVertexAttribArray(colorLocation) glUseProgram(0) glFlush() glutSwapBuffers() Am I missing something obvious? Any suggestions on how to debug further? Josh |