简体   繁体   中英

FLTK box element not visible in window

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?

在此输入图像描述

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM