[PyOpenGL-Users] New user trying tutorial
Brought to you by:
mcfletch
From: Berlioz S. <roc...@gm...> - 2014-08-30 20:07:08
|
I've been interested in attempting to use pyopengl and pygame together to display 3D images and accelerate my programs. I figured a logical first step would be to learn a bit about pyopengl, so I tried the tutorial. I successfully installed pyopengl on OSX 10.9, and ran the first tutorial. However, the second (introducing color variations http://pyopengl.sourceforge.net/context/tutorials/shader_2.html) fails with a bus error 10. Is there another tutorial I should follow/what mistake did I make that is giving me a segfault? Here is my code: from OpenGLContext import testingcontext BaseContext = testingcontext.getInteractive() from OpenGL.GL import * from OpenGL.arrays import vbo from OpenGL.GL import shaders import numpy as np class TestContext(BaseContext): def OnInit(self): try: VERTEX_SHADER = shaders.compileShader(""" varying vec4 vertex_color; void main(){ gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; vertex_color = gl_Color; }""", GL_VERTEX_SHADER) FRAGMENT_SHADER = shaders.compileShader(""" varying vec4 vertex_color; void main(){ gl_FragColor = vertex_color; }""", GL_FRAGMENT_SHADER) self.shader = shaders.compileProgram(VERTEX_SHADER, FRAGMENT_SHADER) except (GLError, RuntimeError) as err: print "Shader compilation error:", err raise self.vbo = vbo.VBO(np.array([ [ 0, 1, 0, 0,1,0 ], [-1,-1, 0, 1,1,0 ], [ 1,-1, 0, 0,1,1 ], [ 2,-1, 0, 1,0,0 ], [ 4,-1, 0, 0,1,0 ], [ 4, 1, 0, 0,0,1 ], [ 2,-1, 0, 1,0,0 ], [ 4, 1, 0, 0,0,1 ], [ 2, 1, 0, 0,1,1 ], ],'f') ) def Render(self, mode): glUseProgram(self.shader) try: self.vbo.bind() try: glEnableClientState(GL_VERTEX_ARRAY) glEnableClientState(GL_COLOR_ARRAY) #glVertexPointerf(self.vbo) glColorPointer(3, GL_INT, 24, self.vbo+12) glDrawArrays(GL_TRIANGLES, 0, 9) finally: self.vbo.unbind() glDisableClientState(GL_VERTEX_ARRAY) glDisableClientState(GL_COLOR_ARRAY) finally: shaders.glUseProgram(0) if __name__ == "__main__": TestContext.ContextMainLoop() |