-
Notifications
You must be signed in to change notification settings - Fork 7
/
gl_example.py
45 lines (37 loc) · 1.14 KB
/
gl_example.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# pip install PyOpenGL OpenGLContext PyVRML97 pydispatcher PIL
from pymol import cmd
from pymol.callback import Callback
import time
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
import numpy as np
def random_walk(N):
x = np.random.randn(N + 1, 3).astype('f').cumsum(axis=0)
x -= x.mean(axis=0)
return 0.5 * x / x.std()
class myCallback(Callback):
"""Creates a simple vertex shader..."""
def __init__(self):
self.rebuild(1 * 1000 * 1000)
def rebuild(self, nlines):
self.nlines = nlines
mygeom = random_walk(nlines) * 10.0
self.vbo = vbo.VBO(mygeom)
def __call__(self):
try:
self.vbo.bind()
try:
glEnableClientState(GL_VERTEX_ARRAY)
glVertexPointerf(self.vbo)
glDrawArrays(GL_LINE_STRIP, 0, self.nlines + 1)
finally:
self.vbo.unbind()
glDisableClientState(GL_VERTEX_ARRAY)
finally:
pass
walker = myCallback()
cmd.load_callback(walker, 'gl01')