Re: New user trying tutorial
Berlioz Silver <[email protected]> Sat, 30 Aug 2014 13:10:05 -0700
| Newsgroups | gmane.comp.python.opengl.user |
|---|---|
| Message-ID | <CAG6TPhB5tsbXvfpy+ha1A7QdnAjJ5baPp0Trh1erDvTtcHVZVw@mail.gmail.com> |
Sorry, just figured it out. I'd still like to know if there are other good tutorials though. On Sat, Aug 30, 2014 at 1:07 PM, Berlioz Silver <[email protected]> wrote: > 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() > ------------------------------------------------------------------------------ Want excitement? Manually upgrade your production database. When you want reliability, choose Perforce Perforce version control. Predictably reliable. http://pubads.g.doubleclick.net/gampad/clk?id=157508191&iu=/4140/ostg.clktrk _______________________________________________ PyOpenGL Homepage http://pyopengl.sourceforge.net _______________________________________________ PyOpenGL-Users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/pyopengl-users