Difference between revisions of "Using GLFW with Code::Blocks"

From Code::Blocks
 
Line 21: Line 21:
 
#Download the GLFW sources (including documentation) from: http://prdownloads.sourceforge.net/glfw/glfw-2.5.zip?download
 
#Download the GLFW sources (including documentation) from: http://prdownloads.sourceforge.net/glfw/glfw-2.5.zip?download
 
#Unzip the archive anywhere you like (I will assume <tt>C:\glfw</tt> for simplicity).
 
#Unzip the archive anywhere you like (I will assume <tt>C:\glfw</tt> for simplicity).
#For Windows users, there is a batch file which allows to compile using a variety of compilers.
+
#Compile
#*Open a DOS window, <tt>cd</tt> to the directory where GLFW lives (e.g. <tt>C:\glfw</tt>), and type <tt>compile make mgw</tt>. If you use the Borland compiler, type <tt>compile make bcc</tt> instead, and for MSVC, type <tt>compile make msvc</tt>.
+
#*For Windows users, there is a batch file which allows to compile using a variety of compilers. Open a DOS window, <tt>cd</tt> to the directory where GLFW lives (e.g. <tt>C:\glfw</tt>), and type <tt>compile make mgw</tt>. If you use the Borland compiler, type <tt>compile make bcc</tt> instead, and for MSVC, type <tt>compile make msvc</tt>.
 
#*Linux users will just want to type <tt>make</tt>.
 
#*Linux users will just want to type <tt>make</tt>.
 
Build time is ~1 minute.
 
Build time is ~1 minute.
Line 29: Line 29:
 
==Installing GLFW==
 
==Installing GLFW==
 
#Navigate to the <tt>lib\win32</tt> folder (<tt>lib\x11</tt> for Linux).
 
#Navigate to the <tt>lib\win32</tt> folder (<tt>lib\x11</tt> for Linux).
#Copy <tt>libglfw.a</tt>, <tt>libglfwdll.a</tt>, and <tt>glfw.dll</tt> from inside the <tt>lib\win32</tt> folder (<tt>lib\x11</tt> for Linux) to where you keep your dll files (could be <tt>C:\MinGW\dll</tt> or <tt>C:\MinGW\lib</tt>, whatever).
+
#Copy <tt>libglfw.a</tt>, <tt>libglfwdll.a</tt>, and <tt>glfw.dll</tt> from inside the <tt>lib\win32</tt> folder (<tt>lib\x11</tt> for Linux) to where you keep your libraries (could be <tt>C:\MinGW\dll</tt>, <tt>C:\MinGW\lib</tt>, or <tt>C:\CodeBlocks\lib</tt>, whatever).
 
#Go up two levels (to the GLFW base directory), and then into <tt>include/GL</tt>. Copy <tt>glfw.h</tt> to the <tt>GL</tt> folder inside your system includes folder (e.g. <tt>C:\MinGW\include\GL</tt> or <tt>C:\codeblocks\include\GL</tt>)
 
#Go up two levels (to the GLFW base directory), and then into <tt>include/GL</tt>. Copy <tt>glfw.h</tt> to the <tt>GL</tt> folder inside your system includes folder (e.g. <tt>C:\MinGW\include\GL</tt> or <tt>C:\codeblocks\include\GL</tt>)
  

Revision as of 21:20, 9 October 2005

Using GLFW with Code::Blocks to develop OpenGL applications

What is GLFW

"GLFW is a free, open source, portable framework for OpenGL application development.

In short, it is a link library that constitutes a powerful API for handling operating

system specific tasks, such as opening an OpenGL window and reading keyboard, mouse and joystick input."

You want to write a program using OpenGL and worry whether messing with W32 API, GLUT, or SDL is the least evil?
In this case, GLFW is for you. GLFW lets you create a window with an OpenGL context (including full-screen windows), sample mouse and joysticks and read keyboard input in a platform-independent way. Additionally, GLFW offers portable high resolution timing and multithreading/message functionality. All of this goes into a 36kB library that is zlib-licensed, which more or less means you can do with it whatever you want, as long as you do not claim authorship of the library or have some other obviously illegal intent. All in all, this is certainly one of the best available OpenGL toolkits.

Prerequisites

  1. Internet Connection
  2. Some archiving program (tar, 7z, WinZip, PowerArchiver, ...)
  3. Code::Blocks 1.0RC2 or later (for the application template)
  4. A working MinGW installation (alternatively, Borland or MSVC will work, too)


Building the Libraries

  1. Download the GLFW sources (including documentation) from: http://prdownloads.sourceforge.net/glfw/glfw-2.5.zip?download
  2. Unzip the archive anywhere you like (I will assume C:\glfw for simplicity).
  3. Compile
    • For Windows users, there is a batch file which allows to compile using a variety of compilers. Open a DOS window, cd to the directory where GLFW lives (e.g. C:\glfw), and type compile make mgw. If you use the Borland compiler, type compile make bcc instead, and for MSVC, type compile make msvc.
    • Linux users will just want to type make.

Build time is ~1 minute.


Installing GLFW

  1. Navigate to the lib\win32 folder (lib\x11 for Linux).
  2. Copy libglfw.a, libglfwdll.a, and glfw.dll from inside the lib\win32 folder (lib\x11 for Linux) to where you keep your libraries (could be C:\MinGW\dll, C:\MinGW\lib, or C:\CodeBlocks\lib, whatever).
  3. Go up two levels (to the GLFW base directory), and then into include/GL. Copy glfw.h to the GL folder inside your system includes folder (e.g. C:\MinGW\include\GL or C:\codeblocks\include\GL)

Building a GLFW Project

To build a program with GLFW, you need to include GL/glfw.h (no need to include GL/gl.h) and link to glfw, opengl32, glu32, gdi32, user32, and kernel32.

Code::Blocks 1.0RC2 includes a template to build a statically linked GLFW application. Since GLFW is really lightweight, there is actually no reason not to statically link to it, but if you insist on dynamic linkage, just change the include library in "Build Options" accordingly.

Make a new project using the GLFW template, and hit the blue gear, you should see a windown with a few spinning triangles:

The stereotypical OpenGL spinning triangle demo