Re: [osg-users] OpenGL ES 2.0 and LIGHTING

2018-11-20 Thread Grigoriy Mylnikov
Thank you, it works.

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=75222#75222





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] OpenGL ES 2.0 and LIGHTING

2018-11-20 Thread Chris Hanson
http://alphapixel.com/faqs/

src\osgUtil\SceneView.cpp(422): osg::Uniform* uniform =
_localStateSet->getOrCreateUniform(“osg_ViewMatrix”,osg::Uniform::FLOAT_MAT4);

src\osgUtil\SceneView.cpp(428): osg::Uniform* uniform =
_localStateSet->getOrCreateUniform(“osg_ViewMatrixInverse”,osg::Uniform::FLOAT_MAT4);
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Change color of node read from dxf file

2018-11-20 Thread Chris Hanson
I dunno man, your code is making my head explode. I don't think Geode HAS
an addChild method, so I don't even know why what you're doing would
compile.

I don't think I can help any further. I'm missing something or you are.

On Tue, Nov 20, 2018 at 5:46 PM Diego Mancilla  wrote:

> Hi,
>
> The suggestion of Chris solve the problem.
>
> The actual code:
>
>
> Code:
> osg::Node* lines = osgDB::readNodeFile("lines.dxf");
> osg::Geode* geode = new osg::Geode;
>
> ColorVisitor newColor;
> newColor.setColor( 1.0f, 0.0f, 0.0f );
> topography->accept(newColor);
>
> geode->addChild(lines);
> _mViewer->setSceneData(geode);
> _mViewer->realize();
>
>
>
>
> Where ColorVisitor is a derived class from osg::NodeVistor:
>
>
> Code:
>
>
> class ColorVisitor : public osg::NodeVisitor
> {
> public:
> ColorVisitor();
> ColorVisitor(const osg::Vec4 );
> virtual ~ColorVisitor();
> virtual void ColorVisitor::apply(osg::Node );
> virtual void ColorVisitor::apply(osg::Geode );
> virtual void ColorVisitor::setColor(const float r, const float g, const
> float b, const float a = 1.0f);
> virtual void ColorVisitor::setColor(const osg::Vec4 );
>
> private:
> osg::Vec4 m_color;
> osg::ref_ptr< osg::Vec4Array > m_colorArrays;
>
>
>
> and the implementation:
>
>
> Code:
>
> #include "ColorVisitor.h"
>
> ColorVisitor::ColorVisitor():
> osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN) {
> m_color.set(1.0, 1.0, 1.0, 1.0);
> m_colorArrays = new osg::Vec4Array;
> m_colorArrays->push_back(m_color);
> };
>
> ColorVisitor::ColorVisitor(const osg::Vec4 ):
> osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN){
> m_color = color;
> m_colorArrays = new osg::Vec4Array;
> m_colorArrays->push_back(m_color);
> };
>
> ColorVisitor::~ColorVisitor(){};
>
> void ColorVisitor::apply(osg::Node ) {
> traverse(node);
> };
>
> void ColorVisitor::apply(osg::Geode ) {
> osg::StateSet *state = NULL;
> unsigned int vertNum = 0;
> unsigned int numGeoms = geode.getNumDrawables();
>
> for (unsigned int geodeIdx = 0; geodeIdx < numGeoms; geodeIdx++) {
> if (curGeom) {
> osg::Vec4Array *colorArrays = dynamic_cast *>(curGeom->getColorArray());
> if (colorArrays) {
> for (unsigned int i = 0; i < colorArrays->size(); i++) {
> osg::Vec4 *color = >operator [](i);
> color->set(m_color._v[0], m_color._v[1], m_color._v[2], m_color._v[3]);
> }
> }
> else {
> curGeom->setColorArray(m_colorArrays.get());
> curGeom->setColorBinding(osg::Geometry::BIND_OVERALL);
> }
> }
> }
> };
>
> void ColorVisitor::setColor(const float r, const float g, const float b,
> const float a) {
>
> osg::Vec4 *c = _colorArrays->operator [](0);
> m_color.set(r, g, b, a);
> *c = m_color;
>
> };
>
> void ColorVisitor::setColor(const osg::Vec4 ) {
>
> osg::Vec4 *c = _colorArrays->operator [](0);
> m_color = color;
> *c = m_color;
> };
>
>
>
> The ColorVistor class I took it from Gordon Tomlison's OSG Samples (cant
> post links yet)
>
> One thing stills bother me. If I dont use the line
> Code:
> geode->addChild(lines)
>
>  and instead I pass directly the node to the viewer
>
> Code:
> _mViewer->setSceneData(lines);
>
>  the application crashes. Can anyone tell why this is happening?
>
> Thank you!
> PS: Sorry I coudnt get the code blocks indented... :(
>
> Cheers,
>
> --
> Read this topic online here:
> http://forum.openscenegraph.org/viewtopic.php?p=75219#75219
>
>
>
>
>
> ___
> osg-users mailing list
> osg-users@lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>


-- 
Chris 'Xenon' Hanson, omo sanza lettere. xe...@alphapixel.com
http://www.alphapixel.com/
Training • Consulting • Contracting
3D • Scene Graphs (Open Scene Graph/OSG) • OpenGL 2 • OpenGL 3 • OpenGL 4 •
GLSL • OpenGL ES 1 • OpenGL ES 2 • OpenCL
Legal/IP • Forensics • Imaging • UAVs • GIS • GPS •
osgEarth • Terrain • Telemetry • Cryptography • LIDAR • Embedded • Mobile •
iPhone/iPad/iOS • Android
@alphapixel  facebook.com/alphapixel (775)
623-PIXL [7495]
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Change color of node read from dxf file

2018-11-20 Thread Diego Mancilla
Hi,

The suggestion of Chris solve the problem.

The actual code:


Code:
osg::Node* lines = osgDB::readNodeFile("lines.dxf");
osg::Geode* geode = new osg::Geode;

ColorVisitor newColor;
newColor.setColor( 1.0f, 0.0f, 0.0f );
topography->accept(newColor);

geode->addChild(lines); 
_mViewer->setSceneData(geode);
_mViewer->realize();




Where ColorVisitor is a derived class from osg::NodeVistor:


Code:


class ColorVisitor : public osg::NodeVisitor
{
public:
ColorVisitor();
ColorVisitor(const osg::Vec4 );
virtual ~ColorVisitor();
virtual void ColorVisitor::apply(osg::Node );
virtual void ColorVisitor::apply(osg::Geode );
virtual void ColorVisitor::setColor(const float r, const float g, const float 
b, const float a = 1.0f);
virtual void ColorVisitor::setColor(const osg::Vec4 );

private:
osg::Vec4 m_color;
osg::ref_ptr< osg::Vec4Array > m_colorArrays;



and the implementation:


Code:

#include "ColorVisitor.h"

ColorVisitor::ColorVisitor(): 
osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN) {
m_color.set(1.0, 1.0, 1.0, 1.0);
m_colorArrays = new osg::Vec4Array;
m_colorArrays->push_back(m_color);
};

ColorVisitor::ColorVisitor(const osg::Vec4 ): 
osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN){
m_color = color;
m_colorArrays = new osg::Vec4Array;
m_colorArrays->push_back(m_color);
};

ColorVisitor::~ColorVisitor(){};

void ColorVisitor::apply(osg::Node ) {
traverse(node);
};

void ColorVisitor::apply(osg::Geode ) {
osg::StateSet *state = NULL;
unsigned int vertNum = 0;
unsigned int numGeoms = geode.getNumDrawables();

for (unsigned int geodeIdx = 0; geodeIdx < numGeoms; geodeIdx++) {
if (curGeom) {
osg::Vec4Array *colorArrays = dynamic_cast(curGeom->getColorArray());
if (colorArrays) {
for (unsigned int i = 0; i < colorArrays->size(); i++) {
osg::Vec4 *color = >operator [](i);
color->set(m_color._v[0], m_color._v[1], m_color._v[2], m_color._v[3]);
}
}
else {
curGeom->setColorArray(m_colorArrays.get());
curGeom->setColorBinding(osg::Geometry::BIND_OVERALL);
}
}
}
};

void ColorVisitor::setColor(const float r, const float g, const float b, const 
float a) {

osg::Vec4 *c = _colorArrays->operator [](0);
m_color.set(r, g, b, a);
*c = m_color;

};

void ColorVisitor::setColor(const osg::Vec4 ) {

osg::Vec4 *c = _colorArrays->operator [](0);
m_color = color;
*c = m_color;
};



The ColorVistor class I took it from Gordon Tomlison's OSG Samples (cant post 
links yet)

One thing stills bother me. If I dont use the line 
Code:
geode->addChild(lines)

 and instead I pass directly the node to the viewer

Code:
_mViewer->setSceneData(lines);

 the application crashes. Can anyone tell why this is happening? 

Thank you!
PS: Sorry I coudnt get the code blocks indented... :(

Cheers,

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=75219#75219





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] OpenGL ES 2.0 and LIGHTING

2018-11-20 Thread Grigoriy Mylnikov
Hi,

One more question. If I use gl_ModelViewMatrix in shaders to transform Light 
position, it gets transformed by both camera matrix and current node's matrix, 
that is not right.
Is there some build-in OSG uniform that holds only camera matrix or only model 
matrix? Or I should compute it and pass as my own uniform?

Thank you!

Cheers,
Grigoriy

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=75218#75218





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Change color of node read from dxf file

2018-11-20 Thread Diego Mancilla
Hello Chris,

Thank you for your answer. 

 My code, actually compiles, nevertheless I was expecting a conceptual error 
from my side.

 I will try what you suggest.

Cheers,

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=75217#75217





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org