default Fl::gl_visual

27 views
Skip to first unread message

danielc...@gmail.com

unread,
Jul 3, 2025, 5:17:30 PMJul 3
to fltk.general
Hi,

How to get the default before setting Fl::gl_visual(...)?

I'm testing in windows, linux, and raspberry pi, they work with different settings.

in linux Fl::gl_visual(FL_OPENGL3 |FL_RGB | FL_DOUBLE | FL_DEPTH | FL_STENCIL | FL_MULTISAMPLE);
works but in arm64 have to remove that for it to work.

thanks

Gonzalo Garramuño

unread,
Jul 3, 2025, 6:12:59 PMJul 3
to fltkg...@googlegroups.com

If you will be drawing with opengl, the usual approach is to use an Fl_Gl_Window with mode() set to those flags.  That has been tested more thoroughly and it does work on arm64 (macOS at least as several developers use that).

Only if you want to use gl calls from within normal FLTK Windows you would need to actually call Fl::gl_visual. 

-- 
ggar...@gmail.com

Daniel Chanfana

unread,
Jul 3, 2025, 7:52:33 PMJul 3
to fltkg...@googlegroups.com
yes but is it possible to get the default mode somewhere?
or get at runtime what the hardware can do?

I tried this function but it dont work, returns allways the first.

bool set_best_gl_mode() {
    struct GLVisualOption {
        int flags;
        const char* name;
    };
    std::vector<GLVisualOption> try_gl_visuals = {
        { FL_OPENGL3 | FL_RGB | FL_DOUBLE | FL_DEPTH | FL_STENCIL | FL_MULTISAMPLE, "GL3 + all" },
        { FL_OPENGL3 | FL_RGB | FL_DOUBLE | FL_DEPTH | FL_STENCIL, "GL3 + stencil" },
        { FL_OPENGL3 | FL_RGB | FL_DOUBLE | FL_DEPTH, "GL3 + depth" },
        { FL_RGB | FL_DOUBLE | FL_DEPTH | FL_STENCIL | FL_MULTISAMPLE, "GL2 + all" },
        { FL_RGB | FL_DOUBLE | FL_DEPTH | FL_STENCIL, "GL2 + stencil" },
        { FL_RGB | FL_DOUBLE | FL_DEPTH, "GL2 + depth" },
        { FL_RGB | FL_DOUBLE, "GL2 basic" },
        { 0, "Default system visual" }
    };

    static Fl_Gl_Window test(0, 0);  // dummy window for probing

    // First pass: high_res_GL = 1 (preferred)
        Fl::use_high_res_GL(1);
    for (auto& visual : try_gl_visuals) {
        Fl::gl_visual(visual.flags);
        if (test.can_do()) {
            std::cout << "GL visual: " << visual.name
                      << " (flags: " << visual.flags
                      << "), high_res_GL = 1\n";
            return true;
        }
    }

    // Fallback pass: high_res_GL = 0
        Fl::use_high_res_GL(0);
    for (auto& visual : try_gl_visuals) {
        Fl::gl_visual(visual.flags);
        if (test.can_do()) {
            std::cout << "GL visual: " << visual.name
                      << " (flags: " << visual.flags
                      << "), high_res_GL = 0\n";
            return true;
        }
    }

    std::cerr << "No compatible GL visual found (even without high_res_GL).\n";
    return false;
}


--
You received this message because you are subscribed to a topic in the Google Groups "fltk.general" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/fltkgeneral/QvxUybVQhgk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to fltkgeneral...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/fltkgeneral/2f93752c-9fbd-4c98-9f15-7339309215cd%40gmail.com.

Manolo

unread,
Jul 4, 2025, 3:10:00 AMJul 4
to fltk.general
The default mode FLTK uses for Fl_Gl_Window's is: FL_RGB|FL_DOUBLE|FL_DEPTH.

danielc...@gmail.com

unread,
Jul 4, 2025, 10:59:55 AMJul 4
to fltk.general
And how to know if hardware supports FL_OPENGL3 ?

imm

unread,
Jul 4, 2025, 11:13:02 AMJul 4
to General FLTK
On Fri, 4 Jul 2025, 15:59 daniel wrote:
And how to know if hardware supports FL_OPENGL3 ?

You probably need a GL extension wrangler like GLEW or equivalent, that makes it much easier to determine what GL capabilities a system has and to utilise them.

--
Ian
From my Fairphone FP3
   


Manolo

unread,
Jul 4, 2025, 12:24:11 PMJul 4
to fltk.general
Le vendredi 4 juillet 2025 à 16:59:55 UTC+2, danielc...@gmail.com a écrit :
And how to know if hardware supports FL_OPENGL3 ?

FLTK assumes that FL_OPENGL3 is always possible on the platforms it supports
(Linux, Unix, Windows, macOS) except for macOS versions earlier than 10.7. 
No FLTK user ever disproved that.

Manolo

unread,
Jul 5, 2025, 2:08:44 AMJul 5
to fltk.general

Le vendredi 4 juillet 2025 à 16:59:55 UTC+2, danielc...@gmail.com a écrit :
And how to know if hardware supports FL_OPENGL3 ?

This is how to do that:
after having called Fl_Gl_Window::make_current(),
call 
  glGetString(GL_VERSION); 
that function returns a const uchar * that describes the GL version in use.
In my case, I obtain this
"4.5 (Compatibility Profile) Mesa 25.0.5-2"
You want the first number to be ≥ 3.0

Reply all
Reply to author
Forward
0 new messages