Licenciatura em Engenharia Informática e de Computadores Computação Gráfica Creating OpenGL applications that use GLUT Short guide to creating OpenGL applications in Windows and Mac OSX
Contents Obtaining GLUT (not in OSX) A file structure to ease portability Source code portability between OSX and all other Synonyms Project, Target, Solution Visual Studio How to create a new Solution, then a new Project Xcode How to create a new Project, then a new Target
Getting GLUT Windows Go to Nate Robins page at user.xmission.com/~nate/glut.html Download glut-3.7.6-bin.zip Unpack the ZIP file Create a neat GLUT folder structure (see next slide) OSX Comes with the OS, no need to do anything Be aware: no freeglut please, it is not endorsed by the OpenGL ARB
GLUT (for Windows) Files in ZIP file glut.def glut.h glut32.dll glut32.lib README-win32.txt Recommended file structure glut include lib GL glut32.lib glut.def glut.h glut32.dll
Recommended File Structure (ensuring portability) glut mywork src VS solution root Xcode solution root Project 1 Project 2 Project n Advantages One single source code shared by both environments Directory structure can be stored on mounted network drivers, Dropbox, cloud, etc.
Making sure OpenGL source code is portable As simple as. #if defined( APPLE ) defined(macosx) #include <GLUT/glut.h> #else #include <GL/glut.h> #endif
Synonyms Visual Studio Solution Project Xcode Project Target
Visual Studio - creating a new Solution Open Visual Studio A new solution is automatically created when you create the first Project
Visual Studio creating a new OpenGL Project Open Visual Studio Select File > New > Project Select Visual C++ from Installed Templates Select Win32 Console Application On the bottom dialogue Enter project name Move to the root of your work (e.g., mywork) Check Create directory for solution (if first project) Enter solution name (if first project) Press OK
Visual Studio creating a new OpenGL Project Click Next when Win32 Application Wizard shows Unselect Precompiled headers Select Empty project Click Finish
Visual Studio creating a new OpenGL Project On Solution Explorer Add implementation files to Source files Right click Source files Select Add Select New Item or Existing Item (if files already exist) Follow instructions Do the same for Header files
Visual Studio creating a new OpenGL Project On Solution Explorer Right click on project name, select Properties Select C/C++ > Additional Include Directories Browse to the parent of the glut/include directory, select it, press OK Select Linker > Additional Library Directories Browse to the glut/lib directory, select it, press OK Press Apply and OK Note: use relative paths to directories to ensure you can compile and run on different computers Congratulations, you are now ready to build your application
Visual Studio & Directories Very Important Requirement Executables are written to the Debug (or Release) directory under the your solution s directory (not project s) glut32.dll must be in that directory or in the system directory Running OpenGL Applications From within VS An application runs using its project s root directory as current directory By double clicking on the executable Application runs in the Debug (or Release) directory of your solution s root directory
Xcode - creating a new Project Start Xcode Select Create a new Xcode Project Under Mac OS X on the left panel choose Other then select Empty Project on the upper right panel and press Choose.. On the New Project dialogue, fill the name of the project in Save As: and select the project s root directory A Project Window shows up
Xcode adding source/header files Right click on the project name on the Project Window For existing files Select Existing Files for existing ones, browse and select them (you can even select an whole directory) New files Select New File, then C++ or Header File and click Next Fill in the file name and select its location When creating a.cpp file remember to check/uncheck the box to automatically create a.h file
Xcode creating an Open GL target On the Project Window, right click on Targets, select Add, then New Target Select Shell Tool (Xcode 3) or Command Line Tool(Xcode 4), click Next, fill in the target s name and click Finish Close the target Info window that shows up Right click on the newly created target name Xcode 3: select Add, Existing Frameworks, then select GLUT.framework and OpenGL.framework and press Add Xcode 4: select Build Phases, choose Link Binaries with Libraries and proceed to pick the two frameworks as above. To add source / header files Select the files and drag them to the target
Xcode default run directories Run from within Xcode Target runs on project_root/build/debug (or Release) To change this: Set your target as the Active Target Select Project, then Edit Active Executable target_name Edit the Set the working directory to: section at the bottom of the window that opens to your requirements Run from Finder (double-clicking on target) User home directory Run from Terminal The terminal s current working directory
Acknowledgements Diana Gouveia Ribeiro (70096) differences from Xcode 3 to Xcode 4