In this section, we will outline the steps required to set up the same libraries in Mac OS X and Linux.
We will first need to download the prerequisite libraries from the following websites:
To simplify the installation process for Mac OS X or Ubuntu users, the use of MacPorts in Mac OS X or the apt-get
command in Linux (as described in Chapter 1, Getting Started with OpenGL) is highly recommended.
The following section assumes that the download directory is ~/opengl_dev
(refer to Chapter 1, Getting Started with OpenGL).
There are two methods to install the prerequisite libraries. The first method uses precompiled binaries. These binary files are fetched from remote repository servers and the version updates of the library are controlled externally. An important advantage of this method is that it simplifies the installation, especially in terms of resolving dependencies. However, in a release environment, it is recommended that you disable the automatic updates and thus protect the binary from version skewing. The second method requires users to download and compile the source code directly with various customizations. This method is recommended for users who would like to control the installation process (such as the paths), and it also provides more flexibility in terms of tracking and fixing bugs.
For beginners or developers who are looking for rapid prototyping, we recommend that you use the first method as it will simplify the workflow and have short-term maintenance. On an Ubuntu or Debian system, we can install the various libraries using the apt-get
command. To install all the prerequisite libraries and dependencies on Ubuntu, simply run the following commands in the terminal:
sudo apt-get install libglm-dev libglew1.6-dev libsoil-dev libopencv
Similarly, on Mac OS X, we can install GLEW, OpenCV, and GLM with MacPorts through command lines in the terminal:
sudo port install opencv glm glew
However, the SOIL library is not currently supported by MacPorts, and thus, the installation has to be completed manually, as described in the following section.
For advanced users, we can install the latest packages by directly compiling from the source, and the upcoming steps are common among Mac OS as well as other Linux OS.
To compile the GLEW package, follow these steps:
glew-1.10.0.tgz
package:tar xzvf glew-1.10.0.tgz
/usr/include/GL
and /usr/lib
:cd glew-1.10.0 make && sudo make install
To set up the header-only GLM library, follow these steps:
glm-0.9.5.4.zip
package:unzip glm-0.9.5.4.zip
~/opengl_dev/glm/glm
) to /usr/include/glm
:sudo cp -r glm/glm/ /usr/include/glm
To set up the SOIL library, follow these steps:
soil.zip
package:unzip soil.zip
makefile
(inside the projects/makefile
directory) and add -arch x86_64
and -arch i386
to CXXFLAGS
to ensure proper support:CXXFLAGS =-arch x86_64 –arch i386 -O2 -s -Wall
cd Simple OpenGL Image Library/projects/makefile mkdir obj make && sudo make install
To set up the OpenCV library, follow these steps:
opencv-2.4.9.zip
package:unzip opencv-2.4.9.zip
CMake
:cd opencv-2.4.9/ mkdir build cd build cmake ../ make && sudo make install
sudo sh -c 'echo "/usr/local/lib" > /etc/ld.so.conf.d/opencv.conf' sudo ldconfig –v
Makefile
) within each project folder:CFILES = ../common/shader.cpp ../common/texture.cpp ../common/controls.cpp main.cpp CFLAGS = -O3 -c -Wall INCLUDES = -I/usr/include -I/usr/include/SOIL -I../common `pkg-config --cflags glfw3` `pkg-config --cflags opencv` LIBS = -lm -L/usr/local/lib -lGLEW -lSOIL `pkg-config --static --libs glfw3` `pkg-config --libs opencv` CC = g++ OBJECTS=$(CFILES:.cpp=.o) EXECUTABLE=main all: $(CFILES) $(EXECUTABLE) $(EXECUTABLE): $(OBJECTS) $(CC) $(INCLUDES) $(OBJECTS) -o $@ $(LIBS) .cpp.o: $(CC) $(CFLAGS) $(INCLUDES) $< -o $@ clean: rm -v -f *~ ../common/*.o *.o *.obj $(EXECUTABLE)
To compile the code, we simply run the make
command in the project directory and it generates the executable (main
) automatically.
Further documentation on each of the libraries installed can be found here:
18.118.126.241