In-Class Exercise

Assigned: 03/11

Due: never


Introduction

This in-class exercise is intended to help you become familiar with the iMac systems in ICL5 and with using GLSL and RenderMan® on those systems. The following tasks should help you accomplish this:

  1. Learn to use OpenGL and GLUT on the iMac using XCode and/or g++
  2. Learn to use GLSL on the Mac
  3. Learn to use RenderMan on the Mac

This exercise will not be submitted for grading; its sole purpose is to help familiarize you with the ICL5 machines.

Tasks

Task 0: Retrieving Files

Studies have shown that success in one task tends to increase the chances of success in subsequent tasks, so the goal of Task 0 is to start you out with something easy.

For the subsequent tasks, you will need the files found in lab0files.zip. Download that file and expand it to your desktop; you should now have a folder named lab0files. This folder contains subfolders named GLSL and RenderMan; each of them contains the basic set of source files for this assignment:

lab0 source folder hierarchy image

For all the rest of the programming assignments this quarter, you'll download a similar archive containing "starting point" files for both GLSL and RenderMan tasks. (You'll also download a "results" folder hierarchy this way, but there isn't one of those for Lab 0 because you're not turning anything in.)

Task 1: Using XCode and/or g++

The goal of this task is to learn how to use XCode and/or g++ to manage OpenGL projects on the Mac.

There are several tutorials available online which cover the use of OpenGL and XCode. Here are two of them:

An alternative to XCode is to use "old-school" methods - that is, command-line compilation and linking. You can compile and link OpenGL/GLSL programs from the command line by giving the proper options to gcc or g++. To compile and link using the proper libraries, tell the compiler which compilation frameworks you want it to use; for instance, here are typical compile commands for C and C++ programs:

gcc -o prog1 -framework OpenGL -framework GLUT prog1.c
g++ -o prog2 -framework OpenGL -framework GLUT prog2.cpp

If there are additional source files, simply list them at the end of the command:

gcc -o prog1 -framework OpenGL -framework GLUT prog1.c support1.c
g++ -o prog2 -framework OpenGL -framework GLUT prog2.cpp support2.cpp

If needed, you can also add the Cocoa framework to this command with -framework Cocoa.

Important note: The ICL5 machines are running Mountain Lion. Apple tightened the security framework in Snow Leopard (two OS revisions ago), and one effect of this is that "debugging" is considered to be a privileged operation - accounts must be members of a "developer tools" group to use debugging tools. Your account will be added to this group to allow you to use the debugging tools; until that happens, the "Build and Run" functionality of XCode and the command-line gdb program will not work on these machines. The XCode "Build" functionality will work, but you may have to run the binary manually.

Compounding things is the fact that two OpenGL/GLSL versions are installed on these systems:

Our initial assignments will work correctly under any OpenGL version that supports at least GLSL version 1.20; later assignments may require a newer implementation. (The "old-school" example commands create programs that run under X11, so they are limited to OpenGL 2.1 and GLSL 1.20.)

Task 2: Using GLSL

The goal of this task is to learn how to use GLSL within an OpenGL program on ICL5 machines.

You may want to read through the Lighthouse3d tutorial on running GLSL and OpenGL. Things to note about this tutorial:

The lab0files/GLSL folder contains a basic Phong shader (implemented in the vertex shader) and two driver programs; driver1 draws three spheres, and driver2 draws a cube. Using either XCode or g++, compile and test these programs.

Task 3: Using RenderMan

The goal of this task is to learn how to use RenderMan on the ICL5 machines.

The files you will need for this task are in the lab0files/RenderMan folder you unpacked earlier. This folder contains all the files for the simple shading exercise used in the CG2 RenderMan assignment.

RenderMan comes with a GUI for running it on the Mac; however, you can also use it in command-line mode. To use the GUI form, follow these steps:

  1. Start the RenderMan application, found in /Applications/Pixar/RenderMan; you should see a window like this one:

    RenderMan GUI prman window
  2. Double-click on the lab0files/RenderMan folder to open it.

  3. Click on the shader tab in the RenderMan GUI; you should see a subwindow named "Recent Files". Compile each shader source file (brick.sl, plastic.sl, and wood2.sl) by dragging it from the RenderMan folder into the "Recent Files" subwindow.

  4. Click the prman tab to return to that part of the GUI. Drag the rit.rib file from the RenderMan folder to the "Rendering Queue" subwindow to render the image.

  5. You should see a file named image.tif appear in the RenderMan folder; double-click it to open it using the Preview application, and you should see the rendered image.

If you prefer to use the command-line interface, follow these instructions:

  1. Start a terminal window by clicking the terminal icon, terminal application icon, in the dock, or by running /Applications/Utilities/Terminal directly.

  2. If the command 'which prman' prints "Command not found", you will need to tell your shell where to find the RenderMan command binaries. These are found buried deep inside the RenderMan installation folder, which is an application package.

    The application package for RenderMan is /Applications/Pixar/RenderMan. You can see its contents by doing a right-click (or control-click) on it and selecting the "Show Package Contents" menu entry. Under the "Versions" folder is the installation folder for the RenderMan application, and under that is a bin directory containing the command-line RenderMan programs.

    The name of hte installation folder varies from one version of RenderMan to another. Assuming the installation folder is RenderManProServer-16.5, add its bin directory to your search path this way:

    You may want to add these lines to your .cshrc file (for Csh users) or .bashrc file (for Bash users) so that you don't have to re-execute them in every terminal window.

  3. Change directory into the lab0files/RenderMan folder on the Desktop.

  4. Compile the shader source files with the command shader *.sl

  5. Render the image with the command prman rit.rib

  6. You can then double-click on the image.tif file to view the resulting image.


RenderMan is a registered trademark of Pixar.