Dear all,
my project needs gl3 features and so I use the following methods:
camera->getGraphicsContext()->getState()->setUseModelViewAndProjectionUniforms(useGL3);
camera->getGraphicsContext()->getState()->setUseVertexAttributeAliasing(useGL3);
Of course I need my own shaders then.
But I also like having built-in functionality like StatsHandler.
To set a simple shader for the StatsHandlers camera I do like that:
osgViewer::
StatsHandler
*
sthd
=
new osgViewer::
StatsHandler;
view->addEventHandler(sthd);
if (useGL3) {
stateSet = sthd->getCamera()->getOrCreateStateSet();
stateSet->getOrCreateUniform(BASE_TEXTURE_UNIFORM, osg::Uniform::INT_SAMPLER_2D)->set(BASE_TEXTURE_UNIT);
stateSet->setTextureAttributeAndModes(BASE_TEXTURE_UNIT, textur_weiss.get(), osg::StateAttribute::ON);
installDefaultShader(stateSet);
}
The shaders are really simple:
VERTEX
uniform mat4 osg_ModelViewProjectionMatrix;
uniform mat4 osg_ModelViewMatrix;
uniform mat3 osg_NormalMatrix;
uniform vec3 lightPosition0 = vec3(0.0f, 0.0f, 1.0f);
in vec4 osg_Vertex;
in vec4 osg_Normal;
in vec4 osg_Color;
in vec4 osg_MultiTexCoord0;
out vec3 normal;
out vec3 lightDir;
out vec4 vertexColor;
out vec2 textureCoord;
void main() {
normal = normalize(osg_NormalMatrix * osg_Normal.xyz);
vec3 vertexPos = vec3(osg_ModelViewMatrix * osg_Vertex);
lightDir = normalize(lightPosition0 - vertexPos);
vertexColor = osg_Color;
textureCoord = osg_MultiTexCoord0.xy;
gl_Position = osg_ModelViewProjectionMatrix * osg_Vertex;
}
FRAGMENT
uniform sampler2D baseTexture;
in vec3 normal;
in vec3 lightDir;
in vec4 vertexColor;
in vec2 textureCoord;
out vec4 fragData;
void main() {
vec4 textureColor = texture2D(baseTexture, textureCoord);
fragData = vertexColor * textureColor;
}
That works fine for the graphics but all text is black. Obviously
text does not set osg_Color
.
Unfortunately I failed discovering the reason in the sources of osg.
Can anyone give me a hint on how to solve this?
Many thanks in advance
- Werner -