Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/Samples/CelShading/src/CelShading.cpp @ 5

Last change on this file since 5 was 5, checked in by anonymous, 17 years ago

=hoffentlich gehts jetzt

File size: 5.2 KB
Line 
1/*
2-----------------------------------------------------------------------------
3This source file is part of OGRE
4    (Object-oriented Graphics Rendering Engine)
5For the latest info, see http://www.ogre3d.org/
6
7Copyright (c) 2000-2006 Torus Knot Software Ltd
8Also see acknowledgements in Readme.html
9
10You may use this sample code for anything you like, it is not covered by the
11LGPL like the rest of the engine.
12-----------------------------------------------------------------------------
13*/
14/*
15-----------------------------------------------------------------------------
16Filename:    CelShading.cpp
17Description: Demo of cel-shaded graphics using vertex & fragment programs
18-----------------------------------------------------------------------------
19*/
20
21
22#include "ExampleApplication.h"
23
24SceneNode* rotNode;
25
26// Listener class for frame updates
27class CelShadingListener : public ExampleFrameListener
28{
29protected:
30public:
31    CelShadingListener(RenderWindow* win, Camera* cam)
32        : ExampleFrameListener(win, cam)
33    {
34    }
35
36    bool frameStarted(const FrameEvent& evt)
37    {
38        if( ExampleFrameListener::frameStarted(evt) == false )
39                return false;
40
41        rotNode->yaw(Degree(evt.timeSinceLastFrame * 30));
42        return true;
43    }
44};
45
46// Custom parameter bindings
47#define CUSTOM_SHININESS 1
48#define CUSTOM_DIFFUSE 2
49#define CUSTOM_SPECULAR 3
50
51class CelShadingApplication : public ExampleApplication
52{
53public:
54    CelShadingApplication() { 
55    }
56
57    ~CelShadingApplication() {  }
58
59protected:
60   
61        void createFrameListener(void)
62    {
63                // This is where we instantiate our own frame listener
64        mFrameListener= new CelShadingListener(mWindow, mCamera);
65        mRoot->addFrameListener(mFrameListener);
66
67    }
68   
69
70    // Just override the mandatory create scene method
71    void createScene(void)
72    {
73        // Check capabilities
74                const RenderSystemCapabilities* caps = Root::getSingleton().getRenderSystem()->getCapabilities();
75        if (!caps->hasCapability(RSC_VERTEX_PROGRAM) || !(caps->hasCapability(RSC_FRAGMENT_PROGRAM)))
76        {
77                        OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, "Your card does not support vertex and fragment programs, so cannot "
78                "run this demo. Sorry!", 
79                "CelShading::createScene");
80        }
81
82        // Create a point light
83        Light* l = mSceneMgr->createLight("MainLight");
84        // Accept default settings: point light, white diffuse, just set position
85        // Add light to the scene node
86        rotNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
87        rotNode->createChildSceneNode(Vector3(20,40,50))->attachObject(l);
88
89        Entity *ent = mSceneMgr->createEntity("head", "ogrehead.mesh");
90
91        mCamera->setPosition(20, 0, 100);
92        mCamera->lookAt(0,0,0);
93
94
95        // Set common material, but define custom parameters to change colours
96        // See Example-Advanced.material for how these are finally bound to GPU parameters
97        SubEntity* sub;
98        // eyes
99        sub = ent->getSubEntity(0);
100        sub->setMaterialName("Examples/CelShading");
101        sub->setCustomParameter(CUSTOM_SHININESS, Vector4(35.0f, 0.0f, 0.0f, 0.0f));
102        sub->setCustomParameter(CUSTOM_DIFFUSE, Vector4(1.0f, 0.3f, 0.3f, 1.0f));
103        sub->setCustomParameter(CUSTOM_SPECULAR, Vector4(1.0f, 0.6f, 0.6f, 1.0f));
104        // skin
105        sub = ent->getSubEntity(1);
106        sub->setMaterialName("Examples/CelShading");
107        sub->setCustomParameter(CUSTOM_SHININESS, Vector4(10.0f, 0.0f, 0.0f, 0.0f));
108        sub->setCustomParameter(CUSTOM_DIFFUSE, Vector4(0.0f, 0.5f, 0.0f, 1.0f));
109        sub->setCustomParameter(CUSTOM_SPECULAR, Vector4(0.3f, 0.5f, 0.3f, 1.0f));
110        // earring
111        sub = ent->getSubEntity(2);
112        sub->setMaterialName("Examples/CelShading");
113        sub->setCustomParameter(CUSTOM_SHININESS, Vector4(25.0f, 0.0f, 0.0f, 0.0f));
114        sub->setCustomParameter(CUSTOM_DIFFUSE, Vector4(1.0f, 1.0f, 0.0f, 1.0f));
115        sub->setCustomParameter(CUSTOM_SPECULAR, Vector4(1.0f, 1.0f, 0.7f, 1.0f));
116        // teeth
117        sub = ent->getSubEntity(3);
118        sub->setMaterialName("Examples/CelShading");
119        sub->setCustomParameter(CUSTOM_SHININESS, Vector4(20.0f, 0.0f, 0.0f, 0.0f));
120        sub->setCustomParameter(CUSTOM_DIFFUSE, Vector4(1.0f, 1.0f, 0.7f, 1.0f));
121        sub->setCustomParameter(CUSTOM_SPECULAR, Vector4(1.0f, 1.0f, 1.0f, 1.0f));
122
123        // Add entity to the root scene node
124        mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(ent);
125
126        mWindow->getViewport(0)->setBackgroundColour(ColourValue::White);
127    }
128};
129
130
131
132#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
133#define WIN32_LEAN_AND_MEAN
134#include "windows.h"
135#endif
136
137#ifdef __cplusplus
138extern "C" {
139#endif
140
141#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
142INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT )
143#else
144int main(int argc, char **argv)
145#endif
146{
147    // Create application object
148    CelShadingApplication app;
149
150    try {
151        app.go();
152    } catch( Exception& e ) {
153#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
154        MessageBox( NULL, e.getFullDescription().c_str(), "An exception has occured!", MB_OK | MB_ICONERROR | MB_TASKMODAL);
155#else
156        std::cerr << "An exception has occured: " << e.getFullDescription();
157#endif
158    }
159
160
161    return 0;
162}
163
164#ifdef __cplusplus
165}
166#endif
Note: See TracBrowser for help on using the repository browser.