Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add bootstrap example using FLTK #29

Open
pdhahn opened this issue Apr 19, 2022 · 2 comments
Open

Add bootstrap example using FLTK #29

pdhahn opened this issue Apr 19, 2022 · 2 comments

Comments

@pdhahn
Copy link

pdhahn commented Apr 19, 2022

Similar to boostraps using wxWidgets or Qt, please add a case using FLTK 1.4.

@mosra
Copy link
Owner

mosra commented Apr 20, 2022

Unfortunately I have no experience with FLTK whatsoever, but if you would have a minimal code that sets up a window with raw OpenGL, I could continue from there.

@pdhahn
Copy link
Author

pdhahn commented Apr 20, 2022

In general, in FLTK (1.4), the approach is to subclass the Fl_Gl_Window class for your own OpenGL window class code. If you download/install FLTK from github, it has a test application called test/cube.cxx that is not exactly trivial, but straightforward. It implements a class called cube_box that inherits Fl_Gl_Window which displays some moving cubes. Here's a skeletal snippet of the class declaration...

#include <FL/Fl_Gl_Window.H>
#include <FL/gl.h>
class cube_box : public Fl_Gl_Window {
  void draw();
  int handle(int);
public:
  double lasttime;
  int wire;
  double size;
  double speed;
  cube_box(int x,int y,int w,int h,const char *l=0) : Fl_Gl_Window(x,y,w,h,l) {
    lasttime = 0.0;
    box(FL_DOWN_FRAME);
  }
};

In a nutshell, you must override the inherited, virtual draw() method to include your own OpenGL drawing code (be sure to call the base class draw()!). The required OpenGL initialization is performed when(ever) the Fl_Gl_Window class's valid() method returns false. You can override the virtual handle() method to respond to events (mouse,keyboard) as desired (again, be sure to call the base class's handle() before returning).

As for the main(), in general, you create an instance of your derived window class, add any other FLTK widgets needed, call the window's inherited show() method, then finally run by calling the FLTK function Fl::run() (which only returns upon exit, which can happen with the Escape char press). Or (alternatively), as in this test code's case, repeatedly calling Fl::check() or Fl::wait() in an infinite loop to make FLTK incrementally update the display, process events, etc. These methods return immediately after doing their work, with a return code of 0 meaning "exit", else keep looping.

However, note in this test code FYI, it's a bit more complex because they create a container window (instance of Fl_Window) into which is added various widgets including two instances of the cube_box class (as sub-windows under the container window). That's all in accordance with the flexibility provided by FLTK, but of course you do not need all that stuff for your bootstrap.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants