FLTK + OpenGL3 + 2d text

68 views
Skip to first unread message

Kaushik Ghose

unread,
Dec 12, 2017, 11:47:56 AM12/12/17
to fltk.general
Hi Folks,

I've been banging my head on this for a few weeks and gotten to the point where I wonder if I should use a different framework (I really don't want to). There is probably a simple solution and my inexperience with OpenGL is the main blocker. Here is the problem:

I've been happily using FLTK and OpenGL 3+ to draw stuff in a subclassed Fl_Gl_Window. I use very basic shaders to draw what are essentially wireframes.

Now, I want to annotate some parts of this 3D world with text. I'm happy to do the transforms needed to convert the 3D location to a 2D projection (as we need for billboarding) but I can not text to appear on the Fl_Gl_window.

I'm using the following construct

void draw() {
  //set up 3D projection and do 3D drawing using shaders
  ortho();
  gl_color( FL_WHITE );
  gl_draw("HI", 100, 100);
}

I'm expecting HI to appear at (100,100) but no joy. Could some kind soul point me in the right direction? Thanks!

Greg Ercolano

unread,
Dec 12, 2017, 12:01:48 PM12/12/17
to fltkg...@googlegroups.com
On 12/12/17 06:45, Kaushik Ghose wrote:
> void draw() {
> //set up 3D projection and do 3D drawing using shaders
> ortho();
> gl_color( FL_WHITE );
> gl_draw("HI", 100, 100);
> }
>
> I'm expecting HI to appear at (100,100) but no joy.

Do you set the font somewhere? e.g.
gl_font(1, 12);

Perhaps try this test code:
http://seriss.com/people/erco/fltk/#OpenGlTextOn3D
While it's not opengl3, it uses the same function.

Kaushik Ghose

unread,
Dec 12, 2017, 11:32:34 PM12/12/17
to fltk.general

        Do you set the font somewhere? e.g.
        gl_font(1, 12);

        Perhaps try this test code:
        http://seriss.com/people/erco/fltk/#OpenGlTextOn3D
        While it's not opengl3, it uses the same function.

Hi, Thanks for your response. I actually ran into that example early on. I'm on macOS and this method does not work probably because using core profile precludes using the fixed function pipeline.

My question boils down to - does any of gl_draw gl_rect etc. work in core profile?

Thanks!

Greg Ercolano

unread,
Dec 12, 2017, 11:42:52 PM12/12/17
to fltkg...@googlegroups.com
On 12/12/17 19:53, Kaushik Ghose wrote:
>
> Do you set the font somewhere? e.g.
> gl_font(1, 12);
>
> Perhaps try this test code:
> http://seriss.com/people/erco/fltk/#OpenGlTextOn3D <http://seriss.com/people/erco/fltk/#OpenGlTextOn3D>
> While it's not opengl3, it uses the same function.
>
> Hi, Thanks for your response. I actually ran into that example early on.
> I'm on macOS and this method does not work probably because using core
> profile precludes using the fixed function pipeline.
>
> My question boils down to - does any of gl_draw gl_rect etc. work in core profile?

If setting the font with gl_font() isn't the issue, I probably
can't help, as I don't know much at all about OpenGL3, or what
a "core profile" is.

I should leave this for others to respond.

The only other thing I can think of is make sure you're using
the latest FLTK (1.4.x from SVN, or the latest 1.4.x snapshot),
as I think Manolo's made tweaks to support OpenGL3 fairly recently in 1.4.

Perhaps our examples/OpenGL3test.cxx should include showing
how to draw text, if possible.

Manolo

unread,
Dec 13, 2017, 3:40:57 AM12/13/17
to fltk.general
Under MacOS, OpenGL can be used either according to the fixed function pipeline (that is, OpenGL versions 1 and 2)
or with shaders and program pipelines (a.k.a., core profile), but mixing both modes is impossible. That's why gl_draw()
and gl_rect() don't work in MacOS when using OpenGL 3: both use glBegin()/glEnd() which are not supported by the core profile.
The present FLTK text drawing functions are therefore ineffective under MacOS when used in core profile mode.
It's however entirely possible to use OpenGL in compatibilty profile and to draw text. FLTK's OpenGL text support
under MacOS+compatibility mode is in fact better than it's on Windows and X11 because all of Unicode and all fonts
can be used.

Here is an explanation taken from the OpenGL documentation at
Platform Issue (MacOSX): When MacOSX 10.7 introduced support for OpenGL beyond 2.1, they also introduced the core/compatibility dichotomy. However, they did not introduce support for the compatibility profile itself. Instead, MacOSX gives you a choice: core profile for versions 3.2 or higher, or just version 2.1. There is no way to get access to features after 2.1 and still access the Fixed Function Pipeline.


Kaushik Ghose

unread,
Dec 13, 2017, 8:37:03 AM12/13/17
to fltk.general
Hi,


On Wednesday, December 13, 2017 at 3:40:57 AM UTC-5, Manolo wrote:

Under MacOS, OpenGL can be used either according to the fixed function pipeline (that is, OpenGL versions 1 and 2)
or with shaders and program pipelines (a.k.a., core profile), but mixing both modes is impossible. That's why gl_draw()
and gl_rect() don't work in MacOS when using OpenGL 3: both use glBegin()/glEnd() which are not supported by the core profile.
The present FLTK text drawing functions are therefore ineffective under MacOS when used in core profile mode.
It's however entirely possible to use OpenGL in compatibilty profile and to draw text. FLTK's OpenGL text support
under MacOS+compatibility mode is in fact better than it's on Windows and X11 because all of Unicode and all fonts
can be used.

Here is an explanation taken from the OpenGL documentation at
Platform Issue (MacOSX): When MacOSX 10.7 introduced support for OpenGL beyond 2.1, they also introduced the core/compatibility dichotomy. However, they did not introduce support for the compatibility profile itself. Instead, MacOSX gives you a choice: core profile for versions 3.2 or higher, or just version 2.1. There is no way to get access to features after 2.1 and still access the Fixed Function Pipeline.


Thanks for you responses! It's new code, so I'm trying to use more modern OpenGL. I think, unfortunately, I'll have to look for a different framework that will allow text even with later OpenGL versions. Would you have any suggestions. I've read about DIY using say freetype and textures, but my main work with the project is different and I'd rather not get bogged down with that level of implementation.

Thanks!
 

Manolo

unread,
Dec 14, 2017, 3:24:37 AM12/14/17
to fltk.general
You may refer to this document describing how to draw text in OpenGL3:

In FLTK 1.3.4, source file src/gl_draw.cxx contains the MacOS implementation of text drawing in the form of textures
written to the GL scene according to the fixed pipeline model. Function compute_texture() computes a texture
for a string and memorizes it in a FIFO list of textures. Function display_texture(int rank) draws the texture at index
rank in the FIFO of textures. Function gl_draw_textures(string, l) pilots the use of textures determining if the string
is new (a new texture is to be computed) and which texture needs to be drawn.

It's may be possible to reuse compute_texture() where most MacOS-specifics are located, and devise what would
correspond to display_texture() in the OpenGL3 logic?

Kaushik Ghose

unread,
Dec 14, 2017, 6:15:05 AM12/14/17
to fltkg...@googlegroups.com
Hi,

On Thu, Dec 14, 2017 at 3:24 AM, Manolo <manol...@gmail.com> wrote:

You may refer to this document describing how to draw text in OpenGL3:

In FLTK 1.3.4, source file src/gl_draw.cxx contains the MacOS implementation of text drawing in the form of textures
written to the GL scene according to the fixed pipeline model. Function compute_texture() computes a texture
for a string and memorizes it in a FIFO list of textures. Function display_texture(int rank) draws the texture at index
rank in the FIFO of textures. Function gl_draw_textures(string, l) pilots the use of textures determining if the string
is new (a new texture is to be computed) and which texture needs to be drawn.

It's may be possible to reuse compute_texture() where most MacOS-specifics are located, and devise what would
correspond to display_texture() in the OpenGL3 logic?

Ok, I will try this. I see that you mention 1.3.4 and not 1.4 I have been using 1.3.4 but if I work on this feature should I do it on 1.4?
Also I see that size_range(int, int) has vanished from 1.4. What happened to it?

Thanks!
-Kaushik


Manolo

unread,
Dec 14, 2017, 8:24:50 AM12/14/17
to fltk.general
Yes, as a developer it's preferable to work relatively to FLTK 1.4.
Function gl_draw_textures() of 1.3 is named Fl_Cocoa_Gl_Window_Driver::draw_string() in 1.4.
Differences between 1.3 and 1.4 consist in a clear separation of the platform-specific and
platform-independent parts. But the implementation itself is unchanged.

The public API to
Fl_Window::size_range (int minw, int minh, int maxw=0, int maxh=0, int dw=0, int dh=0, int aspect=0)
is unchanged between 1.3 and 1.4. In both cases default argument values allow to call
it with only 2 arguments, or with more.
Do you mean something else?

In general terms, 1.4 has exactly the same public API as 1.3, plus a few more things, such as
support for SVG images and for GUI rescaling with ctrl/+/-/0/ under X11 and WIN32.

Kaushik Ghose

unread,
Dec 14, 2017, 10:17:57 AM12/14/17
to fltkg...@googlegroups.com
Hi,

Thanks for the reply

On Thu, Dec 14, 2017 at 8:24 AM, Manolo <manol...@gmail.com> wrote:


Yes, as a developer it's preferable to work relatively to FLTK 1.4.
Function gl_draw_textures() of 1.3 is named Fl_Cocoa_Gl_Window_Driver::draw_string() in 1.4.
Differences between 1.3 and 1.4 consist in a clear separation of the platform-specific and
platform-independent parts. But the implementation itself is unchanged.


Ok, I will move to 1.4 and work on getting text working with OpenGL3+

 
The public API to
Fl_Window::size_range (int minw, int minh, int maxw=0, int maxh=0, int dw=0, int dh=0, int aspect=0)
is unchanged between 1.3 and 1.4. In both cases default argument values allow to call
it with only 2 arguments, or with more.
Do you mean something else?


When I tried to use FLTK 1.4 with my application which subclasses Fl_Gl_Window I get

Undefined symbols for architecture x86_64:

  "Fl_Window::size_range(int, int, int, int, int, int, int)", referenced from:

      sim::Display::Display(sim::Simulator&, int, int, char*) in display.cpp.o

ld: symbol(s) not found for architecture x86_64


I call size_range(400, 400) in one place

This error does not appear when I use FLTK 1.3

Thanks!
-Kaushik

Albrecht Schlosser

unread,
Dec 14, 2017, 10:48:52 AM12/14/17
to fltkg...@googlegroups.com
On 14.12.2017 16:17 Kaushik Ghose wrote:
>
> When I tried to use FLTK 1.4 with my application which subclasses
> Fl_Gl_Window I get
>
> Undefined symbols for architecture x86_64:
>
> "Fl_Window::size_range(int, int, int, int, int, int, int)", referenced from:
>
> sim::Display::Display(sim::Simulator&, int, int, char*) in display.cpp.o
>
> ld: symbol(s) not found for architecture x86_64
>
>
> I call size_range(400, 400) in one place
>
> This error does not appear when I use FLTK 1.3

This is strange. There are two test programs in FLTK that call
size_range(int w, int h) and both can be built on my Linux 64-bit system
(as well as under Windows 64-bit with MinGW and VS):

test/editor.cxx:946: w->size_range(300,200);
test/mandelbrot_ui.fl:17: code0 {o->size_range(220,220);}

The declaration in FL/Fl_Window.H is:

void size_range(int minw, int minh, int maxw=0, int maxh=0, int dw=0,
int dh=0, int aspect=0);

with 7 int's as in your error message.

Questions:

(1) what exactly is your build platform (OS and compiler versions)

(2) if you have both FLTK 1.3 and FLTK 1.4 on your system, can you
definitely rule out "cross contamination" of the two FLTK versions?

The problem may be that you have FLTK 1.3 installed in a system location
and FLTK 1.4 in a separate build directory and your compiler/linker find
different headers and libs from 1.3 and 1.4 so name mangling may cause
the undefined reference. If this is the case you should remove the
"installed" (i.e. system) version of FLTK 1.3 and try again. If this
works with 1.4, then build 1.3 yourself in a non-system location so you
can easily switch between 1.3 and 1.4. That's what we recommend and most
of the FLTK dev's are doing (including me).

Manolo

unread,
Dec 14, 2017, 11:01:15 AM12/14/17
to fltk.general


On Thursday, 14 December 2017 16:17:57 UTC+1, Kaushik Ghose wrote:
When I tried to use FLTK 1.4 with my application which subclasses Fl_Gl_Window I get

Undefined symbols for architecture x86_64:

  "Fl_Window::size_range(int, int, int, int, int, int, int)", referenced from:

      sim::Display::Display(sim::Simulator&, int, int, char*) in display.cpp.o

ld: symbol(s) not found for architecture x86_64


I call size_range(400, 400) in one place

This error does not appear when I use FLTK 1.3


It's most probaby what Albrecht suggests. I have added here a call to Fl_Window::size_range()
to file examples/OpenGL3test.cxx and there's no link error under MacOS.

Greg Ercolano

unread,
Dec 14, 2017, 12:08:47 PM12/14/17
to fltkg...@googlegroups.com
On 12/14/17 07:17, Kaushik Ghose wrote:
> When I tried to use FLTK 1.4 with my application which subclasses Fl_Gl_Window I get
>
> Undefined symbols for architecture x86_64:
> "Fl_Window::size_range(int, int, int, int, int, int, int)", referenced from:
> sim::Display::Display(sim::Simulator&, int, int, char*) in display.cpp.o
> ld: symbol(s) not found for architecture x86_64


I don't normally make an Fl_Gl_Window the top level window
so I don't usually call size_range() for Fl_Gl_Window.

Normally, I create an Fl_Window first and put the
Fl_Gl_Window inside that.

It's probably because I like to leave myself a way to add
FLTK widgets to the window if need be, making the Fl_Window
slightly larger than the GL window, and putting the FLTK
widgets in the space between.

But it seems to work to make Fl_Gl_Window a top level window.

I compiled this small app on both linux + OSX and it builds
OK with 1.4.x current using:

/path/to/your/fltk-1.4.x-svn/fltk-config --compile foo.cxx --use-gl

Does this build for you, or do you get an error about size_range()?

foo.cxx

Kaushik Ghose

unread,
Dec 14, 2017, 12:26:04 PM12/14/17
to fltkg...@googlegroups.com
Hi!

On Thu, Dec 14, 2017 at 11:01 AM, Manolo <manol...@gmail.com> wrote:


It's most probaby what Albrecht suggests. I have added here a call to Fl_Window::size_range()
to file examples/OpenGL3test.cxx and there's no link error under MacOS.


You and Albrecht are correct! I had originally installed FLTK  with brew. I uninstalled it and recreated my CMake caches and it compiles just fine now and I can verify that I can switch between the two versions with the same code. I just have to make clean inbetween.

Best
-Kaushik


Reply all
Reply to author
Forward
0 new messages