Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from OpenGL.GL import *
- from OpenGL.arrays import vbo
- from OpenGL.GL import shaders
- import wx
- import wx.glcanvas
- class MyCanvas(wx.glcanvas.GLCanvas):
- def __init__(self, parent):
- wx.glcanvas.GLCanvas.__init__(self, parent)
- 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, 1, 0, 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')
- )
- wx.EVT_PAINT(self, self.OnPaint)
- self.haveInited = False
- self.context = wx.glcanvas.GLContext(self)
- def OnPaint( self, mode):
- if not self.haveInited:
- self.SetCurrent(self.context)
- glClearColor(.3, .3, .3, 0)
- self.haveInited = True
- 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 )
- class MyApp(wx.App):
- def OnInit(self):
- frame = wx.Frame(None)
- canvas = MyCanvas(frame)
- frame.Show()
- return True
- MyApp(redirect = False).MainLoop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement