Hi Roman,
I don't know anything about VolumeClouds, so I don't think I'm going to
be much help here.  What is "PuffTexture"?  How and where is it set?  I
would try:

geode->getOrCreateStateSet()->setTextureMode(0,
                                   GL_TEXTURE_2D,
                                   osg::StateAttribute::ON |
osg::StateAttribute::OVERRIDE);

I've never handled textures in OpenGL inside of OSG.  Usually just
geometry.

Sorry,
Justin


-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Roman
Grigoriev
Sent: Wednesday, December 05, 2007 7:03 AM
To: OpenSceneGraph Users
Subject: Re: [osg-users] OSG and OpenGL rendering

Thanx Vican  that helps me
I've done as you said but I have not seen textures on my textured quads
Maybe I should use stateset but if I do like this
osg::StateSet* stateset = new osg::StateSet;

stateset->setTextureMode(0,GL_TEXTURE_2D,osg::StateAttribute::ON);

geode->setStateSet(stateset);

I havn't seen any textures too. Please help me.

I've done like this
class Cloud : public osg::Drawable

{

public:

Cloud() {}

Cloud(const Cloud& cloud,const osg::CopyOp& 
copyop=osg::CopyOp::SHALLOW_COPY):

osg::Drawable(cloud,copyop) {}

META_Object(myCloudApp,Cloud)



virtual void drawImplementation(osg::RenderInfo&) const

{

Vector3 sunvector,cameraposition;

sunvector.x=0;

sunvector.y=0;

sunvector.z=1;

cameraposition.x=1;

cameraposition.y=1;

cameraposition.z=1;

Frustum.CalculateFrustum();

VolumeClouds.Render(cameraposition, sunvector * SkyRadius);

}






protected:


virtual ~Cloud() {}


};

class updateCloudCB: public osg::NodeCallback {

public:

updateCloudCB() {}

~updateCloudCB() {}

virtual void operator()(osg::Node* node, osg::NodeVisitor* nv)

{

Vector3 sunvector,cameraposition;

sunvector.x=1;

sunvector.y=0;

sunvector.z=1;

cameraposition.x=1;

cameraposition.y=1;

cameraposition.z=1;

Frustum.CalculateFrustum();

VolumeClouds.Update(sunvector * SkyRadius, cameraposition);



traverse(node,nv);

}

private:

};

and in main.cpp - I've done like this:

if (VolumeClouds.Create(30, CloudPlaneSize / 2, CloudPlaneHeight))
return 1;

osg::Geode* geode = new osg::Geode();

geode->addDrawable( new Cloud );

root->addChild(geode);

->setUpdateCallback(new updateCloudCB);

in VolumeClouds.Render

void VolumetricClouds::Render(VolumetricCloud* Cloud, Vector3 Camera, 
Vector3 Sun, float alpha)

{

unsigned i;




float mat[16];

glGetFloatv(GL_MODELVIEW_MATRIX, mat);


Vector3 vx(mat[0], mat[4], mat[8] );

Vector3 vy(mat[1], mat[5], mat[9] );


glEnable(GL_TEXTURE_2D);

glBindTexture(GL_TEXTURE_2D, PuffTexture);


glEnable(GL_BLEND);

glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);


Vector3 Light = Normalize(Camera - Sun);

Vector3 Omega;

Color4 ParticleColor;


vector<CloudPuff>::iterator PuffIter;

CloudPuff* Puff;

int index = 0;


Vector3* vp; Vector2* tp; Color4* cp;

vp = Cloud->VertexBuffer;

tp = Cloud->TexCoordBuffer;

cp = Cloud->ColorBuffer;


Vector2 v1(1.0f, 0.0f), v2(0.0f, 0.0f), v3(0.0f, 1.0f), v4(1.0f, 1.0f);

float costheta, phase;

float omega2;

Vector3 Corner1, Corner2, Corner3, Corner4;

Corner1 = -vx - vy; Corner2 = vx - vy; Corner3 = vx + vy; Corner4 = vy -
vx;


for (PuffIter = Cloud->Puffs.begin(); PuffIter != Cloud->Puffs.end(); 
++PuffIter)

{

Puff = &*PuffIter;

Omega = Puff->Position - Camera;


omega2 = Omega.x * Omega.x + Omega.y * Omega.y + Omega.z * Omega.z;

omega2 = carmack_func(omega2);


//omega2 is now 1 / Mag(Omega)

Omega.x *= omega2; Omega.y *= omega2; Omega.z *= omega2;


costheta = Dot(Omega, Light);

phase = 0.75f * (1.0f + costheta * costheta);


ParticleColor.R = (0.3f + Puff->Color.R * phase) * alpha;

ParticleColor.G = (0.3f + Puff->Color.G * phase) * alpha;

ParticleColor.B = (0.3f + Puff->Color.B * phase) * alpha;

ParticleColor.A = Puff->Color.A * Puff->Life * alpha;

*(vp++) = Puff->Position + Corner1 * Puff->Size;

*(tp++) = v1;

*(cp++) = ParticleColor;


*(vp++) = Puff->Position + Corner2 * Puff->Size;

*(tp++) = v2;

*(cp++) = ParticleColor;


*(vp++) = Puff->Position + Corner3 * Puff->Size;

*(tp++) = v3;

*(cp++) = ParticleColor;


*(vp++) = Puff->Position + Corner4 * Puff->Size;

*(tp++) = v4;

*(cp++) = ParticleColor;

}


glEnableClientState(GL_VERTEX_ARRAY);

glEnableClientState(GL_TEXTURE_COORD_ARRAY);

glEnableClientState(GL_COLOR_ARRAY);


glVertexPointer(3, GL_FLOAT, 0, Cloud->VertexBuffer);

glColorPointer(4, GL_FLOAT, 0, Cloud->ColorBuffer);

glTexCoordPointer(2, GL_FLOAT, 0, Cloud->TexCoordBuffer);


glDrawArrays(GL_QUADS, 0, Cloud->Puffs.size() * 4);

NumSprites += Cloud->Puffs.size();

glDisableClientState(GL_VERTEX_ARRAY);

glDisableClientState(GL_TEXTURE_COORD_ARRAY);

glDisableClientState(GL_COLOR_ARRAY);


glDisable(GL_BLEND);

glDisable(GL_TEXTURE_2D);

}

----- Original Message ----- 
From: "Vican, Justin E." <[EMAIL PROTECTED]>
To: "OpenSceneGraph Users" <osg-users@lists.openscenegraph.org>
Sent: Monday, December 03, 2007 5:31 PM
Subject: Re: [osg-users] OSG and OpenGL rendering


> Hi Roman,
> In order to draw OpenGL code in the scene graph, you need to derive a
> class from the osg::Drawable class.  Overload the
> osg::Drawable::drawImplementation method and have it call the
> VolumeClouds::Render method.  You'll have to add any instance of this
> class to an osg::Geode and insert that geode into the scene graph.
>
> To execute the VolumeClouds::Update call at the correct time during
> traversal, you'll have to add an osg::NodeCallback to the geode or an
> osg::Drawable::UpdateCallback to the drawable.  In either case, you'll
> probably have to derive from the callback class and overload a method
to
> make the call to VolumeClouds::Update.
>
> Hope this helps,
> Justin
>
> -----Original Message-----
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] On Behalf Of Roman
> Grigoriev
> Sent: Monday, December 03, 2007 9:12 AM
> To: OpenSceneGraph Users
> Subject: [osg-users] OSG and OpenGL rendering
>
> Hi guys!
> I try to implement Mark Harris cool clouds in osg but nowI try to use
> his
> code that he wrote on pure GL.
> all functions worked but I haven't seen clouds in window. As you see
> clouds
> are not connected to root node
> but I don't know how to use it. Please help me.
>
> here is my code:
> in main()
> osg::ref_ptr<osg::GraphicsContext::Traits> traits = new
> osg::GraphicsContext::Traits;
>
> traits->x = 0;
>
> traits->y = 0;
>
> traits->width = 1280;
>
> traits->height = 1024;
>
> traits->windowDecoration = false;
>
> traits->doubleBuffer = true;
>
> traits->sharedContext = 0;
>
> traits->sampleBuffers = true;
>
> traits->samples=8;
>
> osg::ref_ptr<osg::GraphicsContext> gc =
> osg::GraphicsContext::createGraphicsContext(traits.get());
>
> camera.get()->setGraphicsContext(gc.get());
>
> camera.get()->setViewport(new osg::Viewport(0,0, traits->width,
> traits->height));
>
> GLenum buffer = traits->doubleBuffer ? GL_BACK : GL_FRONT;
>
> camera.get()->setDrawBuffer(buffer);
>
> camera.get()->setReadBuffer(buffer);
>
>
>
>
> viewer.addSlave(camera.get(), true);
>
> root = new osg::Group();
>
> viewer.setSceneData(root);
>
> if (VolumeClouds.Create(30, CloudPlaneSize / 2, CloudPlaneHeight))
> return 1;
>
> Vector3 sunvector,cameraposition;
>
> sunvector.x=1;
>
> sunvector.y=0;
>
> sunvector.z=0;
>
> cameraposition.x=0;
>
> cameraposition.y=0;
>
> cameraposition.z=0;
>
> while(!viewer.done())
>
> {
>
> VolumeClouds.Update(sunvector * SkyRadius, cameraposition);
>
> VolumeClouds.Render(cameraposition, sunvector * SkyRadius);
>
> viewer.frame();
>
> }
>
>
>
>
> _______________________________________________
> osg-users mailing list
> osg-users@lists.openscenegraph.org
>
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.or
> g
> _______________________________________________
> osg-users mailing list
> osg-users@lists.openscenegraph.org
>
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.or
g
> 


_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.or
g
_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to