FLTK logo

STR #3198

FLTK matrix user chat room
(using Element browser app)   FLTK gitter user chat room   GitHub FLTK Project   FLTK News RSS Feed  
  FLTK Apps      FLTK Library      Forums      Links     Login 
 Home  |  Articles & FAQs  |  Bugs & Features  |  Documentation  |  Download  |  Screenshots  ]
 

Return to Bugs & Features | Roadmap 1.3 | SVN ⇄ GIT ]

STR #3198

Application:FLTK Library
Status:1 - Closed w/Resolution
Priority:1 - Request for Enhancement, e.g. asking for a feature
Scope:3 - Applies to all machines and operating systems
Subsystem:Core Library
Summary:Support opengl profiles
Version:1.3-feature
Created By:greg.ercolano
Assigned To:manolo
Fix Version:1.3.4 (SVN: v10876)
Update Notification:

Receive EMails Don't Receive EMails

Trouble Report Files:


Name/Time/Date Filename/Size  
 
#1 manolo
07:41 Sep 05, 2015
GL3.patch
5k
 
 
#2 manolo
03:42 Sep 06, 2015
GL3v2.patch
4k
 
 
#3 manolo
10:08 Sep 14, 2015
testGL3.cpp
6k
 
 
#4 manolo
10:19 Sep 16, 2015
testGL3_v2.cpp
7k
 
 
#5 manolo
23:31 Sep 18, 2015
testGL3-glut.cpp
6k
 
 
#6 manolo
13:09 Sep 20, 2015
opengl3.patch
19k
 
 
#7 manolo
08:53 Oct 25, 2015
opengl3_v2.patch
20k
 
     

Trouble Report Comments:


Name/Time/Date Text  
 
#1 greg.ercolano
03:10 Feb 26, 2015
OpenGL profiles allow access to new opengl 3.x features.

Currently FLTK's opengl support only allows access to the
older (2.1) API, blocking access to opengl 3.x and up features.

Patches needed.
 
 
#2 greg.ercolano
04:14 Feb 26, 2015
I've gathered some interesting links on the subject:

This seems to offer some general info on modern opengl programming
(3.x and up):
http://www.codeproject.com/Articles/771225/Learning-Modern-OpenGL

Apple OpenGL capabilities table:
https://developer.apple.com/opengl/capabilities/

Apple describes latest opengl support features (this is ever changing)
but currently mentions things like OpenCL support, shaders, GPU access:
https://developer.apple.com/opengl/

This book has a section on opengl 3.x and includes tutorials
and example code on opengl 3.x programming:
https://books.google.com/books?id=BLQdaTmbd-QC&pg=PT37&lpg=PT37&dq=opengl+profiles+freeglut&source=bl&ots=QZ7qlqWNYy&sig=OaD0RjIu0Lm1vthcG2jvf7jH2Zc&hl=en&sa=X&ei=ygbvVO_rJIbtoASvzoCAAw&ved=0CDIQ6AEwAzgK#v=onepage&q=opengl%20profiles%20freeglut&f=false

The last message in this thread mentions how (on Windows 7) to assign
particular graphics hardware to an exe, which I find 'interesting':
http://gamedev.stackexchange.com/questions/29852/unable-to-create-opengl-3-3-context-flags-0-profile-1

There's many references on the net to the "McKesson Tutorials",
so we should probably include some simple examples of these once
we support opengl profiles, to demonstrate new opengl features:
http://www.arcsynthesis.org/gltut/

This thread points to some other tutorials:
https://forum.beyond3d.com/threads/recommend-learning-modern-3d-graphics-programming-opengl-jason-l-mckesson.52998/


Qt's implementation of opengl profiles:
http://qt-project.org/wiki/How_to_use_OpenGL_Core_Profile_with_Qt

wxwidgets patches for opengl profiles:
http://trac.wxwidgets.org/ticket/16402
https://forums.wxwidgets.org/viewtopic.php?f=27&t=37085
 
 
#3 manolo
02:51 Apr 13, 2015
@Greg: I'd like to understand where is FLTK blocked
to use opengl 3.x features. I ask this because I have
put in Fl_X::mode_to_NSOpenGLPixelFormat() which is
called by Fl_Gl_Choice::find() to create a GL context
on Mac OS X:
      attribs[n++] = NSOpenGLPFAOpenGLProfile;
      attribs[n++] = NSOpenGLProfileVersionLegacy;
which requires a pre-OpenGL 3 profile.

Should I remove this so users of opengl 3
on the Mac are not blocked?
Should I leave it because the present FLTK API to GL is
restricted to opengl V2 anyhow?
 
 
#4 greg.ercolano
13:43 Apr 14, 2015
Hi Manolo,

I had my head around this briefly while investigating the thread that
started on fltk.general by Aditya and continued by Martin McDonough
on or around Feb 23 2015 with the thread subject: "Re: Choose OpenGL profile."

It seemed there were necessarily some mods to the opengl initialization flags
so that one could specify an opengl version# needed, and then you get back
what version is actually supported.

I think there was some mods needed to our initialization code
to support this, can't remember the details, but I believe this was covered
in the docs enclosed above.

Perhaps there are ways to add attributes after FLTK does its initialization
to let one access the features using the same code we have now.. if so, some
example code should be provided and 'blessed' by us, so end users know how to
enable opengl 3.x and up in applications.

I haven't myself done any tests yet with opengl 3.x, I've never needed it.
 
 
#5 manolo
08:01 Sep 05, 2015
It seems that with very minor changes it's possible to use
OpenGL v.3 with FLTK on the Mac platform. This is illustrated
by the attached GL3.patch containing
- 2 small changes in the FLTK library (in FL/gl.h and src/Fl_cocoa.mm)
- the source code of a very simple demo program smallGL3.cpp,
written without any OS-specific code.

The FLTK API needs an extra mode() flag asking for
a V3 GL context (the patch uses FL_FAKE_SINGLE*2 until a name for
this new flag is decided).

The draw() member function of the Fl_Gl_Window-derived custom class
is written with a somewhat different structure, to accomodate
for the GL V.3 logic.

Its handle() member function illustrates a very simple reaction
to mouse clicks.

No experiment yet with the MSWindows or Xlib platforms.

Can an OpenGL-savvy developer report whether this impression
holds for real-size programs?
 
 
#6 manolo
03:47 Sep 06, 2015
It's possible to get a V3 GL context on the Mac platform
with the present FLTK code, using the
    Fl_Gl_Window::mode(const int *a)
member function and an array of Mac-specific pixel format
attributes: see attached GL3v2.patch

It works only for single-buffered contexts, though.
 
 
#7 AlbrechtS
02:37 Sep 09, 2015
> It works only for single-buffered contexts, though.

I believe this was fixed in svn r 10854, wasn't it?
 
 
#8 AlbrechtS
02:40 Sep 09, 2015
Please see also related STR #3257.

http://www.fltk.org/str.php?L3257
 
 
#9 manolo
02:53 Sep 11, 2015
> It works only for single-buffered contexts, though.

This is no longer true with the current svn source code:
double-buffered OpenGL v3 contexts can be used.

Just call Fl_Gl_Window::mode(const int *a) as follows:

#ifdef __APPLE__
    static int array[] = { // equivalent to FL_RGB | FL_DOUBLE
      kCGLPFADoubleBuffer,
      kCGLPFAOpenGLProfile,
      kCGLOGLPVersion_3_2_Core,
      0
    };
    mode(array);
#endif

and use the last public FLTK source code
(Mac OS only, for now).
 
 
#10 manolo
10:32 Sep 14, 2015
It seems that it's possible to use OpenGL v3 (and more recent)
on the Linux/Unix platform with the standard FLTK 1.3
It is necessary to call the glewInit() function just before
beginning to draw, and therefore to link with libGLEW.

The attached testGL3.cpp is an example program that uses 
OpenGL v3 usable with Linux (and Mac OS).
It is compilable with :
g++ -c `fltk-config --cxxflags` testGL3.cpp
g++ testGL3.o -o testGL3 `fltk-config --use-gl --ldflags` -lGLEW

With debian/Ubuntu, this requires the libglew-dev package.

If this works satisfactorily, it would be possible to move the
glew_initialize() function from the user app to the FLTK library.
 
 
#11 manolo
10:17 Sep 16, 2015
It is possible to run OpenGL 3.0 (and above) programs using an unmodified FLTK library
version 1.3.0 and above (with a special requirement under Mac OS, see below), and to use a
single source code for all platforms.

1) on the Unix/Linux platform
It is necessary to install the glew library (available as a package in most distributions,
source code at http://glew.sourceforge.net/ if the package is not available).
The application program must call glewInit() (from the glew library) immediately
after having created the first OpenGL context. The attached example source code
(testGL3.cpp) shows one way to do that. Thus, the application program must be linked
to the glew library, in addition to usual libraries.
A complete build command is:
g++ testGL3.cpp `fltk-config --cxxflags` `fltk-config --use-gl --ldflags` -lGLEW -lGL -o testGL3

2) on the MSWindows platform
As in 1), it is sufficient to call glewInit() and to link to the glew library.
The source code of this library is at http://glew.sourceforge.net/ (make sure you download
the source, not the binaries, and the ZIP source, not the TGZ source).
Then build the library under mingw with:
make lib lib/libglew32.a

The application program can be built with:
GLEWPATH=../glew-1.13.0    (or any local variation of that)
g++ testGL3.cpp -I$GLEWPATH/include $GLEWPATH/lib/libglew32.a `fltk-config --cxxflags`\
 `fltk-config --use-gl --ldstaticflags` -lopengl32 -static-libgcc -static-libstdc++ -o testGL3
 
3) On the Mac OS X platform
With the current FLTK library, it is necessary to use the platform-specific
    Fl_Gl_Window::mode(const int *array)
member function to create an OpenGL 3 context. This requires to replace
the FLTK bitflags given as argument to the Fl_Gl_Window::mode(int flags) function, by their
equivalent under Mac OS. For example
    mode(FL_DOUBLE)
can be replaced by:
    static int array[] = {
      kCGLPFADoubleBuffer, // equivalent to FL_DOUBLE
      kCGLPFAOpenGLProfile, kCGLOGLPVersion_3_2_Core, // this pair asks for OpenGL V3.2 or more
      0 // marks end of array data
    };
    mode(array);
No special compilation or linking arguments are required under Mac OS. The current FLTK source
from the svn repository is required for double-buffered OpenGL contexts. Other contexts
can be obtained with FLTK 1.3 and above.

The attached testGL3.cpp program is a simple FLTK app that uses OpenGL 3.0 and runs on all
platforms, if compiled and linked as described above, provided the graphics card runs
OpenGL 3.0 or above (this condition is not met with MSWindows as guest OS under VirtualBox).
 
 
#12 manolo
23:25 Sep 16, 2015
There is a typo in testGL3_v2.cpp

Replace twice
  FL_MAJOR_VERSION*1000+FL_MINOR_VERSION*100+FL_PATCH_VERSION > 10304
by
  FL_MAJOR_VERSION*10000+FL_MINOR_VERSION*100+FL_PATCH_VERSION >= 10304
so the GL window uses the high resolution of Apple 'retina' displays.
 
 
#13 ianmacarthur
06:46 Sep 17, 2015
Just wanted to add that I often use glew on OSX too, so my build uses "the same" Makefile and sources on OSX/Linux/Win32.

So although Manolo's scheme has fewer dependencies on OSX, it is feasible to make the glew approach work for all 3 targets if folks choose to go that way.
 
 
#14 manolo
23:36 Sep 18, 2015
@Ian: does that mean that glew on the mac allows to get OpenGL 3+
contexts without having to call Fl_Gl_Window::mode(const int *array) ?
 
 
#15 manolo
23:43 Sep 18, 2015
The attached testGL3-glut.cpp illustrates how to use
OpenGL 3+ with FLTK's GLUT compatibility.
 
 
#16 manolo
13:10 Sep 20, 2015
Attached opengl3.patch is a proposal to make FLTK 1.3.4
compatible with OpenGL 3.
 
 
#17 manolo
02:03 Oct 27, 2015
On the X11/MSWindows platforms, the current FLTK code produces
contexts for the highest OpenGL version supported by the hardware
and for all lower versions. But access to OpenGL functions from
versions above 1.1 requires loading pointers to each such function
at runtime. FLTK 1.3.4 helps solving this by recommending
to use the GLEW library, and by showing where exactly the crucial
glewInit() call should be positionned in an OpenGL 3-using FLTK app.

On the Mac OS platform, FLTK 1.3.4 introduces a new item
of the Fl_Mode enumeration, FL_OPENGL3, that allows to create
OpenGL 3-compatible contexts (a.k.a. core contexts).

Added two new examples programs that show how to access OpenGL 3
in a cross-platform fashion, and how to combine OpenGL 3 and GLUT.

In the future, FLTK may decide to bundle the GLEW library source
code, and add operations for building this library on all relevant
platforms and with all supported building tools.
 
     

Return to Bugs & Features ]

 
 

Comments are owned by the poster. All other content is copyright 1998-2024 by Bill Spitzak and others. This project is hosted by The FLTK Team. Please report site problems to 'erco@seriss.com'.