Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/Tests/PlayPen/src/WindowEmbedding.cpp @ 3

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

=update

File size: 5.5 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
10This program is free software; you can redistribute it and/or modify it under
11the terms of the GNU Lesser General Public License as published by the Free Software
12Foundation; either version 2 of the License, or (at your option) any later
13version.
14
15This program is distributed in the hope that it will be useful, but WITHOUT
16ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
18
19You should have received a copy of the GNU Lesser General Public License along with
20this program; if not, write to the Free Software Foundation, Inc., 59 Temple
21Place - Suite 330, Boston, MA 02111-1307, USA, or go to
22http://www.gnu.org/copyleft/lesser.txt.
23
24You may alternatively use this source under the terms of a specific version of
25the OGRE Unrestricted License provided you have obtained such a license from
26Torus Knot Software Ltd.
27-----------------------------------------------------------------------------
28*/
29/*
30-----------------------------------------------------------------------------
31Filename:    WindowEmbedding.cpp
32Description: Stuff your windows full of OGRE
33-----------------------------------------------------------------------------
34*/
35#include "Ogre.h"
36
37using namespace Ogre;
38
39void setupResources(void)
40{
41        // Load resource paths from config file
42        ConfigFile cf;
43        cf.load("resources.cfg");
44
45        // Go through all sections & settings in the file
46        ConfigFile::SectionIterator seci = cf.getSectionIterator();
47
48        String secName, typeName, archName;
49        while (seci.hasMoreElements())
50        {
51                secName = seci.peekNextKey();
52                ConfigFile::SettingsMultiMap *settings = seci.getNext();
53                ConfigFile::SettingsMultiMap::iterator i;
54                for (i = settings->begin(); i != settings->end(); ++i)
55                {
56                        typeName = i->first;
57                        archName = i->second;
58                        ResourceGroupManager::getSingleton().addResourceLocation(
59                                archName, typeName, secName);
60                }
61        }
62}
63
64
65//---------------------------------------------------------------------
66// Windows Test
67//---------------------------------------------------------------------
68#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
69#include "windows.h"
70
71RenderWindow* renderWindow = 0;
72bool winActive = false;
73bool winSizing = false;
74
75LRESULT CALLBACK TestWndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
76{
77        if (uMsg == WM_CREATE)
78        {
79                return 0;
80        }
81
82
83        if (!renderWindow)
84                return DefWindowProc(hWnd, uMsg, wParam, lParam);
85
86        switch( uMsg )
87        {
88        case WM_ACTIVATE:
89                winActive = (LOWORD(wParam) != WA_INACTIVE);
90                break;
91
92        case WM_ENTERSIZEMOVE:
93                winSizing = true;
94                break;
95
96        case WM_EXITSIZEMOVE:
97                renderWindow->windowMovedOrResized();
98                renderWindow->update();
99                winSizing = false;
100                break;
101
102        case WM_MOVE:
103        case WM_SIZE:
104                if (!winSizing)
105                        renderWindow->windowMovedOrResized();
106                break;
107
108        case WM_GETMINMAXINFO:
109                // Prevent the window from going smaller than some min size
110                ((MINMAXINFO*)lParam)->ptMinTrackSize.x = 100;
111                ((MINMAXINFO*)lParam)->ptMinTrackSize.y = 100;
112                break;
113
114        case WM_CLOSE:
115                renderWindow->destroy(); // cleanup and call DestroyWindow
116                PostQuitMessage(0); 
117                return 0;
118        case WM_PAINT:
119                if (!winSizing)
120                {
121                        renderWindow->update();
122                        return 0;
123                }
124                break;
125        }
126
127        return DefWindowProc( hWnd, uMsg, wParam, lParam );
128}
129
130
131INT WINAPI EmbeddedMain( HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT )
132{
133        try 
134        {
135                // Create a new window
136
137                // Style & size
138                DWORD dwStyle = WS_VISIBLE | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_OVERLAPPEDWINDOW;
139
140                // Register the window class
141                WNDCLASS wc = { 0, TestWndProc, 0, 0, hInst,
142                        LoadIcon(0, IDI_APPLICATION), LoadCursor(NULL, IDC_ARROW),
143                        (HBRUSH)GetStockObject(BLACK_BRUSH), 0, "TestWnd" };
144                RegisterClass(&wc);
145
146                HWND hwnd = CreateWindow("TestWnd", "Test embedding", dwStyle,
147                                0, 0, 800, 600, 0, 0, hInst, 0);
148
149                Root root("", "");
150
151                root.loadPlugin("RenderSystem_GL");
152                //root.loadPlugin("RenderSystem_Direct3D9");
153                root.loadPlugin("Plugin_ParticleFX");
154                root.loadPlugin("Plugin_CgProgramManager");
155
156                // select first renderer & init with no window
157                root.setRenderSystem(*(root.getAvailableRenderers()->begin()));
158                root.initialise(false);
159
160                // create first window manually
161                NameValuePairList options;
162                options["externalWindowHandle"] = 
163                        StringConverter::toString((size_t)hwnd);
164
165                renderWindow = root.createRenderWindow("embedded", 800, 600, false, &options);
166
167                setupResources();
168                ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
169
170                SceneManager *scene = root.createSceneManager(Ogre::ST_GENERIC, "default");
171
172
173                Camera *cam = scene->createCamera("cam");
174
175
176                Viewport* vp = renderWindow->addViewport(cam);
177                vp->setBackgroundColour(Ogre::ColourValue(0.5, 0.5, 0.7));
178                cam->setAutoAspectRatio(true);
179                cam->setPosition(0,0,300);
180                cam->setDirection(0,0,-1);
181
182                Entity* e = scene->createEntity("1", "ogrehead.mesh");
183                scene->getRootSceneNode()->createChildSceneNode()->attachObject(e);
184                Light* l = scene->createLight("l");
185                l->setPosition(300, 100, -100);
186
187                // message loop
188                MSG msg;
189                while(GetMessage(&msg, NULL, 0, 0 ) != 0)
190                { 
191                        TranslateMessage(&msg); 
192                        DispatchMessage(&msg); 
193                } 
194
195        } 
196        catch( Exception& e ) 
197        {
198                MessageBox( NULL, e.getFullDescription().c_str(), 
199                        "An exception has occured!", MB_OK | MB_ICONERROR | MB_TASKMODAL);
200        }
201
202
203        return 0;
204}
205
206#endif
207
208
209
210
Note: See TracBrowser for help on using the repository browser.