Search code examples
python-2.7wxpythonshaderpyopengl

pyOpenGL check for bool


This is my source code https://paste.fedoraproject.org/428184/89404314/

The error I got is this:

C:\Python27>python.exe wx_gl_vbo_001.py
Traceback (most recent call last):
  File "wx_gl_vbo_001.py", line 63, in <module>
    MyApp(redirect = False).MainLoop()
  File "C:\Python27\lib\site-packages\wx-3.0-msw\wx\_core.py", line 8628, in __init__
    self._BootstrapApp()
  File "C:\Python27\lib\site-packages\wx-3.0-msw\wx\_core.py", line 8196, in _BootstrapApp
    return _core_.PyApp__BootstrapApp(*args, **kwargs)
  File "wx_gl_vbo_001.py", line 60, in OnInit
    canvas = MyCanvas(frame)
  File "wx_gl_vbo_001.py", line 16, in __init__
    }""", GL_VERTEX_SHADER)
  File "C:\Python27\lib\site-packages\OpenGL\latebind.py", line 44, in __call__
    self._finalCall = self.finalise()
  File "C:\Python27\lib\site-packages\OpenGL\extensions.py", line 245, in finalise
    self.__name__,
OpenGL.error.NullFunctionError: Attempt to call an undefined alternate function (glCompileShader, glCompileShaderARB), check for bool(glCompileShader) before calling

dir(shaders) come with this functions:

 'compileProgram', 'compileShader', 'found', 'fragment_shader', 'geometry_shader4', 'get_program_binary', 'glAttachShader', 'glBindAttribLocation', 'glCompileShader', 'glCreateProgram', 'glCreateShader', 

Solution

  • Sorry for getting back to you so late. Here is a demo that renders a triangle with opengl using the wxpython toolkit (which I have never tried before). In addition to what I noticed in the comments, I saw that you are not using the entire contents of your vbo array and that some of the things in your code such as "self.haveInited" were not necessary. Here is a sample that renders a vbo triangle using OpenGL 2.1.

    import wx
    from wx import glcanvas
    import sys
    from OpenGL.GL import *
    from OpenGL.arrays import vbo
    from OpenGL.GL import shaders
    import numpy as np
    
    class MyCanvas(glcanvas.GLCanvas):
        def __init__(self, parent):
            glcanvas.GLCanvas.__init__(self, parent, -1)
            self.context = glcanvas.GLContext(self)
            self.Bind(wx.EVT_PAINT, self.OnPaint)
    
        def OnPaint(self, event):
            dc = wx.PaintDC(self)
            self.SetCurrent(self.context)
            self.InitGL()
            self.OnDraw()
    
        def InitGL(self):
            glClearColor(0, 0, 0, 1)
            VERTEX_SHADER = shaders.compileShader("""
            #version 120
            void main() 
            {
                gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
            }
            """, GL_VERTEX_SHADER)
            FRAGMENT_SHADER = shaders.compileShader("""
            #version 120
            void main() 
            {
                gl_FragColor = vec4(0, 1, 0, 1);
            }
            """, GL_FRAGMENT_SHADER)
            self.shader = shaders.compileProgram(VERTEX_SHADER,FRAGMENT_SHADER)
            self.vbo = vbo.VBO(np.array([
                [  0, 1, 0 ],
                [ -1,-1, 0 ],
                [  1,-1, 0 ],
            ],'f'))
    
    
        def OnDraw(self):
            self.OnSize()
            glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
            shaders.glUseProgram(self.shader)
            self.vbo.bind()
            glEnableClientState(GL_VERTEX_ARRAY)
            glVertexPointerf(self.vbo)
            glDrawArrays(GL_TRIANGLES, 0, 9)
            self.vbo.unbind()
            glDisableClientState(GL_VERTEX_ARRAY)
            shaders.glUseProgram(0)
            self.SwapBuffers()
    
        def OnSize(self):
            size = self.size = self.GetClientSize()
            glViewport(0, 0, size.width, size.height)
    
    class MyApp(wx.App):
        def __init__(self):
            wx.App.__init__(self)
    
        def OnInit(self):
            frame = wx.Frame(None, title="OpenGL Test", size=(400, 300))
            frame.Show(True)
            c = MyCanvas(frame)
            return True
    
    app = MyApp()
    app.MainLoop()
    

    Hope it helps!