2016-09-14 103 views
0

這是我的源代碼https://paste.fedoraproject.org/428184/89404314/pyOpenGL檢查布爾

我得到的錯誤是這樣的:

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 

目錄(着色器)都配備有該功能:

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

還沒有看太深的代碼,但你似乎調用shaders.CompileShader而不是shaders.compileShader。此外,它看起來像你寫的着色器實際上是版本120着色器,所以請嘗試切換着色器版本。就我所知,像gl_ModelViewProjectionMatrix這樣的變量在現代OpenGL版本中不再存在了! – CodeSurgeon

+0

PyPI和binary出現了一些問題我得到了另一個錯誤:嘗試調用未定義的函數glutInit,在調用 –

回答

1

對不起,讓回到你這麼晚。這是一個使用wxpython工具包(我從未嘗試過)使用opengl渲染三角形的演示。除了我在註釋中注意到的內容之外,我看到您沒有使用vbo數組的全部內容,並且代碼中的某些內容(如「self.haveInited」)不是必需的。這是一個使用OpenGL 2.1呈現vbo三角形的示例。

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() 

希望它有幫助!

+0

前檢查bool(glutInit)是的,你的代碼運行良好並且幫助我。我的代碼是舊的,我不知道在源代碼中使用的python模塊的發展情況下所做的所有更改。隨意添加任何信息。謝謝。 –