[osg-users] Text colors in shaders
Werner Modenbach
Werner.Modenbach at texion.eu
Fri Feb 24 03:57:49 PST 2017
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=newosgViewer::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
uniformmat4osg_ModelViewProjectionMatrix;
uniformmat4osg_ModelViewMatrix;
uniformmat3osg_NormalMatrix;
uniformvec3lightPosition0=vec3(0.0f,0.0f,1.0f);
invec4osg_Vertex;
invec4osg_Normal;
invec4osg_Color;
invec4osg_MultiTexCoord0;
outvec3normal;
outvec3lightDir;
outvec4vertexColor;
outvec2textureCoord;
voidmain(){
normal=normalize(osg_NormalMatrix*osg_Normal.xyz);
vec3vertexPos=vec3(osg_ModelViewMatrix*osg_Vertex);
lightDir=normalize(lightPosition0-vertexPos);
vertexColor=osg_Color;
textureCoord=osg_MultiTexCoord0.xy;
gl_Position=osg_ModelViewProjectionMatrix*osg_Vertex;
}
FRAGMENT
uniformsampler2DbaseTexture;
invec3normal;
invec3lightDir;
invec4vertexColor;
invec2textureCoord;
outvec4fragData;
voidmain(){
vec4textureColor=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 -
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20170224/a6afbb54/attachment-0001.htm>
More information about the osg-users
mailing list