http://www.ogre3d.org/docs/manual/manual_21.html#SEC117
But I don't see the effect in scene.Just the mesh is grey.
If I don't use glsl,it is normal.
If I use hlsl,cg,it is also normal.
Anybody can solve the problem.
By the way,I use ogre1.70,NVIDIA GeForce 9500GT,Intel Pentium Dual CPU,windows xp .
I set up DX9,but don't set up openGL.
my code:
Code: Select all
#include "ExampleApplication.h"
using namespace Ogre;
class MyListener : public ExampleFrameListener
{
public:
SceneManager* mSceneMgr;
public:
MyListener(SceneManager *sceneMgr, RenderWindow* win, Camera* cam)
: ExampleFrameListener(win, cam)
, mSceneMgr(sceneMgr)
{
}
bool frameStarted(const FrameEvent& evt)
{
if (!ExampleFrameListener::frameStarted(evt))
return false;
return true;
}
virtual bool processUnbufferedKeyInput(const FrameEvent& evt)
{
return ExampleFrameListener::processUnbufferedKeyInput(evt);
}
};
class testEffect : public ExampleApplication
{
public:
testEffect ()
{
}
~testEffect ()
{
}
void createScene(void)
{
// Ambient
mSceneMgr->setAmbientLight( ColourValue( 0.1, 0.1, 0.1) );
mSceneMgr->setSkyBox(true, "Examples/CloudyNoonSkyBox");
// camera
mCamera->setPosition(Vector3(0,200,200));
mCamera->lookAt(Vector3(0,0,0));
// light
Vector3 lightdir(0, -1, -1);
lightdir.normalise();
Light* l = mSceneMgr->createLight("tstLight");
l->setType(Light::LT_DIRECTIONAL);
l->setDirection(lightdir);
l->setDiffuseColour(ColourValue::White);
l->setSpecularColour(ColourValue(0.1, 0.1, 0.1));
// ground
MeshManager::getSingleton().createPlane("ground", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
Plane(Vector3::UNIT_Y, 0), 1000, 1000, 20, 20, true, 1, 6, 6, Vector3::UNIT_Z);
Entity* ground = mSceneMgr->createEntity("Ground", "ground");
ground->setMaterialName("Examples/Rockwall");
ground->setCastShadows(false);
mSceneMgr->getRootSceneNode()->attachObject(ground);
// robot
Entity* robot = mSceneMgr->createEntity("robot", "robot.mesh");
SceneNode* robotNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("robotnode",Vector3(0, 0, 0));
robotNode->attachObject(robot);
robot->setMaterialName("test_robot");
}
void createFrameListener(void)
{
mFrameListener = new MyListener(mSceneMgr, mWindow, mCamera);
mRoot->addFrameListener(mFrameListener);
}
public:
};
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
#define WIN32_LEAN_AND_MEAN
#include "windows.h"
INT WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, INT)
#else
int main(int argc, char *argv[])
#endif
{
try{
testEffect app;
app.go();
}catch (Ogre::Exception& e){
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
MessageBoxA(NULL, e.getFullDescription().c_str(), "An exception has occurred!", MB_ICONERROR | MB_TASKMODAL);
#else
std::cerr << "An exception has occurred: " << e.getFullDescription().c_str() << std::endl;
#endif
}
return 0;
}
Code: Select all
fragment_program myFragmentShader glsl
{
source example.frag
}
material test_robot
{
technique
{
pass
{
fragment_program_ref myFragmentShader
{
param_named diffuseMap int 0
}
texture_unit
{
texture r2skin.jpg 2d
}
}
}
}
Code: Select all
varying vec2 UV;
uniform sampler2D diffuseMap;
void main(void)
{
gl_FragColor = texture2D(diffuseMap, UV);
}