3

I'm a beginner in C++ and working through Stroustrup's - Programming Principles and Practice using C++. In chapter 12, the display model is introduced with the task to install and run FLTK on the system.

I installed FLTK and can compile the two test_programs without an issue. But once I run it, only the window is drawn but no box & text is visible.

test_program.cpp

#include <FL/Fl.H>
#include <FL/Fl_Box.H>
#include <FL/Fl_Window.H>

int main() 
{
  Fl_Window window(200, 200, "FLTK");
  Fl_Box box(0,0,200,200,"Hey, this is FLTK!");
  window.show();
  return Fl::run();
}

test_program2.cpp:

#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Box.H>

int main(int argc, char **argv)
{
  Fl_Window *window = new Fl_Window(340,180);
  Fl_Box *box = new Fl_Box(20,40,300,100,"Hello, World!");
  box->box(FL_UP_BOX);
  box->labelfont(FL_BOLD+FL_ITALIC);
  box->labelsize(36);
  box->labeltype(FL_SHADOW_LABEL);
  window->end();
  window->show(argc, argv);
  return Fl::run();
}

Installation process used for FLTK on OSX 10.14 (Mojave) with XCode 10.1 (Command Line Tools are installed):

  1. Installed brew (https://brew.sh/)
  2. Installed FLTK brew install FLTK
  3. Run fltk-config --compile test_program.cpp
  4. Launched executable

From what I can tell all the files seem to be in the right place. clang++ command given by fltk-config (No errors or warnings given):

clang++ -I-I/usr/local/Cellar/fltk/1.3.4-2/include -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_THREAD_SAFE -D_REENTRANT -g -o ../a test_program.cpp /usr/local/Cellar/fltk/1.3.4-2/lib/libfltk.a -lpthread -framework Cocoa

When I launch the executable with ./a, the window pops up and looks like this in both cases, with no box visible. What am I missing?

enter image description here

With my little knowledge about the subject matter, I'm happy about any ideas, hints, pointers. Thank you so much in advance.

Juri
  • 604
  • 9
  • 19
  • Can you try this `box->set_active(); box->show() box->fontcolor(FL_WHITE);`, see if it changes anything. – Strong will Nov 03 '18 at 23:26
  • I added ```box->set_active(); box->show();``` in FLTK 1.3.4 there doesn't seem to be a fontcolor, so I set ```box->color(FL_WHITE)```. But no change to the result. But still also no warnings or errors. – Juri Nov 04 '18 at 09:37
  • Seems to work with 1.3.4 – cup Nov 12 '18 at 21:05

1 Answers1

3

Using fltk-1.4.x-r13107 fixed the issue.

According to the fltk.general Google group, with OSX Mojave (10.14), Apple changed calling logic of drawing on the screen (source).

For all people who are new to c++ & fltk and are not used to install software manually, this worked for me:

  1. Download latest fltk-1.4.x release from http://www.fltk.org/software.php
  2. tar -zxvf fltk-1.4.x-r13107.tar.gz
  3. cd fltk-1.4.x-r13107
  4. make clean
  5. ./configure
  6. make
  7. sudo make install
  8. version check: fltk-config --version should be 1.4.x
Juri
  • 604
  • 9
  • 19
  • Looks like there is also a homebrew tap for it here: https://github.com/gtDMMB/homebrew-core so it's installable with `$ brew install --build-from-source gtDMMB/core/fltkwithcairo` – kjones Mar 15 '19 at 03:39