FLTK logo

STR #3257

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 #3257

Application:FLTK Library
Status:1 - Closed w/Resolution
Priority:1 - Request for Enhancement, e.g. asking for a feature
Scope:2 - Specific to an operating system
Subsystem:MacOS
Summary:How to create OpenGL context > 2.1 on OS X, with C++
Version:1.3-feature
Created By:bsdooby
Assigned To:manolo
Fix Version:1.3.4 (SVN: v10876)
Update Notification:

Receive EMails Don't Receive EMails

Trouble Report Files:

No files


Trouble Report Comments:


Name/Time/Date Text  
 
#1 bsdooby
01:45 Sep 03, 2015
Question:
Is there a possibility to programmatically create an
OpenGL context > 2.1 (say 4.1) on OS X (10.10.5, Yosemite)
with FLTK and C++?

If not, what is the preferred way doing it?
I do not want to resort to using Objective-C in my code
(my application is based on C++).

What I tried:
Patching the source in Fl_cocoa.mm, replacing line 2741 with
"attribs[n++] = NSOpenGLProfileVersion3_2Core"

This yields the highest available OpenGL Core Profile
in the draw() call of my derived Fl_Gl_Window. However,
further calls to OpenGL commands (glBindProgram and friends)
yield OpenGL errors (invalid value, invalid operations etc.)
and nothing is drawn. It seems as if the context is not valid.
 
 
#2 bsdooby
01:47 Sep 03, 2015
I forgot to add: I create the context using the CGL backend of OS X:
...
#ifdef __APPLE__
  8     CGLPixelFormatAttribute attribs[13] = {
  9         kCGLPFAOpenGLProfile, (CGLPixelFormatAttribute)kCGLOGLPVersion_3_2_Core, // This sets the context to the highest available (?)
 10         kCGLPFAColorSize,     (CGLPixelFormatAttribute)24,
 11         kCGLPFAAlphaSize,     (CGLPixelFormatAttribute)8,
 12         kCGLPFAAccelerated,
 13         kCGLPFADoubleBuffer,
 14         kCGLPFASampleBuffers, (CGLPixelFormatAttribute)1,
 15         kCGLPFASamples,       (CGLPixelFormatAttribute)4,
 16         (CGLPixelFormatAttribute)0
 17     };
 18
 19     CGLPixelFormatObj pix;
 20     GLint npix;
 21     CGLChoosePixelFormat(attribs, &pix, &npix);
 22
 23     CGLContextObj ctx;
 24     CGLCreateContext(pix, 0, &ctx);
 25
 26     CGLSetCurrentContext(ctx);
 27     CGLLockContext(ctx);
 28 #endif
...
 
 
#3 AlbrechtS
02:39 Sep 09, 2015
STR #3198 seems to show a possible solution for Mac OS X. Does this work for you?

http://www.fltk.org/str.php?L3198
 
 
#4 bsdooby
13:14 Sep 20, 2015
It's been a while: As we just use FLTK's GLUT (without a dedicated FLTK render window and without glew) I added a "patch" to the FLTK source from the Git repo (https://github.com/IngwiePhoenix/FLTK.git) to enable either the Core or the Legacy mode via a global variable on OS X (this was already explained more or less above). The native OpenGL context request was dropped (see also above). Further, the inclusion of the FLTK GLUT headers instead of the OS X GLUT headers was done. The result is a correct Core or Legacy mode. This is more or less the same as using the approach explained in the thread http://www.fltk.org/str.php?L3198. I know that my hack is not the greatest piece of software ever written, but right now it just gives us exactly the features we want (on OS X). Thank you, Albrecht, for your support and the hint   of the other thread!  
 
#5 bsdooby
14:06 Sep 20, 2015
CORRECTION: Of course we do need glew on OS X, as we only want to include FL/glut.H (instead of all the OpenGL/{gl.h, gl3.h, glu.h, glext.h} includes).

8<============================================
// glut init calls
...
 
// my patched custom OS X FLTK 
#ifdef __APPLE__
 _fl_mac_CGLContext = _FL_CGLCONTEXT_CORE;
 //_fl_mac_CGLContext = _FL_CGLCONTEXT_LEGACY;
#endif
    
glutCreateWindow("Example");
    
glewExperimental = GL_TRUE;
if(glewInit() != GLEW_OK) { return -1; }
...
8<============================================

I hope this makes any sense...
 
 
#6 manolo
22:25 Sep 20, 2015
Would opengl3.patch from
http://www.fltk.org/str.php?L3198
work for you? In particular what about the need for glew?
 
 
#7 bsdooby
07:29 Sep 22, 2015
For our students we need to provide OS X, Windows and Linux "compatible" OpenGL source code. FLTK for OS X is patched with my hack and we ship it exclusively to these students using OS X. Like this, and thanks to glew, we are able to only have, at one point during initalization, an Apple specific call (enabling the patch, wrapped in a preproc. define). Furthermore, our application is purely FLTK GLUT based (no FLTK render window).

I will, however, apply your patch and give it a try.
I prefer the official patches anyway ;)
 
 
#8 bsdooby
06:17 Sep 24, 2015
Your patch works like a charm ;). And I consider it using your
solution instead of mine (much better code, clear interface).

BUT: applying the patch with 'patch -p0 < opengl3.patch' yields one error:

patching file FL/Enumerations.H
patching file FL/Fl_Gl_Window.H
Hunk #3 FAILED at 193.
1 out of 3 hunks FAILED -- saving rejects to file FL/Fl_Gl_Window.H.rej
patching file FL/gl.h
patching file documentation/src/opengl.dox
patching file examples/OpenGL3-glut-test.cxx
patching file examples/OpenGL3test.cxx
patching file src/Fl_cocoa.mm

Is this "normal"?
 
 
#9 manolo
13:52 Sep 24, 2015
It's certainly not normal that the patch does not apply smoothly.
In any case, the patch only concerns documentation for file
FL/Fl_Gl_Window.H, so the code will be OK.

I would suggest you apply manually that part of the patch.
 
 
#10 bsdooby
14:29 Sep 24, 2015
That's what I did, finally. So no big deal. Thanks again for your support and the fix. I hope this will make it into the official FLTK release soon (?).  
 
#11 manolo
08:15 Sep 27, 2015
@bsdooby:  For the patch to enter the FLTK code base,
it would be very helpful if you could provide feedback about your
experience with the patched FLTK:

- is the code cross-platform (linux/Unix, MSWindows, Mac OS X)?

- is the code OK both for old-style (OpenGL 1) and
new style (OpenGL 3 and  later) OpenGL programming?

- is it correct,  for the linux and the MSWindows platforms,
to state that FLTK-created OpenGL contexts are for the
highest OpenGL version supported by the hardware, and are ALSO
compatible with earlier OpenGL versions?
(This is clearly wrong for the Mac OS platform).

- Are there cases where this could be wrong, say, hardware for
OpenGL 3.1 ?

- in my hands, calling the GLEW library on the Mac OS platform
prevents from using OpenGL 3 functions. Can you confirm that?

- how is it possible to install and link with the GLEW library
on the MSWindows platform with other development environments
than Mingw?
 
 
#12 bsdooby
05:56 Oct 05, 2015
As we use FLTK for our OpenGL class (students are allowed to use all three major operating systems), this might be a good way to test the
patched FLTK version. In this class exercises comprise Legacy as well
as Core OpenGL contexts.

The students on Windows are all using the Microsoft toolchain.
I will test MinGW myself and report any issues we encounter.
Stay tuned.
 
 
#13 manolo
01:46 Oct 27, 2015
Fixed in Subversion repository.

Follow detailed instructions given in the documentation:
FLTK programming manual
  Using OpenGL
    Using OpenGL 3.0 (or higher versions)
 
     

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'.