Hi, Eldar

Try to create your uniform with second way, but use 
osg::Uniform(osg::Uniform::FLOAT_VEC4, "colourPoints[0]", 20);// note [0] in 
uniform name
some drivers need this syntax to work propertly with uniform arrays

Cheers

08.05.2012, 18:12, "Eldar Insafutdinov" <e.insafutdi...@gmail.com>:
> Hi
>
> I am trying to use uniform arrays with OSG, but it fails. Here are the 
> snippets of code that  a'm using:
>
> Code:
>
> osg::StateSet *ss = node->getOrCreateStateSet();
>
> // one way of populating uniform array that I tried
> for(int i = 0; i < sz; ++i)
> {
>     char buf[30];
>     sprintf(buf, "colourPoints[%d]", i);
>     osg::Vec3 colour = osg::Vec3(1.0, 0.0, 1.0);
>     ss->addUniform(new osg::Uniform(buf, osg::Vec4(colour, 1.0)));
> }
>
> // another way
> osg::Uniform *colourPoints = new osg::Uniform(osg::Uniform::FLOAT_VEC4, 
> "colourPoints", 20);
> for(int i = 0; i < sz; ++i)
> {
>     osg::Vec3 colour = osg::Vec3(1.0, 0.0, 1.0);
>     colourPoints->setElement(i, osg::Vec4(colour, 1.0));
> }
> ss->addUniform(colourPoints);
>
> // and glsl
> uniform vec4 colourPoints[5];
>
> void main(void)
> {
>     vec4 col = colourPoints[1];
>     gl_FragColor = col;
> }
>
> I tried to set up uniforms both ways but neither of them worked and all I get 
> is a black colour. It must be something obvious that I am missing..
>
> Cheers,
> Eldar
>
> ------------------
> Read this topic online here:
> http://forum.openscenegraph.org/viewtopic.php?p=47598#47598
>
> _______________________________________________
> osg-users mailing list
> osg-users@lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to