Difference between revisions of "Using GLFW with Code::Blocks"
m (edit category) |
|||
(6 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
− | + | [[Category:User Documentation]] | |
==What is GLFW== | ==What is GLFW== | ||
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 |
− | + | #*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 | + | #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>) | ||
Line 36: | Line 36: | ||
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.<br /><br /> | 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.<br /><br /> | ||
− | Make a new project using the GLFW template, and hit the blue gear, you should see a | + | Make a new project using the GLFW template, and hit the blue gear, you should see a window with a few spinning triangles: |
[[Image:Glfw-spin.png|The stereotypical OpenGL spinning triangle demo]] | [[Image:Glfw-spin.png|The stereotypical OpenGL spinning triangle demo]] |
Latest revision as of 12:47, 8 July 2006
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
- Internet Connection
- Some archiving program (tar, 7z, WinZip, PowerArchiver, ...)
- Code::Blocks 1.0RC2 or later (for the application template)
- A working MinGW installation (alternatively, Borland or MSVC will work, too)
Building the Libraries
- 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 C:\glfw for simplicity).
- 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
- Navigate to the lib\win32 folder (lib\x11 for Linux).
- 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).
- 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 window with a few spinning triangles: