Difference between revisions of "BasecodeCSE167F14"

From Immersive Visualization Lab Wiki
Jump to: navigation, search
(Created page with "=Base Code for Programming Projects= The purpose of this web page is to introduce OpenGL programming and set up your computer so that you can begin developing OpenGL applicat...")
 
(Setup Instructions for Mac OSX)
 
(10 intermediate revisions by one user not shown)
Line 1: Line 1:
=Base Code for Programming Projects=
+
=Starter Code for Programming Projects=
  
The purpose of this web page is to introduce OpenGL programming and set up your computer so that you can begin developing OpenGL applications.  
+
The purpose of this web page is to introduce OpenGL programming and set up your computer so that you can begin developing OpenGL applications.
 
   
 
   
In order to display an image, you must create some sort of drawing canvas.  In modern operating systems, the basic drawing canvas is a window.  With OpenGL, you create a window and then create an OpenGL drawing context associated with that window, which allows you to use your video hardware to draw 3D objects directly into that window.  Opening that window and creating the OpenGL context is cumbersome and varies from system to system.  The purpose of GLUT is to simplify and unify this initial step.
+
In order to display an image, you must create a drawing canvas, which is essentially a window.  With OpenGL, you create a window and then create an OpenGL drawing context associated with that window, which allows you to use your video hardware to draw 3D objects directly into that window.  Opening that window and creating the OpenGL context is cumbersome and varies from system to system.  The purpose of GLUT is to simplify and unify this initial step.
  
On this web page we will show you how to download and install GLUT and configure Visual Studio to use it.  After that we will compile and run a sample program to test that everything is working.  You can follow these same instructions if you would like to install GLUT on your home computer to work on the homework projects.
+
The PCs in the computer lab already have GLUT and Visual Studio installed.
  
==Compiling Instructions - Visual Studio on Windows==
+
For your personal computer we will show you how to download and install GLUT and configure Visual Studio to use it.
  
===Installing GLUT - Open'''GL''' '''U'''tility '''T'''oolkit===
+
==Starter Code on Lab Computer==
  
Make a folder called c:\glut and download the glut-3.6.7-<b>bin</b>.zip (not glut-3.6.7-<b>src</b>.zip) to that folder from [http://www.xmission.com/~nate/glut.html here]. Open c:\glut and right click on glut-3.6.7-bin.zip and select Extract Here.  Open the new folder (glut-3.6.7-bin) and verify that you see the following 5 files:
+
* Download [[Media:cube.zip|cube.zip]] onto your machine and unpack it (right-click the file in Windows Explorer and select "Extract Here").
 +
* Double click file "Cube.sln" to open it in Visual Studio.
 +
* Click the icon with the green arrow named "Local Windows Debugger". Confirm with "Yes" in the pop-up window.
 +
* With luck you will see a spinning cube.
 +
* If you see an error, your compiler probably can't find GLUT and you have to tell it where it is:
 +
* Locate the "Solution Explorer" window on the left hand side of your Visual Studio window.
 +
* Right-click "Cube" (not "Solution 'Cube'").
 +
* Select "Properties". This should bring up the "Cube Property Pages" window.
 +
* Left-click "C/C++".
 +
* At "Additional Include Directories" add the directory GLUT is installed in (you will need to find out where this is on your disk by searching for "glut")
 +
* Left-click "Linker".
 +
* At "Additional Library Directories" add the same directory as above.
 +
* Click "OK".
  
* glut.def
+
==Starter Code on Personal Computer or lab computer without pre-installed GLUT==
* glut.h
+
* glut32.dll
+
* glut32.lib
+
* README-win32.txt
+
  
glut32.dll is the compiled code which handles all of the GLUT functions.
+
===Install GLUT===
  
glut.h is the header file which lists all of the GLUT functions. This must be included in any source code that uses GLUT (possibly several files in a multi-file program).
+
* Make a folder called c:\glut and download glut-3.7.6-bin.zip (not glut-3.7.6-src.zip) to that folder from http://www.xmission.com/~nate/glut.html.
 +
* Open c:\glut and right click on glut-3.7.6-bin.zip and select Extract Here.
 +
* Open the new folder (glut-3.7.6-bin) and verify that you see the following five files: glut.def, glut.h, glut32.dll, glut32.lib, README-win32.txt
 +
* Move glut32.dll to c:\Windows\System32 so that all programs can access it. If you don't have write privileges for this directory, you can put the .dll file into the directory your executable (.exe) resides in. This is typically your Debug or Release directory, just below your project directory.
 +
* Create a new directory under c:\glut\glut-3.7.6-bin and name it "GL". Move glut.h to this new directory (should be "c:\glut\glut-3.7.6-bin\GL").
  
glut32.lib is a library file which must be linked with your program so that it knows how to use glut32.dll.
+
===Install the Project===
  
Go back to c:\glut and make these 2 folders: c:\glut\include\GL and c:\glut\lib. Copy glut.h into c:\glut\include\GL and copy glut32.lib into c:\glut\lib.
+
* Download cube.zip onto your machine and unpack it (right-click the file in Windows Explorer and select "Extract Here").
 +
* Double click file "Cube.sln" to open Visual Studio.
  
Normally we would put glut32.dll in c:\windows\system32 (or c:\winnt\system32) so that all programs would have access to it.  However, we do not have access to do this in the lab, so I will show you a work around after we build our first program.
+
===Configure Microsoft Visual Studio===
  
===Configuring Microsoft Visual Studio===
+
* Locate the "Solution Explorer" window on the left hand side of your Visual Studio window.
 
+
* Right-click "Cube" (not "Solution 'Cube'").
In order to use glut.h and glut32.lib we must tell Visual Studio where these files reside. 
+
* Select "Properties". This should bring up the "Cube Property Pages" window.
 
+
* Left-click "C/C++".
* From the Tools menu, select Options.
+
* At "Additional Include Directories" add "C:\glut\glut-3.7.6-bin".
* In Visual Studio 6, select the "Directories" tab or in Visual Studio .NET select "Projects" and then "VC++ Directories" from the left side.
+
* Left-click "Linker".
* Select "Include Files" from the pull down menu on the right side.  Add "c:\glut\include".
+
* At "Additional Library Directories" add "C:\glut\glut-3.7.6-bin".
* Select "Library Files" from the pull down menu on the right side.  Add "c:\glut\lib".
+
* Click "OK".
* Press the OK button.  Visual Studio is now configured.
+
+
===Your first OpenGL program===
+
 
+
From Visual Studio, create a new Project.  There are several different types to choose from, but the one we want is Win32 Console Project (VS 6.0), or Win32 Project (VS .NET).  If you were going to create the window and OpenGL context yourself, you would use a normal Win32 project, but since we're using GLUT, we want the console project. Pick a convenient location for the project, and give it a name (such as Lab1), then press OK (Figure 1).<br>
+
 
+
<center>
+
[[Image:newproject.png]]<br>
+
''Figure 1 - New Project''
+
</center>
+
 
+
If you're using Visual Studio 6, select Empty Project.  If you're using Visual Studio .NET, select Application Settings on the left, then make the following settings (Figure 2):
+
 
+
* Application type: '''Console Application'''
+
* Add support for: uncheck all
+
* Additional Options: '''Empty Project'''
+
+
<center>
+
[[Image:appsettings.png]]<br>
+
''Figure 2 - Application Settings''
+
</center>
+
 
+
Once the project is created, download [[Media:cube.zip|cube.zip]] and add it to your project. It comes with a Visual C++ solution file, as well as a Windows executable to demonstrate what it should look like.  If you compile your program and get link errors, it could be because you are missing the following libraries: glut32.lib, opengl32.lib, and glu32.lib.  To add them, go to Project->Settings, and click on Linker, Input on the left hand side (VS .NET) or the link tab (VS 6.0).  Under additional dependencies (VS .NET) or Object/library modules (VS 6.0), add '''opengl32.lib glut32.lib glu32.lib''' (figure 3).  Now it should compile.
+
 
+
<center>
+
[[Image:libraries.png]]<br>
+
''Figure 3 - Additional Dependencies''
+
</center>
+
 
+
In order for your program to run, it needs access to glut32.dll.  One way to do this is to put glut32.dll in the \system or \system32 path.  In a lab environment like this one, you do not have access to these folders, so there is another method.  Go back to c:\glut and make the folder c:\glut\bin. Copy glut32.dll into c:\glut\bin.  Now minimize to your desktop.
+
 
+
* Right click on My Computer and select '''Properties'''.
+
* Click on the Advanced tab and select Environmental Variables
+
* In the top box (User variables for...) edit Path (or creat it if it does not already exist).  Add c:\glut\bin to the path.  This will now look for dll dependencies in c:\glut\bin so your program can load glut32.dll.
+
 
+
Now execute your program - you should see a red square!
+
 
+
'''Note:''' Make sure that you save your code files on the network drive, not on the local C: drive. You won't be able to access files you put on the C: drive the next time you log on to a (different) lab computer.
+
 
+
==Notes for Windows 7 Users==
+
 
+
Matteo was kind enough to share his experience building the code with Windows 7:
+
 
+
1. Instead doing everything in of Step 2 above, you have to do this:
+
 
+
* Create your project first. (do step 3)
+
* Open the solution
+
* Select "View", the "Property Manager".
+
* In the Property Manager (left), right-click the project and select "Add New Property Sheet".  You have to give it a name - I called it "glut", but that may not be good practice.  Click "Add".
+
* Now right click on the property sheet generated for the project and select "Properties"
+
* Finally, under Configuration Properties, you can get access to "VC++ Directories", just like old times, and complete the steps in Step 2.
+
 
+
2. glut32.dll needs to be in C:\Windows\SysWOW64 instead of C:\Windows\System32.
+
  
 
==Alternative Way of Installing GLUT==
 
==Alternative Way of Installing GLUT==
Line 100: Line 60:
 
* Copy glut32.lib to C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\lib
 
* Copy glut32.lib to C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\lib
 
* Copy glut.h to C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\GL (create a folder called GL first in ...\include before copying glut.h)
 
* Copy glut.h to C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\GL (create a folder called GL first in ...\include before copying glut.h)
 
==Compiling Instructions - Linux (Lab) / MacOSX==
 
 
If GLUT is already installed on the Linux lab machines no configuring is required. Otherwise it has to be installed in the user's home directory and library and include directories have to be passed to the compiler.
 
 
===Building the Example===
 
 
Download [[Media:cube.zip|cube.zip]] onto your machine. Unpack it with "unzip cube.zip". Then change into the "cube" directory with "cd cube". Then build the executable with "make". The compiler will generate an executable named "cubee" in the same directory. The makefile lists the .cpp files to include in the build, so if you add more .cpp files later, you will have to add them to the makefile.
 
 
Type ./cube to execute the program. You should see a green, spinning cube!
 
  
 
==Setup Instructions for Mac OSX==
 
==Setup Instructions for Mac OSX==
  
Aaron Schwartz compiled [[Media:Glut4OSX.pdf | instructions on how to set up OpenGL on a Mac]].
+
Aaron Schwartz compiled [[Media:Glut4OSX.pdf | instructions on how to set up OpenGL on a Mac]]. Tyler Levine [[Media:makefile-osx.txt | updated it for a newer OSX]].
  
 
Janelle Shane shares her [http://photonherder.blogspot.com/2011/09/tutorial-simple-opengl-program-in-xcode.html notes on the setup in XCode].
 
Janelle Shane shares her [http://photonherder.blogspot.com/2011/09/tutorial-simple-opengl-program-in-xcode.html notes on the setup in XCode].

Latest revision as of 12:23, 9 October 2014

Contents

Starter Code for Programming Projects

The purpose of this web page is to introduce OpenGL programming and set up your computer so that you can begin developing OpenGL applications.

In order to display an image, you must create a drawing canvas, which is essentially a window. With OpenGL, you create a window and then create an OpenGL drawing context associated with that window, which allows you to use your video hardware to draw 3D objects directly into that window. Opening that window and creating the OpenGL context is cumbersome and varies from system to system. The purpose of GLUT is to simplify and unify this initial step.

The PCs in the computer lab already have GLUT and Visual Studio installed.

For your personal computer we will show you how to download and install GLUT and configure Visual Studio to use it.

Starter Code on Lab Computer

  • Download cube.zip onto your machine and unpack it (right-click the file in Windows Explorer and select "Extract Here").
  • Double click file "Cube.sln" to open it in Visual Studio.
  • Click the icon with the green arrow named "Local Windows Debugger". Confirm with "Yes" in the pop-up window.
  • With luck you will see a spinning cube.
  • If you see an error, your compiler probably can't find GLUT and you have to tell it where it is:
  • Locate the "Solution Explorer" window on the left hand side of your Visual Studio window.
  • Right-click "Cube" (not "Solution 'Cube'").
  • Select "Properties". This should bring up the "Cube Property Pages" window.
  • Left-click "C/C++".
  • At "Additional Include Directories" add the directory GLUT is installed in (you will need to find out where this is on your disk by searching for "glut")
  • Left-click "Linker".
  • At "Additional Library Directories" add the same directory as above.
  • Click "OK".

Starter Code on Personal Computer or lab computer without pre-installed GLUT

Install GLUT

  • Make a folder called c:\glut and download glut-3.7.6-bin.zip (not glut-3.7.6-src.zip) to that folder from http://www.xmission.com/~nate/glut.html.
  • Open c:\glut and right click on glut-3.7.6-bin.zip and select Extract Here.
  • Open the new folder (glut-3.7.6-bin) and verify that you see the following five files: glut.def, glut.h, glut32.dll, glut32.lib, README-win32.txt
  • Move glut32.dll to c:\Windows\System32 so that all programs can access it. If you don't have write privileges for this directory, you can put the .dll file into the directory your executable (.exe) resides in. This is typically your Debug or Release directory, just below your project directory.
  • Create a new directory under c:\glut\glut-3.7.6-bin and name it "GL". Move glut.h to this new directory (should be "c:\glut\glut-3.7.6-bin\GL").

Install the Project

  • Download cube.zip onto your machine and unpack it (right-click the file in Windows Explorer and select "Extract Here").
  • Double click file "Cube.sln" to open Visual Studio.

Configure Microsoft Visual Studio

  • Locate the "Solution Explorer" window on the left hand side of your Visual Studio window.
  • Right-click "Cube" (not "Solution 'Cube'").
  • Select "Properties". This should bring up the "Cube Property Pages" window.
  • Left-click "C/C++".
  • At "Additional Include Directories" add "C:\glut\glut-3.7.6-bin".
  • Left-click "Linker".
  • At "Additional Library Directories" add "C:\glut\glut-3.7.6-bin".
  • Click "OK".

Alternative Way of Installing GLUT

Krishna is sharing this tip:

If you are installing GLUT on a computer you have administrator privileges, you can put the GLUT files with the other system libraries. Then you don't have to point the compiler to them. This works similarly in all Windows versions, including Windows 8.

  • Copy glut32.dll to C:\System
  • Copy glut32.lib to C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\lib
  • Copy glut.h to C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\GL (create a folder called GL first in ...\include before copying glut.h)

Setup Instructions for Mac OSX

Aaron Schwartz compiled instructions on how to set up OpenGL on a Mac. Tyler Levine updated it for a newer OSX.

Janelle Shane shares her notes on the setup in XCode.