[osg-users] OSG 3.5.0 (130) GLES2 Shaders Example
    Alex Cham 
    cau.mbox at gmail.com
       
    Mon Jul 20 10:17:56 PDT 2015
    
    
  
Hi,
Just Simple OSG 3.5.0 (130) GLES2 Shaders Example
Code:
/**
#define OPENSCENEGRAPH_MAJOR_VERSION    3
#define OPENSCENEGRAPH_MINOR_VERSION    5
#define OPENSCENEGRAPH_PATCH_VERSION    0
#define OPENSCENEGRAPH_SOVERSION        130
$ git log -1
commit bc3a77cb1561ed2e47e88ab507180bcf15309f31
Author: Robert OSFIELD <>
Date:   Fri Jul 17 18:31:22 2015 +0000
mkdir ./GLES2ContextBuild
cd ./GLES2ContextBuild
cmake \
-DCMAKE_C_COMPILER="/usr/bin/clang" \
-DCMAKE_CXX_COMPILER="/usr/bin/clang++" \
-DCMAKE_CXX_FLAGS="-std=c++11 -v -Wall" \
-DBUILD_OSG_EXAMPLES=1 \
-DOSG_GL1_AVAILABLE=OFF \
-DOSG_GL2_AVAILABLE=OFF \
-DOSG_GL3_AVAILABLE=OFF \
-DOSG_GLES1_AVAILABLE=OFF \
-DOSG_GLES2_AVAILABLE=ON \
-DOPENGL_INCLUDE_DIR=/usr/include/ \
-DOPENGL_LIBRARY=/usr/lib/x86_64-linux-gnu/libGLESv2.so \
-DOPENGL_egl_LIBRARY=/usr/lib/x86_64-linux-gnu/libEGL.so \
-DOSG_GL_DISPLAYLISTS_AVAILABLE=OFF \
-DSG_GL_MATRICES_AVAILABLE=OFF \
-DOSG_GL_VERTEX_FUNCS_AVAILABLE=OFF \
-DOSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE=OFF \
-DOSG_GL_FIXED_FUNCTION_AVAILABLE=OFF \
-DOSG_CPP_EXCEPTIONS_AVAILABLE=OFF \
../GLES2ContextSource
http://trac.openscenegraph.org/projects/osg/wiki/Community/OpenGL-ES
Based on OSG osgsimpleshaders.cpp
http://svn.openscenegraph.org/osg/OpenSceneGraph/trunk/examples/osgsimpleshaders/osgsimpleshaders.cpp
See Also Hello Triangle: An OpenGL ES 2.0 Example
https://www.khronos.org/assets/uploads/books/openglr_es_20_programming_guide_sample.pdf
 */
#include <osgViewer/Viewer>
#include <osg/ShapeDrawable>
#include <osg/Geode>
#include <osg/Vec3>
#include <osg/Program>
#include <osg/Shader>
#include <osg/Uniform>
using namespace osg;
static const char *vertexShaderSource = {
		"attribute vec4 vPosition;\n"
		"void main()\n"
		"{\n"
		"gl_Position = vPosition;\n"
		"}\n"};
static const char *fragmentShaderSource = {
		"precision mediump float;\n"
		"void main()\n"
		"{\n"
		"gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);\n"
		"}\n"};
int main(int, char **)
{
	osg::setNotifyLevel(osg::INFO);
    // construct the viewer.
    osgViewer::Viewer viewer;
    // use a geode with a Box ShapeDrawable
    osg::Geode* geode = new osg::Geode();
    geode->addDrawable(new osg::ShapeDrawable(new osg::Box(osg::Vec3(0.0f,0.0f,0.0f),1.0f)));
    osg::StateSet *ss = geode->getOrCreateStateSet();
    osg::Program* program = new osg::Program;
	program->addShader( new osg::Shader( osg::Shader::VERTEX, vertexShaderSource ) );
	program->addShader( new osg::Shader( osg::Shader::FRAGMENT, fragmentShaderSource ) );
	ss->setAttributeAndModes(program, osg::StateAttribute::ON);
    viewer.setSceneData(geode);
    return viewer.run();
}
/*EOF*/
Thank you!
Cheers,
Alex[/code]
------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=64383#64383
    
    
More information about the osg-users
mailing list