Building OpenGL/GLFW Apps |
Makefile
and source
code build a simple line drawing application and runs on Linux,
Mac OS X, and Windows platforms. You can also try out some
examples with buffer objects and shaders.
For instructions on how to build GLUT programs, please refer to the course
note Building OpenGL/GLUT Programs. Please
let me know if you have
any correction or addition. Thanks.
To find out how to specify command line options, add to header file
search path, and link with libraries such as glew, expat, jpeg, and
png, see the course note on these
topics.
sudo apt-get install cmake xorg-dev libglu1-mesa-dev
You must have sudo privileges. (On Red Hat, you'll need to install
cmake28 instead.)
You should now have:
/usr/include/GL
/usr/lib/x86_64-linux-gnu/libGL.so
cd glfw-3.0.4
rehash
cmake -G "Unix Makefiles"
make
sudo make install
You should now have:
/usr/local/include/GLFW
/usr/local/lib/libglfw3.a
#include <GLFW/glfw3.h>
You don't need to include gl.h
as it is already included in glfw3.h
.glu.h
automatically, set the
-DGLFW_INCLUDE_GLU
compiler flag.
-lglfw3 -lGL -lm -lXrandr -lXi -lX11 -lXxf86vm -lpthread
The last three libraries are needed on Ubuntu 14.04.1.
sudo apt-get install eclipse eclipse-cdt
make
, gcc
, ld
, etc.). Since we're not
cross compiling, I choose the "Linux GCC" toolchain. Click "Finish"
(Fig. 4)
server.c
(or click the directory
name on the left pane to import all files in the directory), and click "Finish"
(Fig. 8)
/System/Library/Frameworks/OpenGL.framework
cd
to the top level glfw folder created in the previous step
- mkdir build; cd build
- cmake .. -DGLFW_USE_RETINA=0 -DBUILD_SHARED_LIBS=1 -DCMAKE_C_FLAGS="-Wno-deprecated"
- make; sudo make install
- cd /usr/local/
- sudo chmod -R a+rX *
#include <GLFW/glfw3.h>
You don't need to include gl.h
as it is already included
in glfw3.h
. For an example, see the provided sample source code.
If you want to include glu.h
automatically, set the
-Wno-deprecated -DGLFW_INCLUDE_GLU
compiler flags when
building your app.
-lglfw -framework OpenGL
To link with the static GLFW library, use instead:
-lglfw3 -framework Cocoa -framework OpenGL -framework IOKit -framework CoreVideo
C:\Program Files (x86)\Windows Kits\8.1\Include\um\gl\GL.h
Your installation may have something other than um on the path.
C:\Program Files (x86)\Windows Kits\8.1\Lib\winv6.3\um\x86\OpenGL32.Lib
C:\Program Files (x86)\Windows Kits\8.1\Lib\winv6.3\um\x64\OpenGL32.Lib
C:\Windows\System32\opengl32.dll
C:\Windows\SysWOW64\opengl32.dll
C:\Program Files\Microsoft Visual Studio 12.0\VC\include\GLFW\glfw3.h
C:\Program Files\Microsoft Visual Studio 12.0\VC\include\GLFW\glfw3native.h
C:\Program Files\Microsoft Visual Studio 12.0\VC\lib\glfw3.lib
C:\Program Files\Microsoft Visual Studio 12.0\VC\lib\glfw3dll.lib
C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\glfw3.dll
C:\Program Files\Microsoft Visual Studio 12.0\VC\lib\amd64\glfw3.lib
C:\Program Files\Microsoft Visual Studio 12.0\VC\lib\amd64\glfw3dll.lib
C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\amd64\glfw3.dll
#include <GLFW/glfw3.h>
You don't need to include gl.h
as it is already included
in glfw3.h
. For an example, see the provided sample source code.
[If you want to include glu.h
automatically, add
#define GLFW_INCLUDE_GLU
before the above #include statement.
Similarly if you want to build apps using GLFW's DLL
instead of the static library, add
#define GLFW_DLL
before the #include.]
opengl32.lib;glfw3.lib;
Be careful not to add a space before or after the
semicolon. Hit RETURN and then click "Apply"
(Fig. 40). [If you're using the GLFW's
DLL, replace glfw3.lib with glfw3dll.lib.]
/SUBSYSTEM:WINDOWS /ENTRY:mainCRTStartup
then click "Apply" (Fig. 41). You
may not want to disable the console window if you print out
messages to the console (see next step).
glBindBuffer()
and
those that uses shaders segfault on the call to
glCreateProgram()
for me. I have also not been able to
compile GLFW for Cygwin/X11 for lack of Xf86VidMode library.
So we'll build WGL apps instead. On 64-bit Cygwin, you can choose to
build either 32- or 64-bit apps. If you use static libraries, you can
set up Cygwin to support both.
/usr/include/w32api/GL
/lib/w32api/lib{opengl,gdi}32.a
/usr/YOUR_TOOLCHAIN/include/GLFW
You'd have to create the include and GLdirectory.
Here YOUR_TOOLCHAIN is x86_64-pc-cygwin, so replace
every occurrences of YOUR_TOOLCHAIN with x86_64-pc-cygwin,
we'll see the use of other toolchains below.
/usr/YOUR_TOOLCHAIN/lib/libglfw3.a
/usr/YOUR_TOOLCHAIN/lib/glfw3dll.a
When linking against a library, unlike Visual Studio,
the MinGW/Cygwin linker looks for either
lib<pkg>.a or <pkg>.lib,
not lib<pkg>.lib.
/usr/YOUR_TOOLCHAIN/bin/glfw3.dll
You must add /usr/YOUR_TOOLCHAIN/bin to your environment
PATH variable prior to launching your app.
-lglfw3 -lopengl32 -lgdi32
[Some antivirus software such as Avast! may automatically move the
binary you build into its virus quarantine folder. You may want to
exclude your working folder from automatic virus quarantine.]
Devel→cygwin32-gcc-g++
Devel→mingw64-x86_64-gcc-g++
Devel→mingw64-i686-gcc-g++
Devel→mingw-gcc-g++
The setup program will figure out, download, and install
all necessary dependencies.
Let YOUR_TOOLCHAIN be one of i686-pc-cygwin
,
i686-pc-mingw32
, i686-w64-mingw32
, or
x86_64-w64-mingw32
, which correspond to the above toolchains
in order. The Win32 OpenGL and Microsoft GDI libraries corresponding
to each toolchain should be installed in:
/usr/YOUR_TOOLCHAIN/sys-root/{usr,mingw}/lib/libopengl32.a
/usr/YOUR_TOOLCHAIN/sys-root/{usr,mingw}/lib/libgdi32.a
with the OpenGL include files in:
/usr/YOUR_TOOLCHAIN/sys-root/{usr,mingw}/include/GL
Be sure to add the path /usr/YOUR_TOOLCHAIN/sys_root/{usr,mingw}/bin,
to your search path for binaries and dynamically linked libraries (dll),
i.e. your environment PATH variable, in addition to /usr/YOUR_TOOLCHAIN/bin
already mentioned above. (As such, you can only have one toolchain in use
for a given PATH environment variable.)