GLFW v2.6 BETA
source distribution
 

  1. Introduction
  2. Compiling GLFW and the example programs
  3. Installing GLFW
  4. Using GLFW
  5. Version history
  6. Directory structure of the GLFW distribution
  7. Contacting the project
  8. Acknowledgements


1. Introduction

Welcome to version 2.6 BETA of the GLFW OpenGL framework. GLFW is a free, open source, portable framework for OpenGL application development. In short, it is a library that constitutes a powerful API for handling operating system specific tasks, such as opening an OpenGL window, reading keyboard and mouse input, creating threads, and much more.


2. Compiling GLFW and the example programs

A top level makefile can be found in the root directory of the GLFW distribution that has been designed to work with several compilers. If you simply enter the GLFW root directory in a shell and type make (or nmake or gmake, depending on the name of your make tool), and a list should appear with the currently supported options for systems and compilers.

For example, one of the options is to compile GLFW for Windows with the LCC-Win32 C compiler. To do that, type make win32-lcc in the shell (as specified in the previously mentioned list). That will compile the GLFW static link library and the supplied example programs. For Windows compilers, a Win32 DLL will also be compiled.

Currently supported compilers and systems are:

  1. Borland C++ Builder compiler 5.x for Windows
  2. Cygwin (GCC) for Windows
  3. LCC-Win32 for Windows
  4. Microsoft Visual C++ 6.x for Windows
  5. MinGW32 (GCC) for Windows
  6. OpenWatcom for Windows
  7. Pelles C for Windows
  8. Unix or Unix-like systems running the X Window System (auto detect compiler, or force GCC)
  9. Apple Developer Tools (GCC) for Mac OS X

If your compiler/system is not in the list, you will have to create new makefiles in the lib\win32, lib/x11 or lib/macosx directory, and in the examples directory. If you have any problems, do not hesitate to contact me (I may not know how your compiler works, but I know the GLFW source code). I would also like to add support for more compilers and verify that GLFW compiles under as many systems as possible, so if you had to make any modifications or additions to the source and/or makefiles in order to make GLFW compile successfully, I would like to know what you had to do.

2.1 Note for Microsoft Visual C++ users

When MSVC is installed, you are asked if it should be possible to access the compiler from the command line. For some strange reason, the default answer to this question is NO. If you answered no to this question you will have to run a file named VCVARS32.BAT, which is located in the bin directory of your Visual C++ folder, before you can use the compiler from the command line.

Note that VCVARS32.BAT must be run from the same shell as you intend to use for compiling GLFW (simply clicking on the file from the explorer will not work).

After that is done, it is possible to compile GLFW by entering the GLFW root directory and issuing nmake win32-msvc.

For instance, if MSVC is installed in the directory 'C:\Program Files\Microsoft Developer Studio\VC98', then you should be able to compile GLFW with this procedure:

  1. Start a command prompt (MS-DOS prompt)
  2. "CD" to the directory where you unzipped the GLFW source distribution (where this readme file is located)
  3. Type "C:\Program Files\Microsoft Developer Studio\VC98\BIN\VCVARS32" (with quotation marks)
  4. Type nmake win32-msvc

2.2 Note for MinGW/DevC++ users

Do not use the MSYS shell for compiling GLFW, because the supplied batch file "compile.bat" will only work under a Windows command prompt (or MS-DOS prompt).

Under Windows 98, the MinGW make program may set the $(MAKE) variable incorrectly. To remedy this, uncomment the line at the beginning of the top level Makefile that says MAKE = make (possibly replacing make with some other name, e.g. mingw32-make).

2.3 Note for Cygwin users

The Cygwin makefile was designed to run from a Cygwin bash shell. You can not use an MS-DOS prompt (or NT cmd prompt) to compile GLFW with the win32-cygwin option. Similarly, the win32-clean option will not work from a Cygwin shell, which is why there is a special cygwin-clean option.

2.4 Note for OpenWatcom users

In order to compile GLFW successfully with OpenWatcom (for Windows), execute "nmake MAKE=nmake win32-ow" in the GLFW root directory. Also make sure that you have all your environment variables set up correctly. It is the default option when installing OpenWatcom to permanently set up all the required environment variables. If nmake does not work, you probably have to run "WATCOM\setvars.bat" from the command prompt before executing nmake, where WATCOM is the directory in which you installed OpenWatcom (e.g. C:\Watcom).

2.5 Note for Pelles C users

To build GLFW with Pelles C, you need at lest version 2.80.3 of Pelles C (POCC and POLINK).

Type 'pomake win32-pellesc' to build GLFW.

2.6 Note for Unix/X11 users

Compiler and link library capabilities are auto-detected with a script called compile.sh. It has been tested under Linux Mandrake 10.1, Mac OS X 10.2, SunOS 5.6 (GCC), IRIX 5.3, FreeBSD 5.0 and QNX, but should hopefully run on the majority of available Unix/Unix-like systems and generate functional Makefiles. You do not have to run the script manually, since it is called from the top level Makefile.

2.8 Note for Mac OS X users

To compile GLFW for Mac OS X, you will need to have installed the BSD subsystem and the Developer Tools, which can be found on your Mac OS X CD:s. When they are installed, simply open Terminal and go to the root GLFW directory. From there, you can build the library and all the examples by running make, i.e. make macosx-gcc.


3. Installing GLFW

3.1 Windows

After compiling GLFW with MinGW or Cygwin, three files of interest should have appeared in the lib\win32 directory. They are: libglfw.a (the static link version of GLFW), glfw.dll (the DLL version of GLFW) and libglfwdll.a (the DLL import library).

To install GLFW on Cygwin (and possibly MinGW), run make with the cygwin-install target. This will generate the pkgconfig file and copy it, the header file and the library to the correct locations of your Cygwin installation. If you wish to change the installation location from its default, set the desired prefix path with the environment variable PREFIX.

If you used Borland C++ Builder, LCC-Win32, Microsoft Visual C++ or OpenWatcom, the files are named glfw.lib (the static link version of GLFW), glfw.dll (the DLL version of GLFW) and glfwdll.lib (the DLL import library).

The static link library and the DLL import library should be copied to your compiler's LIB directory (where all other link libraries are located). The DLL can be copied either to your Windows system directory (where opengl32.dll is located), or to the project directory of your GLFW-based projects (where you place your compiled EXEs).

You should also copy the GLFW include file, include\GL\glfw.h, to the GL directory of your compiler's include directory (where gl.h, glu.h etc. are located).

3.2 Unix

After compiling GLFW, three files named libglfw.pc.in, libglfw.a and libglfw.so should have appeared in the lib/x11 directory. This is the pkgconfig template file, the GLFW static link library and the GLFW shared library, respectively.

To install GLFW onto your system, run make as root with the x11-install build target. This will install the pkgconfig file, the static library and the header. By default, the files will be installed under /usr/local. If you wish to install to a different location, set the environment variable PREFIX appropriately when running make.

Note that the shared library is not installed by default, as you really should think twice before using it. GLFW is very small and shared library distribution on Unix outside of packaging systems is quite tricky. The GLFW license also allows static linking without requiring your to share your code.

3.4 Mac OS X

After compiling GLFW, three files named libglfw.pc.in, libglfw.a and libglfw.dylib should appear in the lib/macosx directory. This is the pkgconfig template file, the GLFW static link library and the GLFW dynamic library, respectively.

To install GLFW onto your system, run make with sudo and the macosx-install build target, i.e.:

  sudo make macosx-install

This will install the pkgconfig file, the static library and the header. By default, the files will be installed under /usr/local. If you wish to install to a different location, set the environment variable PREFIX appropriately when running make.

Note that the shared library is not installed by default, as you really should think twice before using it. GLFW is very small and very sutable for static linking. The GLFW license also allows static linking without requiring your to share your code.

4. Using GLFW

There are two aspects to using GLFW:

  1. How does the GLFW API work
  2. How to compile programs that use GLFW

The first point is covered in the GLFW Users Guide and the GLFW Reference Manual, and I suggest that you read at least the Users Guide, since it is a good introduction to the GLFW API.

Designing and compiling programs that use GLFW is not very difficult. A few rules for successfully designing GLFW-based programs are presented in the following sections.


4.1 Include <GL/glfw.h>

In your program, you should include <GL/glfw.h>. This include file defines all the necessary constants, types and prototypes that are used to interact with the GLFW API. It also includes <GL/gl.h> and <GL/glu.h>, and - this is very important - it defines all the necessary constants and types that are necessary for OpenGL to work on different platforms.

For instance, under Windows you are normally required to include <windows.h> before you include <GL/gl.h>. If you write such a program, it would not compile under e.g. Linux since <windows.h> does not exist under Linux. <GL/glfw.h> takes care of these things for you. Note however that it does not actually include <windows.h>, it merely mimics the parts of it that are needed for <GL/gl.h> and <GL/glu.h> (this way we do not get the thousands of constants, types and prototypes that could otherwise possibly interfere with our own declarations).

In other words:

Note: If you do need to include <windows.h>, do it before including <GL/glfw.h>.


4.2 Link with the right libraries

4.2.1 Windows static library

If you link with the static version of GLFW, it is also necessary to link with some system libraries that GLFW uses.

When linking a program under Windows that uses the static version of GLFW, you must also link with the following libraries: opengl32, user32 and kernel32. Some of these libraries may be linked with by default by your compiler. In the table below you can see the minimum required link options for each supported Windows compiler (you may want to add other libraries as well, such as glu32):

CompilerLink options
Borland C++ Builderglfw.lib opengl32.lib
CygwinSee Unix static library below
LCC-Win32glfw.lib opengl32.lib
Microsoft Visual C++glfw.lib opengl32.lib user32.lib
MinGW32-lglfw -lopengl32
OpenWatcomglfw.lib opengl32.lib user32.lib
Pelles Cglfw.lib opengl32.lib user32.lib kernel32.lib


4.2.2 Windows DLL

To compile a program that uses the DLL version of GLFW, you need to define the GLFW_DLL constant. This can either be done with a compiler switch, typically by adding -DGLFW_DLL to the list of compiler options. You can also do it by adding the line:

#define GLFW_DLL

...to all your source files that include glfw.h, before including it.

When linking a program under Windows that uses the DLL version of GLFW, the only library you need to link with for GLFW to work is glfwdll. In the table below you can see the minimum required link options for each supported Windows compiler (you may want to add other libraries as well, such as opengl32 and glu32):

CompilerLink options
Borland C++ Builderglfwdll.lib
Cygwin-lglfwdll
LCC-Win32glfwdll.lib
Microsoft Visual C++glfwdll.lib
MinGW32-lglfwdll
OpenWatcomglfwdll.lib
Pelles Cglfwdll.lib


4.2.3 Unix static library

GLFW now supports pkgconfig, and a libglfw.pc file is generated and installed when you install the library. For systems that do not provide pkgconfig, you should look in this file for the proper compile and link flags for your system, as determined by compile.sh at compile time.

A typical compile and link command line may look like this (using GCC):

  gcc `pkg-config --cflags libglfw` -o myprog myprog.c `pkg-config --libs libglfw`

If you use GLU functions in your program you should also add -lGLU.


4.2.5 Mac OS X static library

When compiling and linking a program under Mac OS X that uses GLFW, you must also link with the following frameworks: Carbon.framework, AGL.framework and OpenGL.framework.

If you are using Xcode, you simply add the GLFW library libglfw.a and these frameworks to your project. If, however, you are building your program from the command line, there are two methods for correctly linking your GLFW program.

GLFW now supports pkgconfig, and a libglfw.pc file is generated and installed when you install the library. You can find pkgconfig in most packaging systems, such as Fink and DarwinPorts, so if you have one of them installed, simply install pkgconfig. Once you have pkgconfig available, the command line for compiling and linking your program is:

  gcc `pkg-config --cflags libglfw` -o myprog myprog.c `pkg-config --libs libglfw`

If you do not wish to use pkgconfig, you will need to add the required frameworks and libraries to your command line using the -l and -framework switches, i.e.:

  gcc -o myprog myprog.c -lglfw -framework Carbon -framework AGL -framework OpenGL

Note that you do not add the .framework extension to a framework when adding it from the command line.

These frameworks contain all GL and GLU functions, so there is no need to add additional libraries or frameworks when using GLU functionality. Also note that even though your machine may have Unix-style GL libraries, they are for use with the X Window System, and will not work with the Mac OS X native version of GLFW.

5. Version history

v2.6

v2.5

v2.4.2

v2.4.1

v2.4

v2.3.2

v2.3.1

v2.3

v2.2.3

v2.2.2

v2.2.1

v2.2

v2.1

v2.0.3

v2.0.2

v2.0.1

v2.0

v1.0.2

v1.0.1

v1.0.0


6. Directory structure of the GLFW distribution

Here is an overview of the directory structure of the GLFW distribution:

docs GLFW manuals in PDF format
examples Several example programs in C
images Images for this HTML document
include  
   GL Here is the GLFW C/C++ include file
lib The source code for GLFW
   amigaos AmigaOS specific implementation (obsoleted)
   dos DOS specific implementation (obsoleted)
   macosx Mac OS X specific implementation
   win32 Windows specific implementation
   x11 Unix/X11 specific implementation
support  
   d D support
   delphi Delphi support
   lua Lua support
   masm MASM32 support
   visualbasic Visual Basic support



7. Contacting the project

The official GLFW web site can be found here: http://glfw.sourceforge.net/. It contains the latest version of GLFW, news and other information that is useful for OpenGL development.

If you have questions related to the use of GLFW, we have a user's web forum, and a user's mailing list on SF.net, and the IRC channel #glfw on Freenode.

If you have a bug to report or a feature you'd like to request, please file it in the SF.net trackers.

Finally, if you're interested in helping out with the development of GLFW or porting it to your favorite platform, we have a developer's mailing list, or you could join us on #glfw.


8. Acknowledgements

GLFW would not be what it is today without the help from: