[osg-users] OSG using OpenGL 3.2 in Mac OS X 10.7 (Lion)

242 views
Skip to first unread message

David Garcia

unread,
Mar 1, 2012, 3:27:10 PM3/1/12
to OpenSceneGraph Users

Hi,

I'm trying to compile an application in Mac that requires OpenGL 3.2. The app starts but fails when compiling the shaders and seems that, by default, OSG 3.0.1 compiles without OpenGL 3 support.

My next step was to recompile OSG with these settings:
/usr/bin/cmake -G Xcode -D OSG_COMPILE_FRAMEWORKS:BOOL=1 -D OSG_WINDOWING_SYSTEM:STRING=Cocoa -D OSG_BUILD_PLATFORM_IPHONE:BOOL=0 -D CMAKE_OSX_ARCHITECTURES:STRING=x86_64 -D OSG_DEFAULT_IMAGE_PLUGIN_FOR_OSX:STRING=imageio -D CMAKE_OSX_SYSROOT:STRING=/Developer/SDKs/MacOSX10.7.sdk -D OSG_GL3_AVAILABLE::BOOL=1  -D OSG_GL1_AVAILABLE::BOOL=0  -D OSG_GL2_AVAILABLE::BOOL=0 .

And seems that this time uses GL3 as it fails to compile with the error:
include/osg/GL:109:18: fatal error: 'GL3/gl3.h' file not found [2]

Then I add the missing includes to the path and I got a lot of errors:

/usr/include/GL3/gl3.h:85:9: warning: 'GL3_PROTOTYPES' macro redefined [2]
 #define GL3_PROTOTYPES
         ^
OpenSceneGraph/include/osg/GL:108:17: note: previous definition is here
         #define GL3_PROTOTYPES 1
                 ^
OpenSceneGraph/include/osg/GL:130:50: error: use of undeclared identifier 'glLoadMatrixf'; did you mean 'glLoadMatrix'? [3]
     inline void glLoadMatrix(const float* mat) { glLoadMatrixf(static_cast<const GLfloat*>(mat)); }
                                                  ^~~~~~~~~~~~~
                                                  glLoadMatrix
fix-it:"OpenSceneGraph/include/osg/GL":{130:50-130:63}:"glLoadMatrix"
OpenSceneGraph/include/osg/GL:130:17: note: 'glLoadMatrix' declared here [3]
     inline void glLoadMatrix(const float* mat) { glLoadMatrixf(static_cast<const GLfloat*>(mat)); }
                 ^
OpenSceneGraph/include/osg/GL:131:50: error: use of undeclared identifier 'glMultMatrixf'; did you mean 'glMultMatrix'? [3]
     inline void glMultMatrix(const float* mat) { glMultMatrixf(static_cast<const GLfloat*>(mat)); }
                                                  ^~~~~~~~~~~~~
                                                  glMultMatrix
… and more …

The question is now, can OpenGL 3.2 be use in Mac OS X? I'm doing something wrong?

Thanks a lot,

  David


Paul Martz

unread,
Mar 1, 2012, 3:45:05 PM3/1/12
to OpenSceneGraph Users
Since release 3.0.0, OSG has supported OpenGL versions >3.0 on Windows. On svn
trunk, see the example 'osgsimplegl3', especially the comment block at the end
of the file that discusses building OSG for GL3 use.

But to my knowledge no one has contributed code to make it work on OS X or
Linux. Please do so, if you need that functionality.
-Paul

> *
> *
>
>
> _______________________________________________
> osg-users mailing list
> osg-...@lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
_______________________________________________
osg-users mailing list
osg-...@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Stephan Huber

unread,
Mar 1, 2012, 5:19:16 PM3/1/12
to OpenSceneGraph Users
Hi,

Am 01.03.12 21:45, schrieb Paul Martz:


> But to my knowledge no one has contributed code to make it work on OS X
> or Linux. Please do so, if you need that functionality.

Besides the specific CMAKE_VARIABLES to get Open GL 3 support on OS X
GraphicsWindowCocoa needs some love when creating a graphics context.

Just setting the NSPixelFormat to

NSOpenGLPixelFormatAttribute pixelFormatAttributes[] =
{
NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersion3_2Core,
0
};

when compiling for Open GL 3 should help.

cheers,
Stephan

David Garcia

unread,
Mar 1, 2012, 7:11:02 PM3/1/12
to OpenSceneGraph Users

Hi,

I have been able to compile it for GL3 (both in 3.0 and 3.1 branches). I did the following modifications:

1) In GL I add two includes, three defines for missing symbols and an ifdef __APPLE__

    #if defined(OSG_GL3_AVAILABLE)
    #ifdef __APPLE__
#include <OpenGL/OpenGL.h> 
#include <OpenGL/gl3.h> 
#define GLint64EXT GLint64
#define GLuint64EXT GLuint64
#define GL_BGRA_EXT GL_BGRA
#else
      #include <GL3/gl3.h>
       #define GL3_PROTOTYPES 1
#endif

2) When compiling my original cmake line lacks extra defines (as seem in osgsimplegl3.cpp). The right line is:

/usr/bin/cmake -G Xcode -D OSG_COMPILE_FRAMEWORKS:BOOL=1 -D OSG_WINDOWING_SYSTEM:STRING=Cocoa \
-D OSG_BUILD_PLATFORM_IPHONE:BOOL=0 -D CMAKE_OSX_ARCHITECTURES:STRING=x86_64 \
-D OSG_DEFAULT_IMAGE_PLUGIN_FOR_OSX:STRING=imageio -D CMAKE_OSX_SYSROOT:STRING=/Developer/SDKs/MacOSX10.7.sdk  \
-D OSG_GL3_AVAILABLE::BOOL=1 -D OSG_GL1_AVAILABLE::BOOL=0 -D OSG_GL2_AVAILABLE::BOOL=0 \
-D OSG_GLES1_AVAILABLE::BOOL=0 -D OSG_GLES2_AVAILABLE::BOOL=0 \
-D OSG_GL_DISPLAYLISTS_AVAILABLE::BOOL=0 -D OSG_GL_FIXED_FUNCTION_AVAILABLE::BOOL=0 \
-D OSG_GL_MATRICES_AVAILABLE::BOOL=0 -D OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE::BOOL=0 \
-D OSG_GL_VERTEX_FUNCS_AVAILABLE::BOOL=0 .

3) Setting the pixel format as Stephan suggests.

In bool GraphicsWindowCocoa::realizeImplementation():
   attr[i++] = NSOpenGLPFAOpenGLProfile;
   attr[i++] = NSOpenGLProfileVersion3_2Core;

In bool PixelBufferCocoa::realizeImplementation() 
    attr[i++] = NSOpenGLPFAOpenGLProfile;
    attr[i++] = NSOpenGLProfileVersion3_2Core;


4) The osg ffmpeg pluging meeds /usr/lib/libbz2.dylib (this is not related to GL3 and probably is due to how I compiled my copy of ffmpeg)


By the way, executing osgsimplegl3 I got lots of errors:
Warning: detected OpenGL error 'invalid enumerant' at Before Renderer::compile
Warning: Material::apply(State&) - not supported.
Warning: TexGen::apply(State&) - not supported.
Warning: Material::apply(State&) - not supported.
Warning: TexGen::apply(State&) - not supported.

Salut,

   David



David Garcia
 
Technical Director 

Paul Martz

unread,
Mar 1, 2012, 8:37:11 PM3/1/12
to OpenSceneGraph Users
On 3/1/2012 5:11 PM, David Garcia wrote:
> 1) In GL I add two includes, three defines for missing symbols and an ifdef
> __APPLE__
>
> #if defined(OSG_GL3_AVAILABLE)
> #ifdef __APPLE__
> #include <OpenGL/OpenGL.h>
> #include <OpenGL/gl3.h>
> #define GLint64EXT GLint64
> #define GLuint64EXT GLuint64
> #define GL_BGRA_EXT GL_BGRA
> #else
> #include <GL3/gl3.h>
> #define GL3_PROTOTYPES 1
> #endif

> 3) Setting the pixel format as Stephan suggests.


>
> In bool GraphicsWindowCocoa::realizeImplementation():
> attr[i++] = NSOpenGLPFAOpenGLProfile;
> attr[i++] = NSOpenGLProfileVersion3_2Core;
>
> In bool PixelBufferCocoa::realizeImplementation()
> attr[i++] = NSOpenGLPFAOpenGLProfile;
> attr[i++] = NSOpenGLProfileVersion3_2Core;

When you have tested and are satisfied with the changes mentioned in items 1 and
3, I hope you'll submit them to osg-submissions. It will be nice to have GL 3
support on something other than MS Windows.

> By the way, executing osgsimplegl3 I got lots of errors:
> Warning: detected OpenGL error 'invalid enumerant' at Before Renderer::compile
> Warning: Material::apply(State&) - not supported.
> Warning: TexGen::apply(State&) - not supported.
> Warning: Material::apply(State&) - not supported.
> Warning: TexGen::apply(State&) - not supported.

If you attempt to render a scene graph that uses functionality that is
deprecated in GL3, such as Material and TexGen StateAttributes, then OSG
displays warnings so that you (or your app) can take steps to address that
situation.
-Paul

Robert Osfield

unread,
Mar 2, 2012, 4:00:23 AM3/2/12
to OpenSceneGraph Users
HI David,

The OSG is designed to check for extensions at runtime, so even if you
compile the OSG against OpenGL 1.1 it will still be able to load up
OpenGL 3.2 features at runtime and use them.

The CMake option to compile specifically against OpenGL 3 is for when
you want to compile against OpenGL 3 without the backwards
compatibility to OpenGL 2.x, this disables all the fixed function
pipeline. This is something you might want, but it's mostly not
necessary.

Robert.

Reply all
Reply to author
Forward
0 new messages