Nicolas Rougier
unread,Feb 10, 2012, 10:33:02 AM2/10/12Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to glumpy-users
There is not such 2d graphs even if you can use glumpy window to draw
anything you want. In the previous glumpy version, there was a script
showing how to integrate matplotlib and glumpy and I need to put it
back into the examples. That may be the best solution in your case,
all the fancy stuff is done by matplotlib and the fast stuff is done
using glumpy.
I've looked at your code and I think your OpenGL is quite efficient.
You can speed it up a little bit by discarding depth buffer as shown
below.
Nicolas
import sys
import numpy as np
import OpenGL
OpenGL.ERROR_ON_COPY = True
import OpenGL.GL as gl
import OpenGL.GLUT as glut
frame, timebase = 0, 0
def display():
global frame, timebase
frame = frame+1
time = glut.glutGet( glut.GLUT_ELAPSED_TIME )
if (time - timebase > 1000):
fps = frame*1000.0/(time-timebase)
print fps
timebase,frame = time,0
gl.glClearColor(0,0,0,1)
gl.glEnable(gl.GL_BLEND)
gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)
gl.glClear(gl.GL_COLOR_BUFFER_BIT)
x,y,width,height = gl.glGetIntegerv(gl.GL_VIEWPORT)
# n = number of lines, p = points per line
n,p = 5000, 50
vertices = np.zeros((n,p,2),dtype=np.float32)
vertices[:,:,0] = np.random.uniform(0,width,n*p).reshape(n,p)
vertices[:,:,1] = np.random.uniform(0,height,n*p).reshape(n,p)
gl.glColor(1, 1, 1, 0.05)
gl.glEnableClientState(gl.GL_VERTEX_ARRAY)
gl.glVertexPointer(2, gl.GL_FLOAT, 0, vertices)
for i in xrange(n):
gl.glDrawArrays(gl.GL_LINE_STRIP, i*p, p)
gl.glDisableClientState(gl.GL_VERTEX_ARRAY);
glut.glutSwapBuffers()
def reshape(width,height):
gl.glViewport(0, 0, width, height)
gl.glMatrixMode(gl.GL_PROJECTION)
gl.glLoadIdentity()
gl.glOrtho(0, width, 0, height, -1, 1)
gl.glMatrixMode(gl.GL_MODELVIEW)
def keyboard( key, x, y ):
if key == '\033': sys.exit( )
if __name__ == '__main__':
glut.glutInit(sys.argv)
glut.glutInitDisplayMode(glut.GLUT_DOUBLE | glut.GLUT_RGBA)
glut.glutCreateWindow('glut-lines')
glut.glutReshapeWindow(800,800)
glut.glutDisplayFunc(display)
glut.glutReshapeFunc(reshape)
glut.glutKeyboardFunc(keyboard )
glut.glutIdleFunc(display)
glut.glutMainLoop()