1 /*
2 -----------------------------------------------------------------------------
3 This source file is part of OGRE
4 (Object-oriented Graphics Rendering Engine)
5 For the latest info, see http://www.ogre3d.org/
6
7 Copyright (c) 2000-2013 Torus Knot Software Ltd
8
9 Permission is hereby granted, free of charge, to any person obtaining a copy
10 of this software and associated documentation files (the "Software"), to deal
11 in the Software without restriction, including without limitation the rights
12 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 copies of the Software, and to permit persons to whom the Software is
14 furnished to do so, subject to the following conditions:
15
16 The above copyright notice and this permission notice shall be included in
17 all copies or substantial portions of the Software.
18
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 THE SOFTWARE.
26 -----------------------------------------------------------------------------
27 */
28 /*
29 -----------------------------------------------------------------------------
30 Filename: WindowEmbedding.cpp
31 Description: Stuff your windows full of OGRE
32 -----------------------------------------------------------------------------
33 */
34 #include "Ogre.h"
35
36 using namespace Ogre;
37
38 void setupResources(void); // Just a prototype
39
setupResources(void)40 void setupResources(void)
41 {
42 // Load resource paths from config file
43 ConfigFile cf;
44 cf.load("resources.cfg");
45
46 // Go through all sections & settings in the file
47 ConfigFile::SectionIterator seci = cf.getSectionIterator();
48
49 String secName, typeName, archName;
50 while (seci.hasMoreElements())
51 {
52 secName = seci.peekNextKey();
53 ConfigFile::SettingsMultiMap *settings = seci.getNext();
54 ConfigFile::SettingsMultiMap::iterator i;
55 for (i = settings->begin(); i != settings->end(); ++i)
56 {
57 typeName = i->first;
58 archName = i->second;
59 ResourceGroupManager::getSingleton().addResourceLocation(
60 archName, typeName, secName);
61 }
62 }
63 }
64
65
66 //---------------------------------------------------------------------
67 // Windows Test
68 //---------------------------------------------------------------------
69 #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
70 #include "windows.h"
71
72 RenderWindow* renderWindow = 0;
73 bool winActive = false;
74 bool winSizing = false;
75
TestWndProc(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam)76 LRESULT CALLBACK TestWndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
77 {
78 if (uMsg == WM_CREATE)
79 {
80 return 0;
81 }
82
83
84 if (!renderWindow)
85 return DefWindowProc(hWnd, uMsg, wParam, lParam);
86
87 switch( uMsg )
88 {
89 case WM_ACTIVATE:
90 winActive = (LOWORD(wParam) != WA_INACTIVE);
91 break;
92
93 case WM_ENTERSIZEMOVE:
94 winSizing = true;
95 break;
96
97 case WM_EXITSIZEMOVE:
98 renderWindow->windowMovedOrResized();
99 renderWindow->update();
100 winSizing = false;
101 break;
102
103 case WM_MOVE:
104 case WM_SIZE:
105 if (!winSizing)
106 renderWindow->windowMovedOrResized();
107 break;
108
109 case WM_GETMINMAXINFO:
110 // Prevent the window from going smaller than some min size
111 ((MINMAXINFO*)lParam)->ptMinTrackSize.x = 100;
112 ((MINMAXINFO*)lParam)->ptMinTrackSize.y = 100;
113 break;
114
115 case WM_CLOSE:
116 renderWindow->destroy(); // cleanup and call DestroyWindow
117 PostQuitMessage(0);
118 return 0;
119 case WM_PAINT:
120 if (!winSizing)
121 {
122 renderWindow->update();
123 return 0;
124 }
125 break;
126 }
127
128 return DefWindowProc( hWnd, uMsg, wParam, lParam );
129 }
130
131
EmbeddedMain(HINSTANCE hInst,HINSTANCE,LPSTR strCmdLine,INT)132 INT WINAPI EmbeddedMain( HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT )
133 {
134 try
135 {
136 // Create a new window
137
138 // Style & size
139 DWORD dwStyle = WS_VISIBLE | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_OVERLAPPEDWINDOW;
140
141 // Register the window class
142 WNDCLASS wc = { 0, TestWndProc, 0, 0, hInst,
143 LoadIcon(0, IDI_APPLICATION), LoadCursor(NULL, IDC_ARROW),
144 (HBRUSH)GetStockObject(BLACK_BRUSH), 0, "TestWnd" };
145 RegisterClass(&wc);
146
147 HWND hwnd = CreateWindow("TestWnd", "Test embedding", dwStyle,
148 0, 0, 800, 600, 0, 0, hInst, 0);
149
150 Root root("", "");
151
152 root.loadPlugin("RenderSystem_GL");
153 //root.loadPlugin("RenderSystem_Direct3D9");
154 root.loadPlugin("Plugin_ParticleFX");
155 root.loadPlugin("Plugin_CgProgramManager");
156
157 // select first renderer & init with no window
158 root.setRenderSystem(*(root.getAvailableRenderers().begin()));
159 root.initialise(false);
160
161 // create first window manually
162 NameValuePairList options;
163 options["externalWindowHandle"] =
164 StringConverter::toString((size_t)hwnd);
165
166 renderWindow = root.createRenderWindow("embedded", 800, 600, false, &options);
167
168 setupResources();
169 ResourceGroupManager::getSingleton().initialiseAllResourceGroups();
170
171 SceneManager *scene = root.createSceneManager(Ogre::ST_GENERIC, "default");
172
173
174 Camera *cam = scene->createCamera("cam");
175
176
177 Viewport* vp = renderWindow->addViewport(cam);
178 vp->setBackgroundColour(Ogre::ColourValue(0.5, 0.5, 0.7));
179 cam->setAutoAspectRatio(true);
180 cam->setPosition(0,0,300);
181 cam->setDirection(0,0,-1);
182
183 Entity* e = scene->createEntity("1", "ogrehead.mesh");
184 scene->getRootSceneNode()->createChildSceneNode()->attachObject(e);
185 Light* l = scene->createLight("l");
186 l->setPosition(300, 100, -100);
187
188 // message loop
189 MSG msg;
190 while(GetMessage(&msg, NULL, 0, 0 ) != 0)
191 {
192 TranslateMessage(&msg);
193 DispatchMessage(&msg);
194 }
195
196 }
197 catch( Exception& e )
198 {
199 MessageBox( NULL, e.getFullDescription().c_str(),
200 "An exception has occurred!", MB_OK | MB_ICONERROR | MB_TASKMODAL);
201 }
202
203
204 return 0;
205 }
206
207 #endif
208
209
210
211
212