问题
This is an example from: http://pyopengl.sourceforge.net/context/tutorials/shader_1.xhtml
It is creating a vbo, binging it, and running it with a shader, but somewhere along the way, something is not working properly. :\
from OpenGLContext import testingcontext
BaseContext = testingcontext.getInteractive()
from OpenGL.GL import *
from OpenGL.arrays import vbo
from OpenGLContext.arrays import *
from OpenGL.GL import shaders
class TestContext( BaseContext ):
def OnInit( self ):
VERTEX_SHADER = shaders.compileShader("""#version 330
void main() {
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
}""", GL_VERTEX_SHADER)
FRAGMENT_SHADER = shaders.compileShader("""#version 330
void main() {
gl_FragColor = vec4( 0, 3, 6, 1 );
}""", GL_FRAGMENT_SHADER)
self.shader = shaders.compileProgram(VERTEX_SHADER,FRAGMENT_SHADER)
self.vbo = vbo.VBO(
array( [
[ 0, 1, 0 ],
[ -1,-1, 0 ],
[ 1,-1, 0 ],
[ 2,-1, 0 ],
[ 4,-1, 0 ],
[ 4, 1, 0 ],
[ 2,-1, 0 ],
[ 4, 1, 0 ],
[ 2, 1, 0 ],
],'f')
)
def Render( self, mode):
shaders.glUseProgram(self.shader)
try:
self.vbo.bind()
try:
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointerf(self.vbo)
glDrawArrays(GL_TRIANGLES, 0, 9)
finally:
self.vbo.unbind()
glDisableClientState(GL_VERTEX_ARRAY);
finally:
shaders.glUseProgram(0)
if __name__ == "__main__":
TestContext.ContextMainLoop()
Running this sample in the normal py 2.7 interactive terminal produces the following:
OpenGLContext.scenegraph.basenodes:Unable to load node implementation for
MMImageTexture: 'module' object has no attribute 'MMImageTexture'
In both cases, a window is produced, but there is no geometry displayed.
Is the basenodes issue indicating that MMImageTexture was a custom basenode and hasn't been created properly? I followed everything in the tut to the letter as far as I can tell. :\ So annoying...so annoying. Prease Helps Me's! :P
My system specs are win7, 4gb ram, corei5, 630m GeForce GT, using python 2.7 and python portable.
来源:https://stackoverflow.com/questions/16945500/why-is-this-tutorial-example-of-a-shader-not-displaying-any-geometry-as-it-is-su