Re: [osg-users] OSG on OpenGL 3: Example code and cookbook
Hi Robert -- I've verified osgsimplegl3 builds and runs correctly in both GL2 and GL3 builds of trunk r12982. Thanks! -Paul ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] OSG on OpenGL 3: Example code and cookbook
Hi Paul, I am just working on merging your gl3example.cpp into svn/trunk and have renamed it osgsimplegl3 as it's a very bare bones little viewer example. I have also added the following lines just before the viewer.run() so that the example works fine on GL2 etc. builds. // for non GL3/GL4 and non GLES2 platforms we need enable the osg_ uniforms that the shaders will use, // you don't need thse two lines on GL3/GL4 and GLES2 specific builds as these will be enable by default. gc-getState()-setUseModelViewAndProjectionUniforms(true); gc-getState()-setUseVertexAttributeAliasing(true); Is this OK? Robert. On 6 January 2012 15:32, Paul Martz pma...@skew-matrix.com wrote: On 1/5/2012 10:18 AM, Robert Osfield wrote: Thanks for this. Do you feel it'd be appropriate to have this as an one of the OpenSceneGraph/examples? Hi Robert -- I do think it would be good to have it available, so if you'd like to include it in the examples, please do. I've attached an updated version that cleans up the code and comments a little bit. I'll forgo any kind of copyright and donate the code to the public domain (noted at the top of the file). I presume this would need to be added in such a way that it only builds for GL3, and there are a few different ways to do that. I'll leave the decision up to you to set a precedent for how GL3-specific examples should be added. -Paul ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] OSG on OpenGL 3: Example code and cookbook
On 1/5/2012 10:18 AM, Robert Osfield wrote: Thanks for this. Do you feel it'd be appropriate to have this as an one of the OpenSceneGraph/examples? Hi Robert -- I do think it would be good to have it available, so if you'd like to include it in the examples, please do. I've attached an updated version that cleans up the code and comments a little bit. I'll forgo any kind of copyright and donate the code to the public domain (noted at the top of the file). I presume this would need to be added in such a way that it only builds for GL3, and there are a few different ways to do that. I'll leave the decision up to you to set a precedent for how GL3-specific examples should be added. -Paul // This is public domain software and comes with // absolutely no warranty. Use of public domain software // may vary between counties, but in general you are free // to use and distribute this software for any purpose. // Example: OSG using an OpenGL 3.1 context. // The comment block at the end of the source describes building OSG // for use with OpenGL 3.x. #include osgViewer/Viewer #include osgDB/ReadFile #include osg/GraphicsContext #include osg/Camera #include osg/Viewport #include osg/StateSet #include osg/Program #include osg/Shader void configureShaders( osg::StateSet* stateSet ) { const std::string vertexSource = #version 140 \n \n uniform mat4 osg_ModelViewProjectionMatrix; \n uniform mat3 osg_NormalMatrix; \n uniform vec3 ecLightDir; \n \n in vec4 osg_Vertex; \n in vec3 osg_Normal; \n out vec4 color; \n \n void main() \n { \n vec3 ecNormal = normalize( osg_NormalMatrix * osg_Normal ); \n float diffuse = max( dot( ecLightDir, ecNormal ), 0. ); \n color = vec4( vec3( diffuse ), 1. ); \n \n gl_Position = osg_ModelViewProjectionMatrix * osg_Vertex; \n } \n; osg::Shader* vShader = new osg::Shader( osg::Shader::VERTEX, vertexSource ); const std::string fragmentSource = #version 140 \n \n in vec4 color; \n out vec4 fragData; \n \n void main() \n { \n fragData = color; \n } \n; osg::Shader* fShader = new osg::Shader( osg::Shader::FRAGMENT, fragmentSource ); osg::Program* program = new osg::Program; program-addShader( vShader ); program-addShader( fShader ); stateSet-setAttribute( program ); osg::Vec3f lightDir( 0., 0.5, 1. ); lightDir.normalize(); stateSet-addUniform( new osg::Uniform( ecLightDir, lightDir ) ); } int main( int argc, char** argv ) { osg::ArgumentParser arguments( argc, argv ); osg::Node* root = osgDB::readNodeFiles( arguments ); if( root == NULL ) { osg::notify( osg::FATAL ) Unable to load model from command line. std::endl; return( 1 ); } configureShaders( root-getOrCreateStateSet() ); const int width( 800 ), height( 450 ); const std::string version( 3.1 ); osg::ref_ptr osg::GraphicsContext::Traits traits = new osg::GraphicsContext::Traits(); traits-x = 20; traits-y = 30; traits-width = width; traits-height = height; traits-windowDecoration = true; traits-doubleBuffer = true; traits-glContextVersion = version; osg::ref_ptr osg::GraphicsContext gc = osg::GraphicsContext::createGraphicsContext( traits.get() ); if( !gc.valid() ) { osg::notify( osg::FATAL ) Unable to create OpenGL v version context. std::endl; return( 1 ); } // Create a Camera that uses the above OpenGL context. osg::Camera* cam = new osg::Camera; cam-setGraphicsContext( gc.get() ); // Must set perspective projection for fovy and aspect. cam-setProjectionMatrix( osg::Matrix::perspective( 30., (double)width/(double)height, 1., 100. ) ); // Unlike OpenGL, OSG viewport does *not* default to window dimensions. cam-setViewport( new osg::Viewport( 0, 0, width, height ) ); osgViewer::Viewer viewer; viewer.setCamera( cam ); viewer.setSceneData( root ); return( viewer.run() ); } /* Building OSG for OpenGL 3.x OSG currently support OpenGL 3.x on Windows. This comment block describes the necessary configuration steps. Get the draft gl3.h header file from OpenGL.org and put it in a folder called GL3 somewhere on your hard drive. OSG includes this header as GL3/gl3.h. Get gl3.h from here: http://www.opengl.org/registry/ Open the cmake-gui and load OSG's top-level CmakeLists.txt. You'll need to make several changes. * Add the path to GL3/gl3.h to the CMake compiler flags, CMAKE_CXX_FLAGS and CMAKE_CXX_FLAGS_DEBUG (for release and debug builds; others if you use other build configurations). The test to add should look something like this: /I C:\GLHeader The folder GLHeader should contain a subfolder GL3, which in turn contains gl3.h. * Enable the
Re: [osg-users] OSG on OpenGL 3: Example code and cookbook
Happy New Year Paul ;-) On 31 December 2011 22:05, Paul Martz pma...@skew-matrix.com wrote: Happy New Year, everyone -- Attached is source code that demonstrates OSG rendering using an OpenGL 3.x context. At the bottom of the source is a comment block describing how to build OSG for OpenGL 3.x. Thanks for this. Do you feel it'd be appropriate to have this as an one of the OpenSceneGraph/examples? Cheers, Robert. ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] OSG on OpenGL 3: Example code and cookbook
Hi Paul, Did you benchmark performance improvements with GL3 enabled ? Can you approximately quantify the FPS gain for example ? Kind regards. 2011/12/31 Paul Martz pma...@skew-matrix.com Happy New Year, everyone -- Attached is source code that demonstrates OSG rendering using an OpenGL 3.x context. At the bottom of the source is a comment block describing how to build OSG for OpenGL 3.x. I hope this is helpful. -- -Paul Martz Skew Matrix Software http://www.skew-matrix.com/ ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org -- Alexandre AMALRIC Ingénieur RD === PIXXIM S.A. 73E, rue Perrin-Solliers 13006 Marseille http://www.pixxim.fr ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] OSG on OpenGL 3: Example code and cookbook
On 1/2/2012 2:37 AM, Alexandre Amalric wrote: Did you benchmark performance improvements with GL3 enabled ? I'd be surprised if there was much difference. I would guess for a modern GPU, GL2 vs GL3 is purely a matter of semantics. -- Chris 'Xenon' Hanson, omo sanza lettere. xe...@alphapixel.com http://www.alphapixel.com/ Digital Imaging. OpenGL. Scene Graphs. GIS. GPS. Training. Consulting. Contracting. There is no Truth. There is only Perception. To Perceive is to Exist. - Xen ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
[osg-users] OSG on OpenGL 3: Example code and cookbook
Happy New Year, everyone -- Attached is source code that demonstrates OSG rendering using an OpenGL 3.x context. At the bottom of the source is a comment block describing how to build OSG for OpenGL 3.x. I hope this is helpful. -- -Paul Martz Skew Matrix Software http://www.skew-matrix.com/ #include osgViewer/Viewer #include osgDB/ReadFile #include osg/GraphicsContext #include osg/Camera #include osg/Viewport #include osg/StateSet #include osg/Program #include osg/Shader void configureShaders( osg::StateSet* stateSet ) { const std::string vertexSource = #version 140 \n \n uniform mat4 osg_ModelViewProjectionMatrix; \n uniform mat4 osg_ModelViewMatrix; \n uniform mat3 osg_NormalMatrix; \n \n in vec4 osg_Vertex; \n in vec3 osg_Normal; \n out vec4 color; \n \n void main() \n { \n vec3 ecVertex = vec3( osg_ModelViewMatrix * osg_Vertex ); \n vec3 ecNormal = normalize( osg_NormalMatrix * osg_Normal ); \n vec3 lightDir = vec3( 0., 0., 1. ); \n float diffuse = max( dot( lightDir, ecNormal ), 0. ); \n color = vec4( vec3( diffuse ), 1. ); \n \n gl_Position = osg_ModelViewProjectionMatrix * osg_Vertex; \n } \n; osg::Shader* vShader = new osg::Shader( osg::Shader::VERTEX, vertexSource ); const std::string fragmentSource = #version 140 \n \n in vec4 color; \n out vec4 fragData; \n \n void main() \n { \n fragData = color; \n } \n; osg::Shader* fShader = new osg::Shader( osg::Shader::FRAGMENT, fragmentSource ); osg::Program* program = new osg::Program; program-addShader( vShader ); program-addShader( fShader ); stateSet-setAttribute( program, osg::StateAttribute::ON ); } int main( int argc, char** argv ) { osg::ArgumentParser arguments( argc, argv ); osg::Node* root = osgDB::readNodeFiles( arguments ); if( root == NULL ) { osg::notify( osg::FATAL ) Unable to load model from command line. std::endl; return( 1 ); } configureShaders( root-getOrCreateStateSet() ); const int width( 800 ), height( 450 ); const std::string version( 3.1 ); osg::ref_ptr osg::GraphicsContext::Traits traits = new osg::GraphicsContext::Traits(); traits-x = 20; traits-y = 30; traits-width = 800; traits-height = 450; traits-windowDecoration = true; traits-doubleBuffer = true; traits-glContextVersion = version; osg::ref_ptr osg::GraphicsContext gc = osg::GraphicsContext::createGraphicsContext( traits.get() ); if( !gc.valid() ) { osg::notify( osg::FATAL ) Unable to create OpenGL v version context. std::endl; return( 1 ); } // Create a Camera that uses the above OpenGL context. osg::Camera* cam = new osg::Camera; cam-setGraphicsContext( gc.get() ); // Must set perspective projection; default ortho confuses TrackballManipulator home computation. cam-setProjectionMatrix( osg::Matrix::perspective( 60., (double)width/(double)height, 1., 100. ) ); // Unlike OpenGL, OSG viewport does *not* default to window dimensions. cam-setViewport( new osg::Viewport( 0, 0, width, height ) ); osgViewer::Viewer viewer; viewer.setCamera( cam ); viewer.setSceneData( root ); return( viewer.run() ); } /* Building OSG for OpenGL 3.x OSG currently support OpenGL 3.x on Windows. This comment block describes the necessary configuration steps. Get the draft gl3.h header file from OpenGL.org and put it in a folder called GL3 somewhere on your hard drive. OSG includes this header as GL3/gl3.h. Get gl3.h from here: http://www.opengl.org/registry/ Open the cmake-gui and load OSG's top-level CmakeLists.txt. You'll need to make several changes. * Add the path to GL3/gl3.h to the CMake compiler flags, CMAKE_CXX_FLAGS and CMAKE_CXX_FLAGS_DEBUG (for release and debug builds; others if you use other build configurations). The test to add should look something like this: /I C:\GLHeader The folder GLHeader should contain a subfolder GL3, which in turn contains gl3.h. * Enable the following CMake variable: OSG_GL3_AVAILABLE * Disable the following CMake variables: OSG_GL1_AVAILABLE OSG_GL2_AVAILABLE OSG_GLES1_AVAILABLE OSG_GLES2_AVAILABLE OSG_GL_DISPLAYLISTS_AVAILABLE OSG_GL_FIXED_FUNCTION_AVAILABLE OSG_GL_MATRICES_AVAILABLE OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE OSG_GL_VERTEX_FUNCS_AVAILABLE * Additionally, leave BUILD_OSG_EXAMPLES disabled. None of the existing examples use GL3, so there's no point in building them. Create your project files in cmake-gui as usual, and build OSG as usual. If you have an external project that will depend on OSG built for OpenGL 3.x, you'll need to ensure your external project