Code Yarns ‍👨‍💻
Tech BlogPersonal Blog

How to get started with Tao Framework using C#

📅 2013-Jun-18 ⬩ ✍️ Ashwin Nanjappa ⬩ 📚 Archive

The Tao Framework is a .Net wrapper library for the OpenGL, GLU, FreeGLUT and Cg libraries. It is now deprecated and its functionality has been superseded by the OpenTK project. However, it is perfect for writing simple OpenGL or GLUT programs in .Net languages like C#.

Getting started on the Tao Framework using C# is easy:

  1. Download and install the last version of Tao Framework from here. The installer will add its .Net assemblies to the GAC.

  2. Create an empty C# console application project in Visual Studio.

  3. Add references to Tao.OpenGL.dll and Tao.FreeGLUT.dll to the project. These files can be found in **C:Files (x86)*

  4. Paste the source code given below into the C# source file.

  5. Copy FreeGLUT.dll from **C:Files (x86)* to directory of the generated EXE file.

  6. Run the program. You should see a grey teapot!

  7. Whether you are porting an existing C or C++ OpenGL application or writing your own, it should be easy to build upon this program.

// C# program that uses Tao framework to call
// OpenGL, GLU and FreeGLUT functions.
//
// Steps:
// 1. Install Tao framework. Its .Net assemblies will be added to GAC.
// 2. Create an empty C# console application project in Visual Studio
// 3. Add references to Tao.OpenGL.dll and Tao.FreeGLUT.dll to the project.
//    These files are in C:\Program Files (x86)\TaoFramework\bin
// 4. Paste this source code into the C# source file
// 5. Copy FreeGLUT.dll from C:\Program Files (x86)\TaoFramework\lib to
//    directory of the generated EXE file
// 6. Run. You should see a grey teapot.
//
// Copyright (c) 2013 Ashwin Nanjappa
// Released under the MIT License

using System;
using Tao.OpenGl;
using Tao.FreeGlut;

namespace TaoExample
{
    class Program
    {
        static void init_graphics()
        {
            Gl.glEnable(Gl.GL_LIGHTING);
            Gl.glEnable(Gl.GL_LIGHT0);
            float[] light_pos = new float[3] {1, 0.5F, 1};
            Gl.glLightfv(Gl.GL_LIGHT0, Gl.GL_POSITION, light_pos);
            Gl.glEnable(Gl.GL_DEPTH_TEST);
            Gl.glClearColor(1, 1, 1, 1);
        }

        static void on_display()
        {
            Gl.glClear(Gl.GL_COLOR_BUFFER_BIT | Gl.GL_DEPTH_BUFFER_BIT);
            Gl.glLoadIdentity();
            Glu.gluLookAt(0, 0, 5, 0, 0, 1, 0, 1, 0);
            Glut.glutSolidTeapot(1);
            Glut.glutSwapBuffers();
        }

        static void on_reshape(int w, int h)
        {
            Gl.glMatrixMode(Gl.GL_PROJECTION);
            Gl.glLoadIdentity();
            Gl.glViewport(0, 0, w, h);
            Glu.gluPerspective(40, w / h, 1, 100);
            Gl.glMatrixMode(Gl.GL_MODELVIEW);
        }

        static void Main()
        {
            Glut.glutInit();
            Glut.glutInitWindowSize(500, 500);
            Glut.glutCreateWindow("Tao Example");
            init_graphics();
            Glut.glutDisplayFunc(on_display);
            Glut.glutReshapeFunc(on_reshape);
            Glut.glutMainLoop();
        }
    }
}

Tried with: Tao Framework 2.1.0, Visual Studio 2012 and Windows 7 x64