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:
g++
This exercise will not be submitted for grading; its sole purpose is to help familiarize you with the ICL5 machines.
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:
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.)
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:
A tutorial at onesadcookie.com on
XCode/GLUT.
This originally dates from 2007, but it has been updated by the author
for XCode 3 and is reported to still work for XCode 4.
A local copy of the macateeny.blogspot.com
Tiny Mac Tutorial
on running OpenGL with XCode.
(The original blog has disappeared; I was fortunate enough to have
created this copy before the blog went away.)
This is for an older version of XCode than the one we have on the ICL5
machines.
The teapots.c source file comes from the OpenGL "redbook"
sample programs.
The link in the document goes the the opengl.org web site,
which has recently rearranged its source code repository; a local copy
can be found at
teapots.c
in my
OpenGL "redbook"
source directory.
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:
OpenGL 2.1/GLSL 1.20: usable with X11 applications
Standard fixed-function OpenGL
OpenGL 3.2/GLSL 1.50: usable with Cocoa applications
Core profile only - no compatability profile, so no fixed-function
OpenGL calls allowed
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.)
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:
As our machines have OpenGL 2.0 or later installed, you should follow the code examples that are shown in orange. The other examples show a workaround for situations where OpenGL 2.0 isn't available, so they aren't appropriate in our case. (They also show the use of GLEW and ARB extensions, which won't work unless GLEW is installed.)
If you download the source code for any of the shaders used in the tutorial (which is a good idea), keep in mind that they were designed for use with the Visual Studio compiler. That compiler is less strict about typechecking than other compilers, especially when it comes to GL types, so you may have to edit and recompile your code.
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.
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:
Start the RenderMan application, found in
/Applications/Pixar/RenderMan; you should see a window
like this one:
Double-click on the lab0files/RenderMan folder to open it.
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.
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.
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:
Start a terminal window by clicking the terminal icon,
,
in the dock, or by running /Applications/Utilities/Terminal
directly.
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:
For Csh:
setenv RMANTREE /Applications/Pixar/RenderMan.app/Versions/RenderManProServer-16.5 set path = ( $RMANTREE/bin $path )
For Bash:
RMANTREE=/Applications/Pixar/RenderMan.app/Versions/RenderManProServer-16.5 PATH=$RMANTREE/bin:$PATH export RMANTREE PATH
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.
Change directory into the lab0files/RenderMan folder on the
Desktop.
Compile the shader source files with the command shader *.sl
Render the image with the command prman rit.rib
You can then double-click on the image.tif file to view the
resulting image.