[PyOpenGL-Users] Fastest way to draw lots of points
Brought to you by:
mcfletch
|
From: Ryan H. <rm...@gm...> - 2012-10-19 16:52:12
|
I am working on a pygame app that I recently converted to using opegl
for the backend. The game has a parallax star field in the background
so I have been looking for the most efficient way of drawing multiple
points. My game updates the display every 33ms. Bellow are the draw
points methods I have tried.
def point(point, color, size=1.0, alpha=255.0):
glPointSize(size)
glDisable(GL_TEXTURE_2D)
glBegin(GL_POINTS)
glColor4f(color[0] / 255.0, color[1] / 255.0, color[2] / 255.0,
alpha / 255.0)
glVertex3f(point[0], point[1], 0)
glEnd()
glEnable(GL_TEXTURE_2D)
def points(points, indices, color, size=1.0, alpha=255.0):
glPointSize(size)
glDisable(GL_TEXTURE_2D)
glColor4f(color[0] / 255.0, color[1] / 255.0, color[2] / 255.0,
alpha / 255.0)
glEnableClientState(GL_VERTEX_ARRAY)
glVertexPointer(2, GL_FLOAT, 0, points)
glDrawElementsui(GL_POINTS, indices)
glDisableClientState(GL_VERTEX_ARRAY)
glEnable(GL_TEXTURE_2D)
def points2(points, color, size=1.0, alpha=255.0):
glPointSize(size)
glDisable(GL_TEXTURE_2D)
glBegin(GL_POINTS)
glColor4f(color[0] / 255.0, color[1] / 255.0, color[2] / 255.0,
alpha / 255.0)
for p in points:
glVertex2f(p[0], p[1])
glEnd()
glEnable(GL_TEXTURE_2D)
I've tested these with different size arrays of points, a small array
of 250 and a large array of 2000.
The first of the 3 methods I would obviously call N times in a loop.
For the small array this is not an issue but for the larger array the
overhead of glBegin starts to take over.
The second method is better than the first but there are some weird
numpy array operations that occur and add overhead with some weird
interactions. If points is a regular python list there seems to be a
linear increase in time with more points. If I points is a numpy array
of dtype="f" it starts faster but seems to increase non-linearly. The
fastest solution is the third function regardless of the size of the
array. Does anyone have any thoughts on this or ideas of how I can
improve any of these methods?
--
Ryan Hope, M.S.
CogWorks Lab
Cognitive Science Department
Rensselaer Polytechnic Institute
|