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
FLTK 1.3.9 gl_draw() problems on M1 Macs #947
Comments
Too late at night to look at it right now. I have a MacBook Pro M1 here and can test stuff if you could post a compilable program here that show the bug. In case you are using an OpenGL 3 context: With the M1, OpenGL can only be either OGL1 or OGL3. The OGL driver is currently only available in OGL1, and gl_draw is one of the calls affected. Manolo is doing some magic trickery here to switch between 1 and 3. Lastly to my greatest disappointment, OpenGL on macOS is deprecated, and luckily still available, but I don't expect much driver fixing if this is and OS issue. |
Hi Matthias, I'm not sure about GL Context. Perhaps FLTK sets it? |
OK. I confirm that with FLTK 1.3.9 text in red color is invisible. I add that only the blue component of colors is visible, green is invisible too. @MatthiasWM Can you explain where does the GL code of 1.3.9 use the blue component as mask to create the textures used to draw text in a GL scene? That is either in @ptepa Can you use FLTK 1.4 under macOS instead of 1.3.9? That would solve "PROBLEM 2". |
That problem looks very much either
because |
Where can I get the configure file for this fltk-master? (I tried and failed to get/build autoconf, gnulib-tool, etc... and the fltk-1.3.9 configure file did not work because there are no FL and GL subdirectories) |
We recommend to use CMake which doesn't require If this doesn't work for you, you can either install autoconf with homebrew (if that's feasible) or, as documented in README.macOS.md:
OTOH you can download a current FLTK 1.4 snapshot from our download page which contains the configure script and should build w/o autoconf. Edit: you could also download the snapshot, expand it, and copy only the configure script to your Git/fltk/master working directory. |
I believe the cure is to make this change in file Replace these 3 lines #498ff
by this single statement: @ptepa Can you confirm this fix? |
Manolo, I fund the bug and I am fixing it now. It's a bit more involved than just that. The order of color components is wrong. Try to put an emoji into the text and you will see what I mean. No worries though, I m almost done for 1.3. |
Also, the cache textures must already be colored and marked as such, and the alpha channel is rendered later when compositing. Sorry, I should have assigned the bug to me sooner. |
Thanks. |
For 1.3, this is fixed in 20138be . To test, try various RGBA values, and for extended testing, add an Emoji to the text. Note that the emoji color is static despite different RGB values, but does render with the requested alpha. Now in 1.4, I assume that the underlying bug is also there, but the fix may be different. I'll be back. |
@ManoloFLTK Ok, so looking at 1.4, you use the more resource efficient alpha channel for rendering text, which is great for 99% of all cases. In 1.3, you used and RGBA buffer and allowed rendering of colorful Emojis. Question: would you want to leave alpha channel rendering as is in 1.4 and we are done, or would you want me to adapt the 1.3 code which needs 4 times more cache and is probably rarely used - but correct if fonts use color? |
@MatthiasWM Added later: I see that, under Windows, emojis draw with colors in some contexts (e.g., the search box of the file manager window) but in monocolor form in other contexts (e.g., NotePad++, terminal, when put in a filename). I see also that FLTK 1.4 presently renders emojis in grey-colored GL text this way: which is still something else (and probably suboptimal for 1.4) than what Windows does when it doesn't render them colorful (an emoji-containing filename is shown here): Being ignorant about GL, I would prefer to let you, please, decide what is most likely to be expected by users for text on a GL scene. |
Well, your OpenGL ignorance implement some very cool code for text rendering. Thank you for that. I used OpenGL 1 in my old job very long ago, so this is relatively easy for me. But I must really learn OpenGL 3, now that 4 is even out (sigh). macOS is very good about rendering emojis. X11 was never prepared for colored text, I assume, and it's probably similar with win32. FLTK's handling of Unicode is not perfect either, so for now, I think we just leave it as is. |
Ian, really, is the author of the code that uses textures to draw GL text. I would believe this issue may be closed now. |
Closing this as fixed. It fixes the issues with 1.3. For 1.4, the single color approach seems fine for now because neither Windows nor X11 seem to support colored fonts anyway, so it would be a waste of resources. Not sure about Wayland. |
Describe the bug
On my M1 Mac, gl_draw sometimes crashes.
After my HACK to avoid this crash, it fails to display red text or displays it with very low alpha (nearly invisible).
To Reproduce
PROBLEM 1: gl_draw() sometimes crashes at '->as_gl_window()' with BAD_ADDRESS
but niether Fl_Window::current() nor 'as_gl_window' are null.
Here's my HACK that avoids these crashes, file gl_draw.cxx:
static void gl_draw_textures(const char* str, int n)
{
// BUG 1: 2024-03-28 ->as_gl_window() sometimes crashes with BAD_ADDRESS on M1 Macs!
// BUG 2: on M1 Macs text labels sometimes appear with very low alpha (opacity)!
#if defined( APPLE ) && defined( arm64 )
Fl_Gl_Window *gwin = 0; // HACK
#else
Fl_Gl_Window *gwin = Fl_Window::current()->as_gl_window();
#endif
PROBLEM 2: (after above HACK workaround), gl_draw() of red or green text does not show (or has very low alpha).
Steps to reproduce the behavior:
Edit file test/cube.cxx, search for gl_draw and add these outdented HACK test lines before it:
// TEMP HACK: try uncommenting one of the test lines below.
//glColor4f( 1.0, 0.0, 0.0, 1.0 ); // BUG: red text does not show.
//glColor4f( 0.0, 1.0, 0.0, 1.0 ); // BUG: green text does not show.
glColor4f( 0.0, 0.0, 1.0, 1.0 ); // blue text does show. WTF?
gl_draw(wire ? "Cube: wire" : "Cube: flat", -4.5f, -4.5f );
make ;./cube
Note that it correctly displays blue text.
Comment-out the line that sets color to blue and uncomment the line that
sets color to red then recompile and rerun.
make ; ./cube
Red text does not appear.
Tests show that white, gray or blue text appears but not red or green text.
Expected behavior
It should display any color text with alpha = 1.0.
Screenshots
FLTK Version
FLTK Configure / Build Options
./configure --enable-debug --enable-localjpeg --enable-localpng --enable-localzlib
make
Operating System / Platform:
MacBookAir M1 (arm64) processor, Apple GPU, MacOS 12.5.1, OpenGL 2.1, g++ = Apple clang version 14.0.0.
Additional context
All Apple Macs use textures for text.
FLTK 1.3.9 works correctly on my Intel (x86_64) Mac, ATI Radeon Pro GPU, OpenGL 2.1, g++ = Apple LLVM version 9.0.0.
The text was updated successfully, but these errors were encountered: