CMP160
Spring 2007
Program # 1 FLTK/OpenGL
Handout
Getting Started
In the first assignment we expect you to become familiar
with basic 2D graphical objects under orthographic projection using OpenGL
libraries and building interfaces with controls (widgets) using FLTK libraries.
We are providing a sample template for the first assignment containing the
following files.
prog1.cpp, prog1.h, gui.cpp, gui.h, graph.cpp, graph.h, Makefile
FLTK Basics
- For working on this assignment,
familiarity with the second and third chapters from FLTK programming
manual is sufficient.
- FLTK provides some common widgets
like buttons, text, boxes, labels etc. The files gui.{cpp/h} take care of the fltk interface part.
The sample template code contains only one exit button and a box for
drawing the graph. FLTK interface changes should be made to the programs gui.cpp and gui.h. In addition to the box and
the button, we need to place two more round buttons and a check button as
shown in the output program.
- The round buttons are used to select
bar graphs and line graphs. At a time only one round button should be
enabled. We can set various properties like color, position, type, etc for
each widget. For example by setting the type of the two round buttons to radio,
we make sure that only one of them can be enabled at a time.
- A check button should be placed to
view the ESI values near the graphs. On checking it, the values
should be visible on the graph and vice versa.
- After creating these buttons,
callback functions have to be written to handle the events on clicking the
buttons. Playing around with other widgets for creative interfaces will be
a very good learning experience.
OpenGL Basics
- Chapter 1 and first half of chapter 2
from the book OpenGL programming guide (red book)
explain the necessary basics for implementing the first assignment. Some
2D graphical operations like clearing the screen, 2D orthographic
projection and drawing basic geometric primitives like points, lines,
filled polygons etc are required. The section on OpenGL Geometric
Drawing Primitives from chapter 2 in the red book gives the necessary
information for drawing various 2D objects.
- The drawing operations take place in
the files graph.cpp and graph.h. For drawing the graphs
you need to first load the ESI data for a city by reading a file
in graph.cpp file. Then
have two separate functions drawLineGraph()
and drawBarGraph() for
drawing line graphs and bar graphs respectively. The choice between line
graph and bar graph is made based on the status of the corresponding round
buttons. Also use a separate function for drawing the legends at one
corner of the display box. If the legend is consistent with both the line
graph and the bar graph then you don’t have to change it depending on the
type of the graph.
- gluOrtho2D()
function can be used for setting orthographic projection mode for
viewing 2D objects. glClearColor(
) and glClear() functions
can be used for clearing the screen before drawing the objects. For
drawing points on a 2D screen we use glVertex2f()
function. With the function calls glBegin(),glEnd()
and glVertex2f(), we can draw different
kinds of geometric primitives like points, lines, triangles, quads,
polygons, etc by specifying the type of primitive. In our assignment we
need to use this structure for drawing the line graph and bar graph for
the temperature data. The line graph can be drawn using GL_LINE_STRIP primitive and the
bar graph can be drawn using GL_QUADS
primitive.
· By
default all polygons are filled with the current color. In our program we need
to set different colors for filling the bar graphs and legends.
- In addition to the given sample
program, please spend some time on the sample programs in Chapter 2 of the
red book for understanding various other OpenGL concepts like double
buffering. You will need to modify only the files graph.cpp, graph.h,
gui.cpp, gui.h and Makefile in this assignment. However you may add
additional files for modularity.