Hi Hans,
Which fog coordinates are you using (i.e. osg::Fog::FOG_COORDINATE -or-
osg::Fog::FRAGMENT_DEPTH)? The following snippet has worked for me.
osg::Fog* fog(new osg::Fog());
fog->setMode(osg::Fog::LINEAR);
fog->setFogCoordinateSource(osg::Fog::FRAGMENT_DEPTH);
fog->setDensity(0);
fog->setStart(10);
fog->setEnd(100);
fog->setColor(osg::Vec4(0.5, 0.5, 0.5, 0.5));
...
rootNode->getOrCreateStateSet()->setAttributeAndModes(fog,
osg::StateAttribute::ON);
Hope This Helps,
Justin
-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of J.P.
Delport
Sent: Tuesday, November 13, 2007 5:22 AM
To: OpenSceneGraph Users
Subject: Re: [osg-users] Problem with osg::Fog
Hi,
below is 'n snippet that I use that works. Only diff seems the call to
gstate->setMode(GL_FOG, osg::StateAttribute::ON);
cheers
jp
---8<---
// Fog
//float fog_density = 9.85e-5;
float fog_density = g_config->getDouble("fog", "density", 0.0);
osg::Vec4d fog_colour = g_config->getVec4("fog", "colour",
osg::Vec4(
0.5, 0.5, 0.5, 0.0));
osg::Fog* fog = new osg::Fog();
fog->setMode(osg::Fog::EXP);
fog->setColor(fog_colour);
fog->setDensity(fog_density);
gstate->setMode(GL_FOG, osg::StateAttribute::ON);
gstate->setAttribute(fog,osg::StateAttribute::ON);
---8<---
Elbers, H.P. wrote:
> Hi Robert,
>
> Thank you for responding. I've been experimenting for hours, with the
> 'opengl programming guide' on my desk, but no luck.
>
> In my small test program the initial view distance to the centre of my
> scene is about 250.
>
> I would expect the following to work but is does NOT:
> fog->setMode(Fog::LINEAR);
> fog->setStart(200.f); fog->setEnd(300.f);
>
> The fog looks 'ok' on my example when I use negative start/end values
> (but I dont understand why it works):
> fog->setMode(Fog::LINEAR);
> fog->setStart(-200.f);
>
> For the exponential mode I would expect this to work, but it does not
> (nor does any other density)
> fog->setMode(Fog::EXP);
> fog->setDensity(.00277); // e^(-250. * .00277) = .5
>
> Any clue? any hint? A simple working example (code or osg-file)?
> anybody?
>
> Thanks,
> Hans,
>
>> Hi Hans,
>>
>> Fog most likely will be working correctly, just the values
>> involved need tweaking. The best thing to do is read up on
>> OpenGL Fog settings, the OSG just passes the settings it has
>> on to OpenGL. osg::Fog is effectively glFog, all the
>> variable and naming conventions are the same.
>>
>> Robert.
>>
>> On Nov 12, 2007 12:25 PM, Elbers, H.P. <[EMAIL PROTECTED]>
wrote:
>>>
>>> Hello All,
>>>
>>> I'm new to osg, and trying to use Fog...
>>>
>>> I get no fog at all, unless I use LINEAR mode with negative
>> start and
>>> end values, wich I find strange: I would expect that
>> positive values
>>> are required. If I try EXP mode, I cannot get any fog at al.
>>>
>>> Am I overlooking something obvious?
>>> Please help!
>>>
>>> Hans Elbers
>>>
>>> ==========================================================
>>> I'm using OSG 2.2 on linux, installed in a default way.
>>> Here is a small test example (with red fog):
>>>
>>> I compile like this:
>>> g++ -c -g main.cpp -o main.o
>>> g++ -o osgtest -g main.o -losg -losgViewer -losgSim
>>>
>>> main.cpp:
>>> ==========================================================
>>> #include <osg/Group>
>>> #include <osg/Fog>
>>> #include <osgDB/ReadFile>
>>> #include <osg/MatrixTransform>
>>> #include <osg/PositionAttitudeTransform> #include
>> <osgViewer/Viewer>
>>> #include <osgGA/TrackballManipulator>
>>>
>>> using namespace osg;
>>> using namespace std;
>>>
>>> int main(int argc, char *argv[]) {
>>> osgViewer::Viewer viewer;
>>> Group *world = new Group();
>>>
>>> StateSet *state= world->getOrCreateStateSet();
>>>
>>> Fog *fog =
>> dynamic_cast<Fog*>(state->getAttribute(StateAttribute::FOG));
>>> if (!fog) fog = new Fog;
>>> fog->setColor(osg::Vec4(1.,0.,0., 1.));
>>> fog->setDensity(0.15f);
>>>
>>> // ====> FOG works !?!?!
>>> fog->setMode(Fog::LINEAR); fog->setStart(-200.f);
>>> fog->setEnd(-300.f);
>>>
>>> // ====> NO FOG !?!?!?
>>> //fog->setMode(Fog::LINEAR); fog->setStart(200.f);
>> fog->setEnd(300.f);
>>> //fog->setMode(Fog::EXP); fog->setStart(200.f);
>> fog->setEnd(300.f);
>>> state->setAttributeAndModes(fog,StateAttribute::ON);
>>>
>>> Node *obj = osgDB::readNodeFile("obj.osg");
>>> if (obj) for (int i=-5; i<=5; i++) for (int j=-5; j<=5; j++) {
>>> PositionAttitudeTransform *T = new PositionAttitudeTransform();
>>> world->addChild(T);
>>> T->setPosition(Vec3(10.*i, 10.*j, 0.));
>>> T->addChild(obj);
>>> }
>>>
>>> viewer.setSceneData(world);
>>> osgGA::TrackballManipulator *manip = new
>> osgGA::TrackballManipulator();
>>> viewer.setCameraManipulator(manip);
>>> viewer.realize();
>>>
>>> viewer.run();
>>> }
>>> ==========================================================
>>>
>>>
>>> obj.osg contains a small cube:
>>> ==========================================================
>>> Group {
>>> UniqueID Group_0
>>> DataVariance UNSPECIFIED
>>> name "root"
>>> nodeMask 0xffffffff
>>> cullingActive TRUE
>>> num_children 1
>>> Geode {
>>> UniqueID Geode_7
>>> DataVariance UNSPECIFIED
>>> name "geode19"
>>> nodeMask 0xffffffff
>>> cullingActive TRUE
>>> num_drawables 1
>>> ShapeDrawable {
>>> UniqueID ShapeDrawable_8
>>> DataVariance UNSPECIFIED
>>> Box {
>>> DataVariance UNSPECIFIED
>>> Center 0 0 0
>>> HalfLengths .5 .5 .5
>>> Rotation 0 0 0 1
>>> }
>>> useDisplayList FALSE
>>> useVertexBufferObjects TRUE
>>> color 1 1 1 1
>>> }
>>> }
>>> }
>>> ==========================================================
>>> _______________________________________________
>>> osg-users mailing list
>>> [email protected]
>>>
>>
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.
>>> org
>>>
>>>
>> _______________________________________________
>> osg-users mailing list
>> [email protected]
>> http://lists.openscenegraph.org/listinfo.cgi/osg-users-opensce
> negraph.org
> _______________________________________________
> osg-users mailing list
> [email protected]
>
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.or
g
>
--
This message is subject to the CSIR's copyright terms and conditions,
e-mail legal notice, and implemented Open Document Format (ODF)
standard.
The full disclaimer details can be found at
http://www.csir.co.za/disclaimer.html.
This message has been scanned for viruses and dangerous content by
MailScanner,
and is believed to be clean. MailScanner thanks Transtec Computers for
their support.
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.or
g
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org