try texMoon->setLit(true) ?
Cheers
/Marcus
Sajjadul Islam wrote:
> Hello Carsten,
>
> Sorry for attaching the wrong code snippet.
>
> I have found out that if i do not load the texture, then the point
> light effect is visible,
> but with texture it is not,
>
> How to get around with that?
>
>
> Regards,
> Sajjad
>
> N.B - to compile you have to create a .depend file
>
> ------------------------------------------------------------------------
>
> #ifndef BASIC_H
> #define BASIC_H
>
> #include <iostream>
>
> #include <OpenSG/OSGConfig.h>
> #include <OpenSG/OSGGLUT.h>
> #include <OpenSG/OSGSimpleGeometry.h>
> #include <OpenSG/OSGGLUTWindow.h>
> #include <OpenSG/OSGSimpleSceneManager.h>
> #include <OpenSG/OSGSimpleAttachments.h>
> #include <OpenSG/OSGRefPtr.h>
> #include <OpenSG/OSGSimpleTexturedMaterial.h>
> #include <OpenSG/OSGImage.h>
> #include <OpenSG/OSGPointLight.h>
> #include <OpenSG/OSGSpotLight.h>
>
> OSG_USING_NAMESPACE
>
> using namespace std;
>
>
>
> #endif
>
> ------------------------------------------------------------------------
>
> #include "Basic.h"
>
>
> //The SimpleSceneManager is a useful class which helps us to
> //manage simple configurations. It will be discussed in detail later on
> SimpleSceneManager *mgr;
>
> //declare some global Transformation pointer
> TransformPtr earthTransform,moonTransform;
>
>
> //Declare global Matrix variables that will be manipulated very often
> Matrix p,m;
> //m - is related to the moon transformation
> //p - is related to the earth transformation
>
> //we have a forward declaration here, just to have a better order
> //of codepieces
> int setupGLUT( int *argc, char *argv[] );
> void moveNode(NodePtr, NodePtr, int);
> void motion(int,int);
> void mouse(int,int,int,int);
> void reshape(int,int);
> void display();
> void keyboard(unsigned char, int,int);
>
> NodePtr createPlanet(void);
>
>
> NodePtr createPlanet(void)
> {
> //crzeate the sun,moon and the earth geometry
> GeometryNodePtr sun = GeometryNodePtr::create();
> //here the sign = refers to the core which is the geometry
> sun = makeSphereGeo(3,6);
>
> GeometryNodePtr earth = GeometryNodePtr::create();
> earth = makeSphereGeo(3,3);
>
> GeometryNodePtr moon = GeometryNodePtr::create();
> moon = makeSphereGeo(2,1);
>
>
> //load the image that we want to use
> //as a texture for earth
> ImagePtr imageEarth = Image::create();
> imageEarth->read("earthmap1k.jpg");
>
>
> //now we create a texture that will hold the image
> SimpleTexturedMaterialPtr texEarth = SimpleTexturedMaterial::create();
> beginEditCP(texEarth);
> texEarth->setImage(imageEarth);
> texEarth->setDiffuse(Color3f(1,0,0));
> endEditCP(texEarth);
>
> //now wrap the texture around the earth
> beginEditCP(earth, Geometry::MaterialFieldMask);
> earth->setMaterial(texEarth);
> endEditCP(earth, Geometry::MaterialFieldMask);
>
>
>
> //load the moon image image that
> //we want to use
> ImagePtr imageMoon = Image::create();
> //now read the image for the moon
> imageMoon->read("moonmap.jpg");
>
>
> //create a texture to hold the image of the moon
> SimpleTexturedMaterialPtr texMoon = SimpleTexturedMaterial::create();
>
> beginEditCP(texMoon);
> texMoon->setImage(imageMoon);
> //texMoon->setDiffuse(Color3f(1,0,0));
> endEditCP(texMoon);
>
> //now wrap the texture around the moon
> beginEditCP(moon, Geometry::MaterialFieldMask);
> moon->setMaterial(texMoon);
> endEditCP(moon, Geometry::MaterialFieldMask);
>
>
> //load the sun image that we want to use
> ImagePtr imageSun = Image::create();
>
> //now read the image for the sun
> imageSun->read("sunmap.jpg");
>
>
> //create a texture to hold the image for the sun
> SimpleTexturedMaterialPtr texSun = SimpleTexturedMaterial::create();
>
> //set the texture to the image read
> beginEditCP(texSun);
> texSun->setImage(imageSun);
> endEditCP(texSun);
>
> //now wrap the texture around the sun
> beginEditCP(sun, Geometry::MaterialFieldMask);
> sun->setMaterial(texSun);
> endEditCP(sun, Geometry::MaterialFieldMask);
>
> //we will create the point light
> PointLightPtr pLight = PointLight::create();
>
> beginEditCP(pLight, PointLight::PositionFieldMask |
> PointLight::ConstantAttenuationFieldMask |
> PointLight::LinearAttenuationFieldMask |
> PointLight::QuadraticAttenuationFieldMask |
> PointLight::DiffuseFieldMask |
> PointLight::AmbientFieldMask |
> PointLight::SpecularFieldMask |
> PointLight::BeaconFieldMask);
>
> pLight->setPosition(Pnt3f(0,0,0));
>
> //set the attebuation parameters
> pLight->setConstantAttenuation(0);
> pLight->setLinearAttenuation(0);
> pLight->setQuadraticAttenuation(0);
>
>
>
> //set the color information
> pLight->setDiffuse(Color4f(1,1,1,1));
> pLight->setAmbient(Color4f(0.2,0.2,0.2,1));
> pLight->setSpecular(Color4f(1,1,1,1));
>
>
> //have to create some beacon
> //will check out that later
> pLight->setBeacon(sun.node());
>
> endEditCP(pLight, PointLight::PositionFieldMask |
>
> PointLight::ConstantAttenuationFieldMask |
>
> PointLight::LinearAttenuationFieldMask |
>
> PointLight::QuadraticAttenuationFieldMask |
> PointLight::DiffuseFieldMask
> |
> PointLight::AmbientFieldMask
> |
> PointLight::SpecularFieldMask
> |
> PointLight::BeaconFieldMask);
>
> NodePtr pLightNode = Node::create();
>
>
> beginEditCP(pLightNode, Node::CoreFieldMask |
>
> Node::ChildrenFieldMask);
> pLightNode->setCore(pLight);
> pLightNode->addChild(sun.node());
> endEditCP(pLightNode, Node::CoreFieldMask |
>
> Node::ChildrenFieldMask);
>
>
> NodePtr earthTransformNode = Node::create();
> NodePtr moonTransformNode = Node::create();
>
>
> //instantiate the transformation pointer
> //that have been declared globally
> earthTransform = Transform::create();
> moonTransform = Transform::create();
>
> m.setIdentity();
> p.setIdentity();
>
>
> //set the matrix to the transformation poiner related to the earth
> beginEditCP(earthTransform, Transform::MatrixFieldMask);
> earthTransform->setMatrix(p);
> endEditCP(earthTransform, Transform::MatrixFieldMask);
>
>
> //set the matrix to the transformation pointer related to the moon
> beginEditCP(moonTransform, Transform::MatrixFieldMask);
> moonTransform->setMatrix(m);
> endEditCP(moonTransform, Transform::MatrixFieldMask);
>
>
>
> //insert the transformation cores
> //into the approapriate nodes
> beginEditCP(earthTransformNode, Node::CoreFieldMask |
> Node::ChildrenFieldMask);
> earthTransformNode->setCore(earthTransform);
> earthTransformNode->addChild(earth.node());
> endEditCP(earthTransformNode, Node::CoreFieldMask |
> Node::ChildrenFieldMask);
>
>
>
> beginEditCP(moonTransformNode, Node::CoreFieldMask |
> Node::ChildrenFieldMask);
> moonTransformNode->setCore(moonTransform);
> moonTransformNode->addChild(moon.node());
> endEditCP(moonTransformNode, Node::CoreFieldMask |
> Node::ChildrenFieldMask);
>
>
> //add the earth to the sun
> beginEditCP(sun.node(), Node::ChildrenFieldMask);
> sun.node()->addChild(earthTransformNode);
> endEditCP(sun.node(), Node::ChildrenFieldMask);
>
>
> //add the moon to the earth
> beginEditCP(earth.node(), Node::ChildrenFieldMask);
> earth.node()->addChild(moonTransformNode);
> endEditCP(earth.node(), Node::ChildrenFieldMask);
>
>
> NodePtr root = Node::create();
>
> beginEditCP(root, Node::ChildrenFieldMask |
> Node::CoreFieldMask);
> root->setCore(Group::create());
> root->addChild(pLightNode);
> endEditCP(root, Node::ChildrenFieldMask |
> Node::CoreFieldMask);
> //LETS SEE IF WE ARE DONE
> return root;
> }
>
>
> int main(int argc, char **argv)
> {
> osgInit(argc,argv);
>
> //create the GLUTWindow which is same for most of the application
> int winid = setupGLUT(&argc,argv);
>
> GLUTWindowPtr gwin = GLUTWindow::create();
>
> gwin->setId(winid);
> gwin->init();
>
> //Create and setup the SSM
> mgr = new SimpleSceneManager();
> mgr->setWindow(gwin);
> mgr->setRoot(createPlanet());
>
> //set the default headlight
> mgr->setHeadlight(false);
> mgr->showAll();
>
>
> Navigator *nav = mgr->getNavigator();
> nav->setFrom(nav->getFrom() + Vec3f(5,15,0));
>
> //give control to the glut mainloop
> glutMainLoop();
>
> }
>
>
>
> //react to the keys
> void keyboard(unsigned char k,int x,int y)
> {
> switch(k)
> {
> case 27:
> {
> OSG::osgExit();
> exit(0);
> }
> break;
> }
> }
>
>
> //react the mouse motions with pressed buttons
> void motion(int x, int y)
> {
> mgr->mouseMove(x,y);
> glutPostRedisplay();
> }
>
> //react to mouse button presses
> void mouse(int button,int state, int x,int y)
> {
> if(state)
> mgr->mouseButtonRelease(button,x,y);
> else
> mgr->mouseButtonPress(button,x,y);
>
> glutPostRedisplay();
> }
>
>
>
> // react to size changes
> void reshape(int w, int h)
> {
> mgr->resize(w, h);
> glutPostRedisplay();
> }
> // just redraw our scene if this GLUT callback is invoked
> void display(void)
> {
>
> //get the elapsed time since the application started
> Real32 time = glutGet(GLUT_ELAPSED_TIME);
>
>
> //create the quaternion and describe the rotation
> //of arth around the sun
> Quaternion earthRot =
> Quaternion(Vec3f(0,1,0),time/static_cast<float>(7500));
>
> //now set the rotation of the moon around earth
> Quaternion moonRot =
> Quaternion(Vec3f(0,1,0),time/static_cast<float>(5000));
>
> //make the matrix idintity
> p.setIdentity();
> m.setIdentity();
>
> Matrix t,r,i;
>
> //the first rotation is around its own axis
> i.setTransform(earthRot);
>
> //then i am translating towards the x-axis
> t.setTransform(Vec3f(20,0,0));
>
> //then i am rotating the earth around the sun
> r.setTransform(earthRot);
>
> t.mult(i);
> r.mult(t);
>
> p.setValue(r);
>
> i.setTransform(moonRot);
> t.setTransform(Vec3f(8,0,0));
> r.setTransform(moonRot);
>
> t.mult(i);
> r.mult(t);
>
>
>
> m.setValue(r);
>
> beginEditCP(earthTransform, Transform::MatrixFieldMask);
> earthTransform->setMatrix(p);
> endEditCP(earthTransform, Transform::MatrixFieldMask);
>
>
> beginEditCP(moonTransform, Transform::MatrixFieldMask);
> moonTransform->setMatrix(m);
> endEditCP(moonTransform, Transform::MatrixFieldMask);
>
>
> mgr->redraw();
> }
> //The GLUT subsystem is set up here. This is very similar to other GLUT
> //applications. If you have worked with GLUT before, you may have the
> //feeling of meeting old friends again, if you have not used GLUT before
> //that is no problem. GLUT will be introduced briefly on the next section
> int setupGLUT(int *argc, char *argv[])
> {
> glutInit(argc, argv);
> glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
> int winid = glutCreateWindow("Planetory System");
>
> // register the GLUT callback functions
> glutDisplayFunc(display);
> glutIdleFunc(display);
> glutReshapeFunc(reshape);
> glutMotionFunc(motion);
> glutMouseFunc(mouse);
> glutKeyboardFunc(keyboard);
> return winid;
>
> }
>
>
>
> ------------------------------------------------------------------------
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by DB2 Express
> Download DB2 Express C - the FREE version of DB2 express and take
> control of your XML. No limits. Just data. Click to get it now.
> http://sourceforge.net/powerbar/db2/
> ------------------------------------------------------------------------
>
> _______________________________________________
> Opensg-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/opensg-users
>
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Opensg-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensg-users