OpenGL, Cg and Visual Studio 2010
The Visual Studio solution referred to in the lab specification was created for Visual Studio 2003/2005, and will likely not work correctly with Visual Studio 2010.
In order to use Visual Studio 2010, it may be easier to create a new solution from scratch. This guide is for those of you who wants to use your own computer. If you are using a school computer, it is probably easier to use the provided 2003/2005 solution with Visual Studio 2005. If you are using Visual Studio 2005, follow the guide found in the lab specification instead.
Please note that GPU programming requires a fairly new graphics card, preferably from Nvidia or AMD (formerly ATI). If your card is too old, or doesn't support GPU programming, the program won't work.
- Download and install the Nvidia Cg toolkit.
- Create a new, empty, C/C++ project in Visual Studio.
- Download the solution files as described in the lab specification. Copy the main.c, .dll and .lib files to the project directory (don't paste the files directly in Visual Studio), and add main.c to the project via Add->Existing Item.
- Right click on your project in the solution explorer, and go to Configuration Properties->VC++ Directories. For Include Directories and Library Directories, add the corresponding Cg include and lib directories. These are likely found under "C:\Program Files (x86)\NVIDIA Corporation\Cg" or "C:\Program Files \NVIDIA Corporation\Cg".
- Go to Configuration Properties->Linker->Input and add "cgGL.lib" and "cg.lib" under Additional Dependencies.
The code in main.c includes sections for loading JPEG files. Since texturing is optional for this assignment, you can go ahead and comment or remove #include "jpeg/jpeglib.h", as well as the loadJPEG method. If you really want to do the texturing assignment, you may either attempt to get JPEG to work, or use BMP/raw image files, which are fairly trivial to load. There should be plenty of examples online. I've written a very naive BMP loader, which can be found here.
The program should now compile, but it won't run properly without the shader programs. The solution files you downloaded should contain a Debug directory. In this directory you'll find two files: fragement.cg and vertex.cg. These are the fragment and vertex shader programs which main.c uses, although they don't contain much at this point. Either copy them to your own Debug directory, or create new ones, and you should be good to go.