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.
We'll start by opening MS Visual Studio C# Express Version and creating a new Windows Application project:
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:
Select the Start Without Debugging menu item under the Debug menu again and test that your application now shows up.
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.
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.
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.
|
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