Today I tried to code the "Lights, cameras and shadows" part in the Ogre 1.10 tutorial. Everything is working fine as long I have the Ambiantlight turned on. When I set its values to 0 and implement the spotlight I get just a black screen, but I expected a spotlight viewing the ninja. (Note: It doesn't matter which type of light I use. The screen stays black. It also doesn't matter if I use different colors for defuseLight.) I searched the internet for this bug, but couldn't find anything. I also looked at the debug messages, but also without success. I don't know what went wrong there, so I hope you can help me.
One more thing: The tutorial is using sometimes this: Ogre::Vector3::UNIT_Z. Can you explain me what this means? I don't understand the explanation in the tutorial quite well.
Here is my Code:
Code: Select all
#include <Ogre.h>
#include <OgreApplicationContext.h>
#include <iostream>
Ogre::SceneManager* sceneManager;
Ogre::SceneNode* cameraSceneNode;
Ogre::Camera* camera;
Ogre::Viewport* viewport;
Ogre::Entity* ninjaEntity;
Ogre::Entity* groundEntity;
Ogre::Light* spotLight;
Ogre::SceneNode* spotLightSceneNode;
class TestApp : public OgreBites::ApplicationContext, public OgreBites::InputListener
{
public:
TestApp();
void setup();
bool keyPressed(const OgreBites::KeyboardEvent& evt);
};
//! [constructor]
TestApp::TestApp() : OgreBites::ApplicationContext("MyTestApp")
{
addInputListener(this);
}
//! [constructor]
//! [key_handler]
bool TestApp::keyPressed(const OgreBites::KeyboardEvent& evt)
{
if (evt.keysym.sym == SDLK_ESCAPE)
{
getRoot()->queueEndRendering();
}
return true;
}
//! [key_handler]
//! [setup]
void TestApp::setup(void)
{
//Ogre::LogManager::getSingleton().setLogDetail(Ogre::LL_LOW);
OgreBites::ApplicationContext::setup();
sceneManager = getRoot()->createSceneManager(Ogre::ST_GENERIC);
sceneManager->setAmbientLight(Ogre::ColourValue(0, 0, 0));
sceneManager->setShadowTechnique(Ogre::ShadowTechnique::SHADOWTYPE_STENCIL_MODULATIVE);
cameraSceneNode = sceneManager->getRootSceneNode()->createChildSceneNode();
camera = sceneManager->createCamera("MainCamera");
cameraSceneNode->setPosition(200, 300, 400);
cameraSceneNode->lookAt(Ogre::Vector3(0, 0, 0), Ogre::Node::TransformSpace::TS_WORLD);
camera->setNearClipDistance(5);
cameraSceneNode->attachObject(camera);
viewport = getRenderWindow()->addViewport(camera);
viewport->setBackgroundColour(Ogre::ColourValue(0, 0, 0));
camera->setAspectRatio(Ogre::Real(viewport->getActualWidth()) / Ogre::Real(viewport->getActualHeight()));
ninjaEntity = sceneManager->createEntity("ninja.mesh");
ninjaEntity->setCastShadows(true);
sceneManager->getRootSceneNode()->createChildSceneNode()->attachObject(ninjaEntity);
Ogre::Plane plane(Ogre::Vector3::UNIT_Y, 0);
Ogre::MeshManager::getSingleton().createPlane(
"ground",
Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
plane,
1500, 1500, 20, 20,
true,
1, 5, 5,
Ogre::Vector3::UNIT_Z
);
groundEntity = sceneManager->createEntity("ground");
sceneManager->getRootSceneNode()->createChildSceneNode()->attachObject(groundEntity);
groundEntity->setCastShadows(false);
groundEntity->setMaterialName("Examples/Rockwall");
spotLight = sceneManager->createLight("spotLight");
spotLight->setDiffuseColour(1.0, 1.0, 1.0);
spotLight->setSpecularColour(1.0, 1.0, 1.0);
spotLight->setType(Ogre::Light::LT_SPOTLIGHT);
spotLight->setDirection(Ogre::Vector3::NEGATIVE_UNIT_Z);
spotLightSceneNode = sceneManager->getRootSceneNode()->createChildSceneNode();
spotLightSceneNode->attachObject(spotLight);
spotLightSceneNode->setDirection(-1, -1, 0);
spotLightSceneNode->setPosition(Ogre::Vector3(200, 200, 0));
spotLight->setSpotlightRange(Ogre::Degree(35), Ogre::Degree(50));
}
//! [setup]
//! [main]
int main(int argc, char *argv[])
{
TestApp app;
app.initApp();
app.getRoot()->startRendering();
app.closeApp();
return 0;
}
//! [main]
Regards,
Daniel