PyOpenGL_LAB: A Small Lab for OpenGL Tests Without Compilation!
1,000,000 random lines
PyOpenGL_LAB is a small application directly derived from GeeXLab. It’s a ready to use PyOpenGL platform. What does it mean? Simply that you can code OpenGL instructions and very quickly see the result without the compilation step. PyOpenGL_LAB already includes the PyOpenGL package so you don’t have to worry about it. Like GeeXLab, PyOpenGL_LAB only requires a properPython 2.6.3 installation.
Unzip PyOpenGL_LAB somewhere and launch PyOpenGL_LAB.exe. You should see something like this:
In this image you can see 10,000 lines rendered with an OpenGL display list. I found the original OpenGL code here.
PyOpenGL_LAB has 2 important files: PyOpenGL_LAB_Init.py and PyOpenGL_LAB_Rendering.py.
PyOpenGL_LAB_Init.py is the initialization file. For example, this file contains the number of lines to be drawn. You can of course add OpenGL commands into this file. PyOpenGL_LAB_Init.py is executed only once.
PyOpenGL_LAB_Rendering.py contains immediate mode commands and this script is executed every frame. Immediate mode means you talk directly with the renderer (or GPU) via two methods: OpenGL commands or HYP_Renderer library.
HYP_Renderer can be seen like a wrapper over OpenGL commands. Some functions of HYP_Renderer lib can be directly written in OpenGL like HYP_Renderer.SetPointSize() but others like HYP_Renderer.ApplyCurrentViewMatrix() are a bit more complex so they are really useful.
Here is the code of PyOpenGL_LAB_Rendering.py:
HYP_Camera.ApplyToRenderer(gMainCameraId) """ ============================ Add your rendering code below: ============================ """ glScalef(15.0, 15.0, 15.0) if useDisplayList: glCallList(listId) else: random.seed(10) glBegin(GL_LINES) i = 0. for i in range(gNumLines): i+=.1 t = random.uniform(0,3) x = math.sin(i+t*.14) y = math.sin(i*.2+t*.114) z = math.cos(i*.12+t*.114)**2 glColor3f( x,y-x,z*.1 ) glVertex3f( x,y,z ) glEnd()
HYP_Camera.ApplyToRenderer() applies camera transformation (projection and view matrices as well as viewport) to the renderer. This is cool: you’re not going to bother with camera settings if the purpose of your test is not camera management.
The rest of the code draws the random lines: either using a display list or with direct calls to glBegin(GL_LINES) and glVertex3f (very slow!).
The OpenGL rendering context and swap buffer are managed by GeeXLab engine so forget them!
Once you’ve finished your modifications, press CTRL+R in GeeXLab to reload PyOpenGL_LAB main file.
Just for fun, I did some benchmarks and here are the results:
System: Core2Duo E8400 / GeForce GTS 250 (fw191.07):
- gNumLines = 100*100 = 10,000 lines – 2580 FPS
- gNumLines = 200*200 = 40,000 lines – 1250 FPS
- gNumLines = 200*500 = 100,000 lines – 520 FPS
- gNumLines = 1000*500 = 500,000 lines – 188 FPS
- gNumLines = 1000*1000 = 1,000,000 lines – 102 FPS
And you, what are your FPS at this LineMark?
Here are some screenshots: