using Tao.OpenGl; using Tao.FreeGlut; namespace animation { public class Animation { private const int WIDTH = 320; private const int HEIGHT = 240; private System.Collections.Generic.List elements; public Animation() { elements = new System.Collections.Generic.List (); fillElements(); initGlut(); initGl(); } public void fillElements() { elements.Add(new Quad(0.0,0.0,0.0) ); } public void initGlut() { Glut.glutInit(); Glut.glutInitDisplayMode(Glut.GLUT_DOUBLE | Glut.GLUT_RGB ); Glut.glutInitWindowSize( WIDTH, HEIGHT ); Glut.glutInitWindowPosition( 100, 100 ); Glut.glutCreateWindow("animation test"); Glut.glutDisplayFunc(display); Glut.glutReshapeFunc(reshape); } public void initGl() { Gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); Gl.glShadeModel(Gl.GL_SMOOTH); reshape(WIDTH, HEIGHT); } public void reshape( int w, int h) { System.Console.WriteLine("reshaping"); Gl.glViewport(0, 0, w, h); Gl.glMatrixMode(Gl.GL_PROJECTION); Gl.glLoadIdentity(); Glu.gluPerspective(120,1,-100, 100); Gl.glMatrixMode(Gl.GL_MODELVIEW); Gl.glLoadIdentity(); } public void display() { System.Console.WriteLine("displaying"); Gl.glClear(Gl.GL_COLOR_BUFFER_BIT); Glu.gluLookAt(0.0 , 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0 ); foreach ( SceneEl el in elements ) { el.draw(); } Glut.glutSwapBuffers(); } public void Run() { Glut.glutMainLoop(); } public static void Main() { Animation anim = new Animation(); anim.Run(); } } } using Tao.OpenGl; namespace animation { public class Quad : SceneEl { double x,y,z; public Quad(double x, double y, double z) { this.x = x; this.y = y; this.z = z; } public void draw() { System.Console.WriteLine("drawing quad"); Gl.glPushMatrix(); Gl.glTranslated(x,y,z); Gl.glBegin(Gl.GL_QUADS); Gl.glColor3d( 1.0, 0.0, 0.0 ); Gl.glVertex3d(-1.0, 1.0, 0.0); Gl.glColor3d( 0.5, 0.5, 1.0 ); Gl.glVertex3d(1.0, 1.0, 0.0); Gl.glColor3d( 0.0, 1.0, 0.0 ); Gl.glVertex3d(1.0, -1.0, 0.0); Gl.glColor3d( 0.5, 0.5, 1.0 ); Gl.glVertex3d(-1.0, -1.0, 0.0); Gl.glEnd(); Gl.glPopMatrix(); } } }