Ok, to keep this up to date, I managed to render a textured model using OpenGL
ES 2.0 on the IPhone. But I am not sure whether this is the way to go...
Vertex Shader:
Code:
varying highp vec2 tex_coord0;
varying highp vec3 normal;
varying highp vec4 position;
void main(void)
{
tex_coord0 = gl_MultiTexCoord0.xy;
normal = gl_Normal;
position = gl_Vertex;
gl_Position = gl_ModelViewProjectionMatrix * position;
}
Fragment Shader:
Code:
varying highp vec2 tex_coord0;
varying highp vec3 normal;
varying highp vec4 position;
uniform sampler2D tex0;
uniform highp vec4 light_pos;
void main(void)
{
gl_FragColor = texture2D(tex0, tex_coord0) * (max(dot(normal, vec3(light_pos -
position)) * 0.7, 0.3));
}
I attach those shaders to the node containing the model:
Code:
osg::Program* program = new osg::Program;
program->setName("shader2");
program->addShader(new osg::Shader(osg::Shader::VERTEX, vertSource));
program->addShader(new osg::Shader(osg::Shader::FRAGMENT, fragSource));
model->getOrCreateStateSet()->setAttributeAndModes(program,
osg::StateAttribute::ON);
Using this code I get a textured model with some basic shading. But is this
really the way to go? It feels so "manual". But what ShaderGen does for OpenGL
ES 2.0 does not work at all (does not compile due to usage of undefined
variable names). Any hints or suggestions are very welcome!
Furthermore I get tons of messages like:
Code:
Warning: detected OpenGL error GL_INVALID_ENUM after applying GLMode 0xba1
Warning: Material::apply(State&) - not supported.
Warning: detected OpenGL error GL_INVALID_ENUM after applying GLMode 0xde1
Warning: detected OpenGL error GL_INVALID_ENUM after applying GLMode 0xb50
Those modes correspond to GL_NORMALIZE, GL_TEXTURE_2D and GL_LIGHTING. Why does
OSG still use them even it is compiled in OpenGL ES 2.0 mode? Am I doing
something wrong? Or is it just work in progress?
Thanks in advance,
rti
------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=31107#31107
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org