Windows: command line
The following instructions assume you have administrator privileges and you can write to C:. If not, you need to adapt the instructions.
1. In your PC's root directory (C:):
(a) Create a folder called C:include. We will put header files here.
(b) Create a folder called C:lib. We will put libraries (.lib) and dynamic link libraries (.dll) here.
(c) Create a folder called C:hello. Source code and executables will go here.
2. Go to www.visualstudio.com and download Microsoft Visual Studio Community 2015.
(a) When installing, choose 'Custom Install', and choose to include the C++ components of Visual Studio.
3. Go to www.glfw.org and download the 32-bit Windows binaries for GLFW 3.2.
(b) Move the folder glfw-3.2.bin.WIN32includeGLFW to C:include.
(c) Move the folder glfw-3.2.bin.WIN32includeGLFW to C:include.
(d) Move the files glfw-3.2.bin.WIN32lib-vc2015* to C:lib.
(e) You can now delete the zip file (or compressed folder).
4. Go to glm.g-truc.net and download GLM 0.9.7.6 .
(b) Move the glm folder to C: to that it becomes C:glm.
(c) You can now delete the zip file (or compressed folder).
5. Use the Visual Studio code editor, or any other code editor, to create a file called C:hellohello.cc with the following content:
#include <iostream>
int main (int argc, char* argv[]) {
return 0;
6. From the Start menu, run 'Developer Command Prompt for VS2015'. At the command prompt, type:
hello
This should compile, link, and run a simple program that prints 'Hello world!' to the terminal.
7. Copy C:libglfw3.dll to C:hello. (The DLL needs to be located in the same location as the executable.)
8. Using the code editor, create a file called C:hellotriangle.cc with the following content:
TO COMPILE AND RUN:
cl triangle.cc /Iinclude libglfw3dll.lib opengl32.lib /EHsc
//#define GLFW_DLL
void keyCallback(GLFWwindow* window, int key, int scancode, int action, int mods) {
if (key GLFW_KEY_Q)
}
GLFWwindow* window;
window = glfwCreateWindow(640, 480, 'Hello World', NULL, NULL);
glfwMakeContextCurrent(window);
while (!glfwWindowShouldClose(window)) {
glBegin(GL_TRIANGLES);
glVertex3f(0.5, 0., 0.);
glEnd();
glfwPollEvents();
glfwTerminate();
}
9. At the command line, typecl triangle.cc /Iinclude libglfw3dll.lib opengl32.lib /EHsc
. You may copy this from the code and paste it into the terminal. Here is an explanation:
- This command tells Windows to use the Visual C++ compiler 'cl' to compile the source code in 'triangle.cc'.
- The compiler (actually the preprocessor) looks for the include file GLFW/glfw3.h in the directory include.
- The compiler generates an object file triangle.obj.
- The linker takes triangle.obj and links it with the library libglfw3dll.lib, which we installed manually. It also links it with opengl32.lib, which is in the default path for libraries (if you are using 'Developer Command Prompt for VS2015').
10. At the command line, type triangle
. This should launch the GLFW/OpenGL application, which creates a window displaying a triangle. Press the Q key to exit. Alternatively, go to the terminal window and press Ctrl-C.
Windows: using Visual Studio's IDE
In Visual Studio > Class View (Dialog box?) > Project Properties > Property Pages (wrench icon):
- Configuration Properties > C/C++ > General > Additional Include Directories: add 'C:include' (and maybe C:glm and anywhere else you might have put header files)
- Configuration Properties > Linker > General > Additional Library Directories: add 'C:lib' and anything else relevant
- Configuration Properties > Linker > Input > Additional Dependencies: add 'opengl32.lib;glfw3.lib' somewhere in the semicolon-separated list
Ubuntu 14.04
This is a real pain. Follow instructions at http://stackoverflow.com/questions/17768008/how-to-build-install-glfw-3-and-use-it-in-a-linux-project. It goes something like this.
1. Install CMake:
2. Install GLFW: Go to http://www.glfw.org/download.html and download the source package, which is a zip file with a name like glfw-3.2.1.zip. Unzip the zip file and go into the directory, then run cmake:
cd ~/Downloads
unzip glfw-3.2.1.zip
cd glfw-3.2.1/
cmake .
If this fails you may need to install various other dependencies. Follow the tutorial link above. For example, you may need to dosudo apt-get install cmake xorg-dev libglu1-mesa-dev
Finally, when cmake succeeds, you can do sudo make install
3. Install GLM. Go to the GLM website, download the tarball, and unpack it. Go into the directory and then
4. Test. Set up a C++ source file using GLFW (see GLFW website). Compile and link using a command like this:
g++ -o myprog.exe myprog.cc -lGL -lglfw3 -lX11 -lXxf86vm -lXrandr -lpthread -lXi -ldl -lXinerama -lXcursor
(Deprecated) In Ubuntu 12.04, you can set up GLUT+GLEW+OpenGL using sudo apt-get update
sudo apt-get install freeglut3-dev
Mac OS X
1. Install CMake. Go to the CMake website, download the Mac OS X installer (a .dmg file), and run the installer. Then set it up to be run from the command line:
sudo /Applications/CMake.app/Contents/bin/cmake-gui --install=/usr/local/bin
2. Install GLFW. Go to the GLFW website, download the latest source tarball, and unpack it anywhere (e.g., in Downloads). Then
cd glfw-3.2.1
cmake .
make
sudo make install
3. Install GLM. Go to the GLM website, download the tarball, and unpack it. Then
cd glm
cmake .
make
sudo make install
Or, maybe just
udo apt install libglm-dev
3b. Install GLEW. (From sourceforge.net)
4. Compile and run C++ code. The command will be something like this:
fname=glfwLighting;
g++ -o $fname $fname.cc -I/usr/local/include -L/usr/local/lib
-lglfw3 -framework Cocoa -framework OpenGL -framework IOKit -framework CoreVideo
$fname
and in the code you might have something like
#include <GLFW/glfw3.h>
//#include <glm/glm.hpp>
#include <glm/gtx/transform.hpp>// for rotate, etc.