FLTK Tutorial
Richard Yu Gu
September, 1999


CS 638 Graphics
Instructor: Dr. Gleicher
TA: Richard Yu Gu

Updated September 2000, Michael Gleicher






Last modified: 17:12 Sep 7, 2001

1 Introduction

The Fast Light Tool Kit ("FLTK", pronounced "fulltick") is a LGPL'd C++ graphical user interface toolkit for X (UNIX®), OpenGL®, and Microsoft® Windows® NT 4.0, 95, 98, or 2000.

This tutorial shows how to construct GUI applications using FLTK with Microsoft Visual C++ 6.0.

This tutorial documentation is intended for the reader to quickly get started with FLTK library under MSVC++ for the Graphics class.  Note: This is neither a detailed or complete documentation for the FLTK library or MSVC++.  Instead, it walks you through the process of building a program with fltk in the U. Wisconsin CSL software environment.

For the complete documentation please check at http://www.fltk.org/, or locally at S:\fltk\i386_win2k\documentation\.  Since this documentation is intended for the students in the Graphics class only, we assume that you are using the instructional Windows 2000 stations in the CSL labs.

2 Creating A New FLTK Work Space In Visual C ++ 6.0

  1. Open Microsoft Visual C++ 6.0 application, by selecting from Start->Programs->Microsoft Visual C++ 6.0 [or Microsoft Visual Studio 6.0]->Microsoft Visual C++ 6.0.
  2. Choose File->New...
  3. On top of the dialog box, click on the "Projects" Tab.
  4. Select "Win32 Console Application" option.  (This is important if you want to use some standard I/O for debugging)
  5. Choose a location and name for the new project.
  6. Enable "Create new workspace" ( assume that you are creating a brand new project )
  7. Click "Ok"
  8. Choose in the next dialog the option "An empty project".
  9. Click "Finish".
  10. Click "Ok" in the next dialog
This process should create a new directory with "name" at your specified location containing the project files, and open the project up in the MSVC++ program.

Note: One big advantage of FlTk over some of the other UI toolkits is that it can be built into a console application. That means that all of the C++ standard I/O stuff you used under Unix (like printf or cout) can be used in your programs.

3 Setting-Up the FLTK project

Now the new project is created, we are going to configurate it to be a FLTK project.

  1. Select Project->Settings...
  2. Choose "All Configurations" option in "Settings For:" menu.
  3. Click "C/C++" tab, this should bring up the C/C++ compiler page up.
  4. Choose "Preprocessor" page from "Category" menu
  5. In the field "Additional include directories:", type in: s:\fltk\include

  6. this tells the compiler where the header files for the library are.
  7. Click "Link" tab, this should bring up the linker page.
  8. Under "Category" menu, select "Input"
  9. In the "Additional library path:" field, type in: s:\fltk\lib

  10. this allows the linker to find FLTK library binary files.
            The following steps will set the project, so that correct output format is used when generating object files.
  1. Click "C/C++" tab again
  2. Choose "Code Generation" in the "Category" menu
  3. Select "Win32 Release" item, in the "Settings For:" menu
  4. Change "Use run-time library" option to "Multithreaded DLL" by selecting it from the menu.
  5. Select "Win32 Debug" item, in the "Settings For:" menu
  6. Change "Use run-time library" option to "Debug Multithreaded DLL" by selecting it from the menu.
            Then we need to tell the linker to use the essential librarys when creating the executable file. Notice that we must change the settings for both "Debug" and "Release" versions. For debug, we need to specify the debug version of the fltk library. Also, notice that we are adding the 2 libraries to our program, so we must be careful not to remove any others.
  1. Click "Link" tab
  2. Select "Win32 Release" item, in the "Setting For:" menu
  3. Add WITHOUT replacing anything else in the "Object/library modules:" field the following text: fltk.lib wsock32.lib
  4. Select "Win32 Debug" item, in the "Setting For:" menu
  5. Add WITHOUT replacing anything else in the "Object/library modules:" field the following text: fltkd.lib wsock32.lib
  6. Then click "Ok".


4 Create and Add Source Files The The Project

After you have all the options setup, the project is FLTK ready.  All you need is to add your FLTK source files to the project, then build and run.

To add source files to the project, you need to follow the following instruction.

  1. Choose Project->Add To Project->Files....
  2. You should see a file-selection dialog appears.  Select the files that you want to add to the project.  You can select multiple files in the same directory by holding down Ctrl key and click the file name.
  3. Click Ok.
One working example program source code is here.  You can try this file first to make sure that all the options for the project is setup correctly.

There is a working example project here.   You can use the settings of this project as a template for our programs.

For more FLTK code examples please refer to the FAQ of this tutorial.

5 Build And Run

Choose Build->Build [projectname].exe.

Now choose Build->Execute [projectname].exe

This should compile and link this project, and launch the new executable.

If during Build process, error messages are generated, then there might be some problem with either your code or some settings that we have done.  For more detail please refer to Trouble Shooting.

If the errors occur at other places, most likely the problem is in your program code itself.

Note: You can choose to build and run the project in either Debug or Release configuration by choosing the desired option through Build->Set Active Configuration... menu.

6 Reopen A Project

The easiest way to do so is to go to the project directory and double-click on the [projectname].dsw file.

Or you can choose File->Open WorkSpace within the MSVC application, and open the [projectname].dsw file.

7 FLTK Basics

Appendix A.  Trouble Shooting. Appendix B FAQ
  1. Are there any FLTK examples program we can check out to get a feel for the library?
    1. There are examples at S:\fltk\src\fltk-1.0.11\test.
    2. and the Project Workspace file is at S:\fltk\src\fltk-1.0.11\visualc\fltk.dsw
To be updated when more questions come up.