OpenGL in Normal FLTK Windows

19 views
Skip to first unread message

holm.h...@gmail.com

unread,
Jan 16, 2022, 12:33:39 PM1/16/22
to fltk.general

Hi,

Do anyone have an example code on how to use OpenGL in a normal FLTK window?
Thinking of calling  gl_start(); and gl_finish();
Can not find in example/ or test/ directory. Neigther on "fltk cheat".

Best regards
Håvard

Manolo

unread,
Jan 16, 2022, 1:34:37 PM1/16/22
to fltk.general
Here a small example program of that.
Also, be sure to read :

=================================
#include <FL/Fl_Window.H>
#include <FL/Fl.H>
#include <FL/fl_draw.H>
#include <FL/gl.h>

class test : public Fl_Widget {
public:
  test(int x, int y, int w, int h);
  void draw();
};

test::test(int x, int y, int w, int h) : Fl_Widget(x,y,w,h)
{
  ;
}

void test::draw()
{
  fl_color(FL_WHITE);
  fl_font(0, 30);
  fl_draw("LABEL", 0, 50);

  gl_start();
  gl_color(FL_YELLOW);
  gl_rectf(0,0,w(),h()-100);
  gl_color(FL_RED);
  gl_rectf(10,10,100,100);
  gl_color(FL_BLACK);
  gl_font(0,24);
  const char *text = "Text€ç§δεфисвенг 新東";
  //const char *text = "TextpgW";
  int w, h;
  gl_measure(text, w, h);
  gl_rect(20, 20-fl_descent(), w, h);
  gl_draw(text, 20, 20);
  gl_draw("next");
  gl_finish();
}

int main(int argc, char **argv)
{
  Fl::gl_visual(FL_RGB);
  Fl_Window *mainwin = new Fl_Window(400, 400, "main");
  new test(0,0,400,400);
  mainwin->end();
  mainwin->resizable(mainwin);
  mainwin->show();
  return Fl::run();
}


Reply all
Reply to author
Forward
0 new messages