Chapter 15. Using OpenGL

Table of Contents
Using OpenGL in FLTK
Making a Subclass of Fl_Gl_Window
Using OpenGL in Normal FLTK Windows
OpenGL Drawing Functions
Using OpenGL Optimizer with FLTK

This chapter discusses using FLTK for your OpenGL applications.

Using OpenGL in FLTK

The easiest way to make an OpenGL display is to subclass Fl_Gl_Window. Your subclass must implement a draw() method which uses OpenGL calls to draw the display. Your main program should call redraw() when the display needs to change, and (somewhat later) FLTK will call draw().

With a bit of care you can also use OpenGL to draw into normal FLTK windows. This allows you to use Gouraud shading for drawing your widgets. To do this you use the gl_start() and gl_finish() functions around your OpenGL code.

You must include FLTK's <FL/gl.h> header file. It will include the file <GL/gl.h>, define some extra drawing functions provided by FLTK, and include the <windows.h> header file needed by WIN32 applications.