Introduction to Graphics
We will be using the fltk toolkit for graphics
Links for fltk: fltk website
fltk manual
To compile your c++ program with graphics,
provide two additional directives -lfltk and -lX11 as shown
below. This will link the necessary
libraries with your program. The libraries are available in osl.
g++ myfile.cpp -lfltk -lX11
Problem statement
1. Download the program given here: program1.cpp
- Change the size of the window and fill
the window tightly with boxes of different colors
You can use your own color
for each box. Here is a program that generates a color palette: program4.cpp
2. Make changes to your program to obtain the figure drawn by this
executable program: (right click, save and execute) a1.out
You will have to play with iteration and sizes.
3. In your program, read data from this file and display it in the form
of a bar chart using
boxes of different proportionate sizes data,
data1 and
data2 and
Do not type out the numbers and the lables.. read them in with
stream i/o
Once compiled, the same program should work on any file without a single change
in the program.
The name of the data file is provided through argument to main.
Evaluation: in-lab by TAs.
Deadline: 10:30 pm
FAQ
0. I'm not getting any graphics:
you may not have passed the two parameters to g++. Read the handout again
carefully. If you passed the parameters, check the capitalization in every
parameter. Are you passing -lx11? It should be -lX11
1. downloaded a1.out is not executing?
In a terminal execute the following command:
chmod a+x a1.out
This changes the permission on the file to executable.
2. I am sending a string into a box as a label, but the program
is not compiling
This call needs the label to be of type char *
So convert the string into a char *.
To convert, use function c_str in string class.
Refer to string manual in cplusplus.com
3. In the bar graph, the heights are ok, but the lables are all the same
This is because you are using a variable to hold the char * label that you
are passing in. Use an array of char* instead.
4. My program is not terminating.. it does nothing.
Check your while loops, they may not be terminating.
5. My program generates a segmentation fault
Check your array index values..
you may be accessing out of bound,
or you may not have allocated array of required size.
or your while loop does not count no. of values correctly.
Print these values and see what's wrong.
--- Good Luck! ----