:)) .. Let make the easy way :)

Here is the code with the proper setup

if (!mEnvironmentGroup.valid()) mEnvironmentGroup = new osg::Group;
mEnvironmentGroup->setName("ENVIRONMENT");
 mEnvironmentGroup->setNodeMask(0x0);

int tex_width = 256;
    int tex_height = 256;

double range = 40000.0;

osg::Camera::RenderTargetImplementation renderTargetImplementation =
osg::Camera::FRAME_BUFFER_OBJECT;

mEnvironmentCubeMap = new osg::TextureCubeMap;
    mEnvironmentCubeMap->setTextureSize(tex_width, tex_height);
    mEnvironmentCubeMap->setInternalFormat(GL_RGB);

 mEnvironmentCubeMap->setFilter(osg::Texture::MIN_FILTER,osg::Texture::LINEAR);

 mEnvironmentCubeMap->setFilter(osg::Texture::MAG_FILTER,osg::Texture::LINEAR);
mEnvironmentCubeMap->setWrap(osg::Texture::WRAP_S,
osg::Texture::CLAMP_TO_EDGE);
    mEnvironmentCubeMap->setWrap(osg::Texture::WRAP_T,
osg::Texture::CLAMP_TO_EDGE);
    mEnvironmentCubeMap->setWrap(osg::Texture::WRAP_R,
osg::Texture::CLAMP_TO_EDGE);

typedef std::pair<osg::Vec3, osg::Vec3> ImageData;
 typedef std::map<unsigned int, ImageData > ViewData;

ViewData id;
    id[osg::TextureCubeMap::POSITIVE_X] = ImageData( osg::Vec3( 1,  0,  0),
osg::Vec3( 0, -1,  0) ); // +X
    id[osg::TextureCubeMap::NEGATIVE_X] = ImageData( osg::Vec3(-1,  0,  0),
osg::Vec3( 0, -1,  0) ); // -X
    id[osg::TextureCubeMap::POSITIVE_Y] = ImageData( osg::Vec3( 0,  1,  0),
osg::Vec3( 0,  0,  1) ); // +Y
    id[osg::TextureCubeMap::NEGATIVE_Y] = ImageData( osg::Vec3( 0, -1,  0),
osg::Vec3( 0,  0, -1) ); // -Y
    id[osg::TextureCubeMap::POSITIVE_Z] = ImageData( osg::Vec3( 0,  0,  1),
osg::Vec3( 0, -1,  0) ); // +Z
    id[osg::TextureCubeMap::NEGATIVE_Z] = ImageData( osg::Vec3( 0,  0, -1),
osg::Vec3( 0, -1,  0) ); // -Z


// right face
    {
        osg::ref_ptr<osg::Camera> camera = new osg::Camera;
        camera->setViewport(new osg::Viewport(0, 0, tex_width, tex_height));
 camera->addChild(mSilverLiningGroup.get());
camera->setAllowEventFocus(false);
 camera->setProjectionMatrixAsFrustum(-1.0,1.0,-1.0,1.0,1.0,range);
camera->setViewMatrixAsLookAt(osg::Vec3(0,0,0),id[osg::TextureCubeMap::POSITIVE_X].first,id[osg::TextureCubeMap::POSITIVE_X].second);
 camera->setRenderTargetImplementation(renderTargetImplementation);
        camera->attach(osg::Camera::COLOR_BUFFER, mEnvironmentCubeMap.get(),
0, osg::TextureCubeMap::POSITIVE_X);
 camera->setUserData(mViewer->getView(0)->getCamera()->getUserData());
camera->setRenderOrder(osg::Camera::PRE_RENDER);
 camera->setComputeNearFarMode(osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR);
camera->setCullingActive(false);
 camera->setClearMask(0);
camera->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
 camera->setName("ENVIRONMENT_CAMERA");
camera->setUpdateCallback( new UpdateEnvironmentCameraNodeCallback(
 id[osg::TextureCubeMap::POSITIVE_X].first,
id[osg::TextureCubeMap::POSITIVE_X].second,
 mViewer->getView(0)->getCamera()) );
mEnvironmentGroup->addChild(camera);

    }

// left face
    {
        osg::ref_ptr<osg::Camera> camera = new osg::Camera;
        camera->setViewport(new osg::Viewport(0, 0, tex_width, tex_height));
camera->addChild(mSilverLiningGroup.get());
camera->setAllowEventFocus(false);
 camera->setProjectionMatrixAsFrustum(-1.0,1.0,-1.0,1.0,1.0,range);
camera->setViewMatrixAsLookAt(osg::Vec3(0,0,0),id[osg::TextureCubeMap::NEGATIVE_X].first,id[osg::TextureCubeMap::NEGATIVE_X].second);
 camera->setRenderTargetImplementation(renderTargetImplementation);
        camera->attach(osg::Camera::COLOR_BUFFER, mEnvironmentCubeMap.get(),
0, osg::TextureCubeMap::NEGATIVE_X);
 camera->setUserData(mViewer->getView(0)->getCamera()->getUserData());
camera->setRenderOrder(osg::Camera::PRE_RENDER);
 camera->setComputeNearFarMode(osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR);
camera->setCullingActive(false);
 camera->setClearMask(0);
camera->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
 camera->setName("ENVIRONMENT_CAMERA");
camera->setUpdateCallback( new UpdateEnvironmentCameraNodeCallback(
 id[osg::TextureCubeMap::NEGATIVE_X].first,
id[osg::TextureCubeMap::NEGATIVE_X].second,
 mViewer->getView(0)->getCamera()) );

mEnvironmentGroup->addChild(camera);
    }

    // front face
    {
        osg::ref_ptr<osg::Camera> camera = new osg::Camera;
        camera->setViewport(new osg::Viewport(0, 0, tex_width, tex_height));
 camera->addChild(mSilverLiningGroup.get());
camera->setAllowEventFocus(false);
 camera->setProjectionMatrixAsFrustum(-1.0,1.0,-1.0,1.0,1.0,range);
camera->setViewMatrixAsLookAt(osg::Vec3(0,0,0),id[osg::TextureCubeMap::POSITIVE_Y].first,id[osg::TextureCubeMap::POSITIVE_Y].second);
 camera->setRenderTargetImplementation(renderTargetImplementation);
        camera->attach(osg::Camera::COLOR_BUFFER, mEnvironmentCubeMap.get(),
0, osg::TextureCubeMap::POSITIVE_Y);
 camera->setUserData(mViewer->getView(0)->getCamera()->getUserData());
camera->setRenderOrder(osg::Camera::PRE_RENDER);
 camera->setComputeNearFarMode(osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR);
camera->setCullingActive(false);
 camera->setClearMask(0);
camera->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
 camera->setName("ENVIRONMENT_CAMERA");
camera->setUpdateCallback( new UpdateEnvironmentCameraNodeCallback(
 id[osg::TextureCubeMap::POSITIVE_Y].first,
id[osg::TextureCubeMap::POSITIVE_Y].second,
 mViewer->getView(0)->getCamera()) );

mEnvironmentGroup->addChild(camera);

    }

// back face
    {
        osg::ref_ptr<osg::Camera> camera = new osg::Camera;
        camera->setViewport(new osg::Viewport(0, 0, tex_width, tex_height));
camera->addChild(mSilverLiningGroup.get());
camera->setAllowEventFocus(false);
 camera->setProjectionMatrixAsPerspective(90.0f, 1.0, 1, range);
camera->setViewMatrixAsLookAt(osg::Vec3(0,0,0),id[osg::TextureCubeMap::NEGATIVE_Y].first,id[osg::TextureCubeMap::NEGATIVE_Y].second);
 camera->setRenderTargetImplementation(renderTargetImplementation);
        camera->attach(osg::Camera::COLOR_BUFFER, mEnvironmentCubeMap.get(),
0, osg::TextureCubeMap::NEGATIVE_Y);
 camera->setUserData(mViewer->getView(0)->getCamera()->getUserData());
camera->setRenderOrder(osg::Camera::PRE_RENDER);
 camera->setComputeNearFarMode(osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR);
camera->setCullingActive(false);
 camera->setClearMask(0);
camera->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
 camera->setName("ENVIRONMENT_CAMERA");
camera->setUpdateCallback( new UpdateEnvironmentCameraNodeCallback(
 id[osg::TextureCubeMap::NEGATIVE_Y].first,
id[osg::TextureCubeMap::NEGATIVE_Y].second,
 mViewer->getView(0)->getCamera()) );

mEnvironmentGroup->addChild(camera);

    }

    // top face
    {
        osg::ref_ptr<osg::Camera> camera = new osg::Camera;
        camera->setViewport(new osg::Viewport(0, 0, tex_width, tex_height));
 camera->addChild(mSilverLiningGroup.get());
camera->setAllowEventFocus(false);
 camera->setProjectionMatrixAsFrustum(-1.0,1.0,-1.0,1.0,1.0,range);
camera->setViewMatrixAsLookAt(osg::Vec3(0,0,0),id[osg::TextureCubeMap::POSITIVE_Z].first,id[osg::TextureCubeMap::POSITIVE_Z].second);
 camera->setRenderTargetImplementation(renderTargetImplementation);
        camera->attach(osg::Camera::COLOR_BUFFER, mEnvironmentCubeMap.get(),
0, osg::TextureCubeMap::POSITIVE_Z);
 camera->setUserData(mViewer->getView(0)->getCamera()->getUserData());
camera->setRenderOrder(osg::Camera::PRE_RENDER);
 camera->setComputeNearFarMode(osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR);
camera->setCullingActive(false);
 camera->setClearMask(0);
camera->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
 camera->setName("ENVIRONMENT_CAMERA");
camera->setUpdateCallback( new UpdateEnvironmentCameraNodeCallback(
 id[osg::TextureCubeMap::POSITIVE_Z].first,
id[osg::TextureCubeMap::POSITIVE_Z].second,
 mViewer->getView(0)->getCamera()) );

mEnvironmentGroup->addChild(camera);


    }



    // bottom face
    {
        osg::ref_ptr<osg::Camera> camera = new osg::Camera;
        camera->setViewport(new osg::Viewport(0, 0, tex_width, tex_height));
 camera->addChild(mSilverLiningGroup.get());
camera->setAllowEventFocus(false);
 camera->setProjectionMatrixAsFrustum(-1.0,1.0,-1.0,1.0,1.0,range);
camera->setViewMatrixAsLookAt(osg::Vec3(0,0,0),id[osg::TextureCubeMap::NEGATIVE_Z].first,id[osg::TextureCubeMap::NEGATIVE_Z].second);
 camera->setRenderTargetImplementation(renderTargetImplementation);
        camera->attach(osg::Camera::COLOR_BUFFER, mEnvironmentCubeMap.get(),
0, osg::TextureCubeMap::NEGATIVE_Z);
 camera->setUserData(mViewer->getView(0)->getCamera()->getUserData());
camera->setRenderOrder(osg::Camera::PRE_RENDER);
 camera->setComputeNearFarMode(osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR);
camera->setCullingActive(false);
 camera->setClearMask(0);
camera->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
 camera->setName("ENVIRONMENT_CAMERA");
camera->setUpdateCallback( new UpdateEnvironmentCameraNodeCallback(
 id[osg::TextureCubeMap::NEGATIVE_Z].first,
id[osg::TextureCubeMap::NEGATIVE_Z].second,
 mViewer->getView(0)->getCamera()) );

mEnvironmentGroup->addChild(camera);

    }


mScene->addChild( mEnvironmentGroup.get() );

-Nick


On Tue, Sep 7, 2010 at 3:41 PM, Wojciech Lewandowski
<[email protected]>wrote:

> Hi Martin,
>
> If you follow the vertexexample closely then then rotation can be simply
> added (or removed because its already there) to TexMat in TexMatCallback.
> Look at R matrix in TexMatCallback::operator(). Multiply this R matrix by
> neccessary rotation. If you don't know what rotation exactly, try 90 or -90
> degrees around X, Y, Z axes. After up to 6 tries you will find the one that
> best suits your need. And you will learn a lot ;-)
>
> Wojtek
>
> --------------------------------------------------
> From: ""Martin Großer"" <[email protected]>
> Sent: Tuesday, September 07, 2010 1:16 PM
> To: "OpenSceneGraph Users" <[email protected]>
> Subject: Re: [osg-users] How can I rotate a image
>
>
>  Ok, also I have create a sky box like the sky box in the vertexprogramm
>> example of osg. But in my scene the up vector is in the z direction and not
>> in the y direction. Now I have rotate my sky box 90 degrees around the x
>> axis.
>>
>> Is it understandable?
>>
>> But now, the images on the sky box are in the wrong orientation. For
>> example the image in the positiv x direction is 90 degrees rotated. And I
>> want to correct this rotation.
>>
>> Is it understandable? I am not sure.
>>
>> Cheers
>>
>> Martin
>>
>> -------- Original-Nachricht --------
>>
>>> Datum: Tue, 7 Sep 2010 14:57:24 +0400
>>> Von: "Trajce (Nick) Nikolov" <[email protected]>
>>> An: OpenSceneGraph Users <[email protected]>
>>> Betreff: Re: [osg-users] How can I rotate a image
>>>
>>
>>  what do you mean by "rotating an image"? Could you tell what you are
>>> actually trying to do? More info you provide more chances to get some
>>> advice
>>>
>>> -Nick
>>>
>>>
>>> 2010/9/7 "Martin Großer" <[email protected]>
>>>
>>> > Hello,
>>> >
>>> > I would like rotate a image. Because I want to rotate the separate
>>> images
>>> > from my sky box. I think it is difficult to change the texture
>>> coordinates
>>> > of my sphere. I my idea is to rotate the images at the beginning.
>>> >
>>> > Example
>>> >
>>> > ::osg::Image* image = osgDB::readImageFile(c_posX.Filename);
>>> >
>>> > // rotate image
>>> >
>>> > _cubeMap->setImage(::osg::TextureCubeMap::POSITIVE_X, image);
>>> >
>>> > I hope someone can help me.
>>> >
>>> > Cheers
>>> >
>>> > Martin
>>> > --
>>> > GMX DSL SOMMER-SPECIAL: Surf & Phone Flat 16.000 für nur 19,99
>>> Euro/mtl.!*
>>> > http://portal.gmx.net/de/go/dsl
>>> > _______________________________________________
>>> > osg-users mailing list
>>> > [email protected]
>>> >
>>> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>>> >
>>>
>>
>> --
>> GMX DSL SOMMER-SPECIAL: Surf & Phone Flat 16.000 für nur 19,99 Euro/mtl.!*
>> http://portal.gmx.net/de/go/dsl
>> _______________________________________________
>> 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-openscenegraph.org
>
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to