Installing and working with Tao

Setting up your development system

This is all done for you on the Caldwell graphics lab (CL 112D) machines. First, make sure you have MS Visual Studio installed. OpenGL is a C-language API written in un-safe unmanged code. In order to use it with C#, we need to wrap the OpenGL dll with a managed C# interface. The Tao Framework has done this for us already. Although it would be great to have a teaching-based binding that only exposed a minimal set of functionality (and #defines). Download and install the Tao Framework Setup file (Tao-2.0.0-setup.exe). This file installs the libraries (in C:\Program Files\Tao) and registers them with the Global Assembly Cache. Again, this is done for you on the lab machines. Once this is done, download and install the latest beta files for OpenGL (Tao.OpenGl-2.1.0.11.zip), by copying the Release version files into Tao's bin directory on your machine. It is important to have the same version on all machines, as well as compared to what the grader has, as versioning is important with .NET.

Create a new Solution and Project.

We'll start by opening MS Visual Studio C# Express Version and creating a new Windows Application project:

Microsoft Visual Studio New Project Dialog

Visual Studio will automatically create several files for you, including a completely functional program. Select the Build Solution under the Build menu. The status bar on the bottom will indicate that the program (solution) built successfully. Now, select the Start Without Debugging menu item under the Debug menu. Depending on your environment, you will either see a small window titled Form1 or a dialog window reporting a security exception as indicated below.

need image for here

Close the application of exception dialog. The exception occurs because .NET will not allow you to run an application from an un-trusted location, such as a CD-ROM, USB disk or in this case a mounted or shared filesystem. The Caldwell machines do not have a local file space for you. You manage and use the UNIX filesystem mounted on these machines. This ensures that you see the same environment on all machines. To run the application, you need to copy the executable (in bin/Debug) over to the local machine's file space. This will be annoying every time you build the application. Under the Project menu, select the Properties menu item (last item on the menu). Click on the Build tab and change the Output Dir to C:\temp as shown below:

Properties dialog showing how to set the Output path

Select the Start Without Debugging menu item under the Debug menu again and test that your application now shows up.

Source Files

Source files were created for Form1.cs, Form1.designer.cs, Program.cs. These are the main files you will edit to create your program (and reference other classes in additional files you create). Primarily you will always be concerned with editing Form1.cs. Visual Studio will edit Form1.designer.cs as you make changes in the Form designer. Let's look at few of the other files quickly before we get to the meat of the tuorial. No changes are required to these for this application. The Program.cs file contains the Main routine (actually a static method of a class called Program). It's primary function is to create a new Form1 and pass control to over to it. It does this with the statement:

Application.Run(new Form1());

Expand the Properties Node to expose the files controlling some of the meta-data associated with this program. Open the file AssemblyInfo.cs as shown below. Add a description and modify the Title, Company and other fields to suite your liking. Again, this information has no bearing on the running of this program, but I am showing it for completeness. You will see this information if look at the Properties of the resulting executable file.

Providing compoany information

Tao bindings and the SimpleOpenGLControl class

Compared to C++, C# uses references for both include files and library files. The .NET Framework provides complete type information within its files (dll's and exe's), allowing the compiler to acquire information about any types exported by these files. To use the Tao Framework, we need to reference Tao.OpenGl and Tao.Platform.Windows. We can either go to Project/Add Reference or right click on References in the Solution Explorer and choose Add Reference. On the Add Reference dialog navigate to where we have Tao.OpenGl.dll and Tao.Platform.Windows.dll. Select both of these and click OK. These will be added to your list of References.

Adding References with Visual Studio


We can now use Tao.OpenGl and Tao.Platform.Windows in our program. Right-click on the Form1.cs file in the Solutions Explorer on the Designer page for Form1.cs and select View Code. Add "using Tao.OpenGl;" and "using Tao.Platform.Windows;" statements to import the namespaces in the Form1.cs file. You should have witnessed Intellisense support for these namespaces as well. Try building and running the program to ensure that it works.

Before we can draw anything with OpenGL we need what is called a graphics context. For this tutorial we will use a little helper class in the Tao.Platform.Windows namespace called the SimpleOpenGLControl. SimpleOpenGlControl is just that, a simple Windows Forms-based OpenGL control. Control is the name assigned in .NET (and other toolkits) for any GUI component. In this case, SimpleOpenGlControl is derived from a UserControl. Its purpose is to get your OpenGL application quickly running with Windows Forms. It abstracts some of the complexities involved with setting up an OpenGL context on Windows. Think of it as a special case of the Panel control in .NET. It can be used anywhere a Panel can. Later, we will examine how to build your own OpenGL control in case you need to expose more functionality or need to override some of SimpleOpenGlControl's behavior. Before we use the SimpleOpenGlControl, let's add it to our Toolbox, so we can use it in the Designer like any other control. Open up Form1.cs in the Designer to bring-up the Toolbox window. On the Toolbox window of Visual Studio, right click the Containers tab and select Chose Items ...From the pop-up dialog, scroll down to the SimpleOpenGlControl and check the checkbox to add it to the toolbox.I also added a new tab to the toolbox called OpenGL. These tabs are just different views into the massive set of controls and components. I dragged the SimpleOpenGlControl to the OpenGL tab holding down the Alt key to copy it. Alas, any new projects and even closing this one and reopening will lose the new Tab. The SimpleOpenGlControl will appear at the bottom of the All Windows Forms :-(.
Adding a control to the toolbox
  Toolbox Tabs

We know have Tao installed and are ready to write our first program using the Tao bindings for C#. A sample tutorial is provided that will draw a very simple triangle.


Last modified: September 20, 2007 2:42 PM