Discussion:
OSG and OpenGL ES 2.0
Ankur Gandhi
2011-04-06 08:35:16 UTC
Permalink
Hi,

I am a new member of OSG. I am using 2.9.11 (latest developer release) version of OSG. In last few weeks, I used OSG over OpenGL. All the examples and Tutorials that are posted on the site have been very useful in learning OSG. Now, I want to use OSG over OpenGL ES 2.0. For this, I have modified cmake variables accordingly to emulate OpenGL ES on my ubuntu system. However I can't seem to get any example work. I get many different kinds of errors as below.


Warning: Material::apply(State&) - not supported.
Warning: TexEnv::apply(State&) - not supported.
Warning: Material::apply(State&) - not supported.
Warning: TexEnv::apply(State&) - not supported.
Warning: Material::apply(State&) - not supported.
Warning: TexEnv::apply(State&) - not supported.
Warning: Material::apply(State&) - not supported.
Warning: TexEnv::apply(State&) - not supported.
Warning: Material::apply(State&) - not supported.
Warning: TexEnv::apply(State&) - not supported.
Warning: Material::apply(State&) - not supported.
Warning: TexEnv::apply(State&) - not supported.
Warning: Material::apply(State&) - not supported.
Warning: TexEnv::apply(State&) - not supported.
Segmentation fault


After going through old posts, i found that these examples won't work directly over OpenGL es.

I would like to know if there are any examples available which i can use over OpenGL ES. It would really help me in figuring out if my OSG recompilation is successful and it will enable me to learn OSG over opengl ES.

Thank you!

Cheers,
Ankur

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=38244#38244
Christian Ruzicka
2011-04-06 15:53:30 UTC
Permalink
Hi,

it's just a really simple scene but it should help you figuring out, if your OpenGLES 2.0 support works (tested on iPhone):


Code:
// create geometry
osg::Group* scene = new osg::Group;
osg::Geode* geode = new osg::Geode;
osg::Geometry* geo = new osg::Geometry;
scene->addChild(geode);
geode->addDrawable(geo);

// set vertices
osg::Vec3Array* vertices = new osg::Vec3Array;
vertices->push_back(osg::Vec3(0.0, 0.0, 0.0));
vertices->push_back(osg::Vec3(0.0, 0.0, 1.0));
vertices->push_back(osg::Vec3(1.0, 0.0, 0.0));
vertices->push_back(osg::Vec3(1.0, 0.0, 1.0));
geo->setVertexArray(vertices);

// set colors
osg::Vec4Array* colors = new osg::Vec4Array;
colors->push_back(osg::Vec4(1.0, 0.0, 0.0, 1.0));
colors->push_back(osg::Vec4(0.0, 1.0, 0.0, 1.0));
colors->push_back(osg::Vec4(0.0, 0.0, 1.0, 1.0));
colors->push_back(osg::Vec4(1.0, 0.0, 1.0, 1.0));
geo->setVertexAttribArray(7, colors);
geo->setVertexAttribBinding(7, osg::Geometry::BIND_PER_VERTEX);

// set primitive set
geo->addPrimitiveSet(new osg::DrawArrays(GL_TRIANGLE_STRIP, 0, 4));
geo->setUseVertexBufferObjects(true);

// declare shaders
char vertSource[] =
"attribute vec4 osg_Vertex;\n"
"attribute vec4 a_col;"
"uniform mat4 osg_ModelViewProjectionMatrix;\n"
"varying vec4 v_col;"

"void main(void)\n"
"{\n"
"gl_Position = osg_ModelViewProjectionMatrix * osg_Vertex;\n"
"v_col = a_col;\n"
"}\n";

char fragSource[] =
"precision mediump float;\n"
"varying vec4 v_col;"

"void main(void)\n"
"{\n"
"gl_FragColor = v_col;\n"
"}\n";

// set shader
osg::Program* program = new osg::Program;
program->setName( "simple shader" );
program->addShader( new osg::Shader( osg::Shader::VERTEX, vertSource ) );
program->addShader( new osg::Shader( osg::Shader::FRAGMENT, fragSource ) );
program->addBindAttribLocation("a_col", 7);
geode->getOrCreateStateSet()->setAttributeAndModes( program, osg::StateAttribute::ON );

// set scene in viewer...




HTH,
Christian

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=38263#38263
Christian Ruzicka
2011-04-06 19:38:27 UTC
Permalink
Hi,

just one addition to my previous post: Normally you wouldn't define an extra vertex attribute array for the vertex color/normal as I did in this test code. Just use

void Geometry::setColorArray(Array* array);
void Geometry::setNormalArray(Array* array);

and access the vertex color/normal in the vertex shader via "osg_Color" and "osg_Normal" (OSG will do the mapping for you).

Cheers,
Christian

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=38270#38270
Ankur Gandhi
2011-04-07 12:25:53 UTC
Permalink
Hi Christian,

Thanks for your input and source code that you shared. I had tried your program however my application crashes with segmentation fault. when i check backtrace, it shows crashing point at the drivers (i am using intel i915 display).

actually I am pretty new to OpenGL & OpenGL ES too. so concept of Shader is new to me. So i think i need to go through shader first! :-) Also, i used OpenGL emulation for OSG build. now i think i will try by installing OpenGL ES library and perform build for actual GLES2.

I will update you soon regarding my activities.

Thanks again for help!

Regards/Ankur
Post by Christian Ruzicka
Hi,
just one addition to my previous post: Normally you wouldn't define an extra vertex attribute array for the vertex color/normal as I did in this test code. Just use
void Geometry::setColorArray(Array* array);
void Geometry::setNormalArray(Array* array);
and access the vertex color/normal in the vertex shader via "osg_Color" and "osg_Normal" (OSG will do the mapping for you).
Cheers,
Christian
------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=38291#38291
Jorge Izquierdo Ciges
2011-04-08 06:37:05 UTC
Permalink
Just an advice. Do not try to start by learning gles in a emulator. It's
tricky and it's not real. There are more differences and incompabilities
that people can think about. Some of them can be very puzzling and difficult
to find inside Osg.
Post by Ankur Gandhi
Hi Christian,
Thanks for your input and source code that you shared. I had tried your
program however my application crashes with segmentation fault. when i check
backtrace, it shows crashing point at the drivers (i am using intel i915
display).
Post by Ankur Gandhi
actually I am pretty new to OpenGL & OpenGL ES too. so concept of Shader
is new to me. So i think i need to go through shader first! :-) Also, i used
OpenGL emulation for OSG build. now i think i will try by installing OpenGL
ES library and perform build for actual GLES2.
Post by Ankur Gandhi
I will update you soon regarding my activities.
Thanks again for help!
Regards/Ankur
Post by Christian Ruzicka
Hi,
just one addition to my previous post: Normally you wouldn't define an
extra vertex attribute array for the vertex color/normal as I did in this
test code. Just use
Post by Ankur Gandhi
Post by Christian Ruzicka
void Geometry::setColorArray(Array* array);
void Geometry::setNormalArray(Array* array);
and access the vertex color/normal in the vertex shader via "osg_Color"
and "osg_Normal" (OSG will do the mapping for you).
Post by Ankur Gandhi
Post by Christian Ruzicka
Cheers,
Christian
------------------
http://forum.openscenegraph.org/viewtopic.php?p=38291#38291
_______________________________________________
osg-users mailing list
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Loading...