[IronPython] OpenGL with IronPython
Sylvain Hellegouarch
sh at defuze.org
Fri Feb 15 21:37:51 CET 2008
Hi there,
You might want to use Tao [1].
The example below works fine with the latest stable release of Tao
(2.0.0) and Mono 1.2.6
Note that I'm using Glfw [2] here but you could use FreeGlut instead of
course.
That example simply renders a spinning triangle onto a window.
- Sylvain
[1] http://taoframework.com/
[2] http://glfw.sourceforge.net/
import clr
clr.AddReference('Tao.Glfw')
clr.AddReference('Tao.OpenGl')
from Tao.Glfw import Glfw
from Tao.OpenGl import Gl, Glu
def run():
Glfw.glfwInit()
if not Glfw.glfwOpenWindow(640, 480, 0, 0, 0, 0, 0, 0,
Glfw.GLFW_WINDOW):
Glfw.glfwTerminate()
return 2
Glfw.glfwEnable(Glfw.GLFW_STICKY_KEYS)
Glfw.glfwSwapInterval(0)
running = True
frame_count = 0
start_time = Glfw.glfwGetTime()
while running:
current_time = Glfw.glfwGetTime()
coordinates = Glfw.glfwGetMousePos()
#Calculate and display FPS (frames per second)
if (current_time - start_time) > 1 or frame_count == 0:
frame_rate = frame_count / (current_time - start_time);
Glfw.glfwSetWindowTitle("Spinning Triangle (%d FPS)" %
frame_rate)
start_time = current_time
frame_count = 0
frame_count = frame_count + 1
window_dim = Glfw.glfwGetWindowSize()
if window_dim[1] > 0:
height = window_dim[1]
else:
height = 1
# Set viewport
Gl.glViewport(0, 0, window_dim[0], height)
# Clear color buffer
Gl.glClearColor(0, 0, 0, 0)
Gl.glClear(Gl.GL_COLOR_BUFFER_BIT)
# Select and setup the projection matrix
Gl.glMatrixMode(Gl.GL_PROJECTION)
Gl.glLoadIdentity()
Glu.gluPerspective(65, window_dim[0]/height, 1, 100)
# Select and setup the modelview matrix
Gl.glMatrixMode(Gl.GL_MODELVIEW)
Gl.glLoadIdentity()
Glu.gluLookAt(0, 1, 0, 0, 20, 0, 0, 0, 1)
# Draw a rotating colorful triangle
Gl.glTranslatef(0, 14, 0)
Gl.glRotatef(1/3 * float(coordinates[0]) + float(current_time) *
100,
0, 0, 1)
Gl.glBegin(Gl.GL_TRIANGLES)
Gl.glColor3f(1, 0, 0)
Gl.glVertex3f(-5, 0, -4)
Gl.glColor3f(0, 1, 0)
Gl.glVertex3f(5, 0, -4)
Gl.glColor3f(0, 0, 1)
Gl.glVertex3f(0, 0, 6)
Gl.glEnd();
Glfw.glfwSwapBuffers()
running = ((Glfw.glfwGetKey(Glfw.GLFW_KEY_ESC) ==
Glfw.GLFW_RELEASE) and
Glfw.glfwGetWindowParam(Glfw.GLFW_OPENED) == Gl.GL_TRUE)
Glfw.glfwTerminate()
if __name__ == '__main__':
run()
jane janet a écrit :
>
> Hi all,
>
> I need help again.
> I don't know how to use OpenGL in IronPython.
> I want to draw the line in IronPython application.
> Please teach me clearly.
>
> All the best,
> Jane
>
> *Jane*
>
>
> ------------------------------------------------------------------------
> Connect and share in new ways with Windows Live. Get it now!
> <http://www.windowslive.com/share.html?ocid=TXT_TAGHM_Wave2_sharelife_012008>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Users mailing list
> Users at lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>
More information about the Ironpython-users
mailing list