aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/irrlicht-1.8/examples/14.Win32Window/main.cpp
diff options
context:
space:
mode:
authorDavid Walter Seikel2013-01-13 18:54:10 +1000
committerDavid Walter Seikel2013-01-13 18:54:10 +1000
commit959831f4ef5a3e797f576c3de08cd65032c997ad (patch)
treee7351908be5995f0b325b2ebeaa02d5a34b82583 /libraries/irrlicht-1.8/examples/14.Win32Window/main.cpp
parentAdd info about changes to Irrlicht. (diff)
downloadSledjHamr-959831f4ef5a3e797f576c3de08cd65032c997ad.zip
SledjHamr-959831f4ef5a3e797f576c3de08cd65032c997ad.tar.gz
SledjHamr-959831f4ef5a3e797f576c3de08cd65032c997ad.tar.bz2
SledjHamr-959831f4ef5a3e797f576c3de08cd65032c997ad.tar.xz
Remove damned ancient DOS line endings from Irrlicht. Hopefully I did not go overboard.
Diffstat (limited to '')
-rw-r--r--libraries/irrlicht-1.8/examples/14.Win32Window/main.cpp502
1 files changed, 251 insertions, 251 deletions
diff --git a/libraries/irrlicht-1.8/examples/14.Win32Window/main.cpp b/libraries/irrlicht-1.8/examples/14.Win32Window/main.cpp
index 33d111e..e43357b 100644
--- a/libraries/irrlicht-1.8/examples/14.Win32Window/main.cpp
+++ b/libraries/irrlicht-1.8/examples/14.Win32Window/main.cpp
@@ -1,251 +1,251 @@
1/** Example 014 Win32 Window 1/** Example 014 Win32 Window
2 2
3This example only runs under MS Windows and demonstrates that Irrlicht can 3This example only runs under MS Windows and demonstrates that Irrlicht can
4render inside a win32 window. MFC and .NET Windows.Forms windows are possible, 4render inside a win32 window. MFC and .NET Windows.Forms windows are possible,
5too. 5too.
6 6
7In the beginning, we create a windows window using the windows API. I'm not 7In the beginning, we create a windows window using the windows API. I'm not
8going to explain this code, because it is windows specific. See the MSDN or a 8going to explain this code, because it is windows specific. See the MSDN or a
9windows book for details. 9windows book for details.
10*/ 10*/
11 11
12#include <irrlicht.h> 12#include <irrlicht.h>
13#ifndef _IRR_WINDOWS_ 13#ifndef _IRR_WINDOWS_
14#error Windows only example 14#error Windows only example
15#else 15#else
16#include <windows.h> // this example only runs with windows 16#include <windows.h> // this example only runs with windows
17#include <iostream> 17#include <iostream>
18#include "driverChoice.h" 18#include "driverChoice.h"
19 19
20using namespace irr; 20using namespace irr;
21 21
22#pragma comment(lib, "irrlicht.lib") 22#pragma comment(lib, "irrlicht.lib")
23 23
24HWND hOKButton; 24HWND hOKButton;
25HWND hWnd; 25HWND hWnd;
26 26
27static LRESULT CALLBACK CustomWndProc(HWND hWnd, UINT message, 27static LRESULT CALLBACK CustomWndProc(HWND hWnd, UINT message,
28 WPARAM wParam, LPARAM lParam) 28 WPARAM wParam, LPARAM lParam)
29{ 29{
30 switch (message) 30 switch (message)
31 { 31 {
32 case WM_COMMAND: 32 case WM_COMMAND:
33 { 33 {
34 HWND hwndCtl = (HWND)lParam; 34 HWND hwndCtl = (HWND)lParam;
35 int code = HIWORD(wParam); 35 int code = HIWORD(wParam);
36 36
37 if (hwndCtl == hOKButton) 37 if (hwndCtl == hOKButton)
38 { 38 {
39 DestroyWindow(hWnd); 39 DestroyWindow(hWnd);
40 PostQuitMessage(0); 40 PostQuitMessage(0);
41 return 0; 41 return 0;
42 } 42 }
43 } 43 }
44 break; 44 break;
45 case WM_DESTROY: 45 case WM_DESTROY:
46 PostQuitMessage(0); 46 PostQuitMessage(0);
47 return 0; 47 return 0;
48 48
49 } 49 }
50 50
51 return DefWindowProc(hWnd, message, wParam, lParam); 51 return DefWindowProc(hWnd, message, wParam, lParam);
52} 52}
53 53
54 54
55/* 55/*
56 Now ask for the driver and create the Windows specific window. 56 Now ask for the driver and create the Windows specific window.
57*/ 57*/
58int main() 58int main()
59{ 59{
60 // ask user for driver 60 // ask user for driver
61 video::E_DRIVER_TYPE driverType=driverChoiceConsole(); 61 video::E_DRIVER_TYPE driverType=driverChoiceConsole();
62 if (driverType==video::EDT_COUNT) 62 if (driverType==video::EDT_COUNT)
63 return 1; 63 return 1;
64 64
65 printf("Select the render window (some dead window may exist too):\n"\ 65 printf("Select the render window (some dead window may exist too):\n"\
66 " (a) Window with button (via CreationParam)\n"\ 66 " (a) Window with button (via CreationParam)\n"\
67 " (b) Window with button (via beginScene)\n"\ 67 " (b) Window with button (via beginScene)\n"\
68 " (c) Own Irrlicht window (default behavior)\n"\ 68 " (c) Own Irrlicht window (default behavior)\n"\
69 " (otherKey) exit\n\n"); 69 " (otherKey) exit\n\n");
70 70
71 char key; 71 char key;
72 std::cin >> key; 72 std::cin >> key;
73 if (key != 'a' && key != 'b' && key != 'c') 73 if (key != 'a' && key != 'b' && key != 'c')
74 return 1; 74 return 1;
75 75
76 HINSTANCE hInstance = 0; 76 HINSTANCE hInstance = 0;
77 // create dialog 77 // create dialog
78 78
79 const char* Win32ClassName = "CIrrlichtWindowsTestDialog"; 79 const char* Win32ClassName = "CIrrlichtWindowsTestDialog";
80 80
81 WNDCLASSEX wcex; 81 WNDCLASSEX wcex;
82 wcex.cbSize = sizeof(WNDCLASSEX); 82 wcex.cbSize = sizeof(WNDCLASSEX);
83 wcex.style = CS_HREDRAW | CS_VREDRAW; 83 wcex.style = CS_HREDRAW | CS_VREDRAW;
84 wcex.lpfnWndProc = (WNDPROC)CustomWndProc; 84 wcex.lpfnWndProc = (WNDPROC)CustomWndProc;
85 wcex.cbClsExtra = 0; 85 wcex.cbClsExtra = 0;
86 wcex.cbWndExtra = DLGWINDOWEXTRA; 86 wcex.cbWndExtra = DLGWINDOWEXTRA;
87 wcex.hInstance = hInstance; 87 wcex.hInstance = hInstance;
88 wcex.hIcon = NULL; 88 wcex.hIcon = NULL;
89 wcex.hCursor = LoadCursor(NULL, IDC_ARROW); 89 wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
90 wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW); 90 wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW);
91 wcex.lpszMenuName = 0; 91 wcex.lpszMenuName = 0;
92 wcex.lpszClassName = Win32ClassName; 92 wcex.lpszClassName = Win32ClassName;
93 wcex.hIconSm = 0; 93 wcex.hIconSm = 0;
94 94
95 RegisterClassEx(&wcex); 95 RegisterClassEx(&wcex);
96 96
97 DWORD style = WS_SYSMENU | WS_BORDER | WS_CAPTION | 97 DWORD style = WS_SYSMENU | WS_BORDER | WS_CAPTION |
98 WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_MAXIMIZEBOX | WS_MINIMIZEBOX | WS_SIZEBOX; 98 WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_MAXIMIZEBOX | WS_MINIMIZEBOX | WS_SIZEBOX;
99 99
100 int windowWidth = 440; 100 int windowWidth = 440;
101 int windowHeight = 380; 101 int windowHeight = 380;
102 102
103 hWnd = CreateWindow( Win32ClassName, "Irrlicht Win32 window example", 103 hWnd = CreateWindow( Win32ClassName, "Irrlicht Win32 window example",
104 style, 100, 100, windowWidth, windowHeight, 104 style, 100, 100, windowWidth, windowHeight,
105 NULL, NULL, hInstance, NULL); 105 NULL, NULL, hInstance, NULL);
106 106
107 RECT clientRect; 107 RECT clientRect;
108 GetClientRect(hWnd, &clientRect); 108 GetClientRect(hWnd, &clientRect);
109 windowWidth = clientRect.right; 109 windowWidth = clientRect.right;
110 windowHeight = clientRect.bottom; 110 windowHeight = clientRect.bottom;
111 111
112 // create ok button 112 // create ok button
113 113
114 hOKButton = CreateWindow("BUTTON", "OK - Close", WS_CHILD | WS_VISIBLE | BS_TEXT, 114 hOKButton = CreateWindow("BUTTON", "OK - Close", WS_CHILD | WS_VISIBLE | BS_TEXT,
115 windowWidth - 160, windowHeight - 40, 150, 30, hWnd, NULL, hInstance, NULL); 115 windowWidth - 160, windowHeight - 40, 150, 30, hWnd, NULL, hInstance, NULL);
116 116
117 // create some text 117 // create some text
118 118
119 CreateWindow("STATIC", "This is Irrlicht running inside a standard Win32 window.\n"\ 119 CreateWindow("STATIC", "This is Irrlicht running inside a standard Win32 window.\n"\
120 "Also mixing with MFC and .NET Windows.Forms is possible.", 120 "Also mixing with MFC and .NET Windows.Forms is possible.",
121 WS_CHILD | WS_VISIBLE, 20, 20, 400, 40, hWnd, NULL, hInstance, NULL); 121 WS_CHILD | WS_VISIBLE, 20, 20, 400, 40, hWnd, NULL, hInstance, NULL);
122 122
123 // create window to put irrlicht in 123 // create window to put irrlicht in
124 124
125 HWND hIrrlichtWindow = CreateWindow("BUTTON", "", 125 HWND hIrrlichtWindow = CreateWindow("BUTTON", "",
126 WS_CHILD | WS_VISIBLE | BS_OWNERDRAW, 126 WS_CHILD | WS_VISIBLE | BS_OWNERDRAW,
127 50, 80, 320, 220, hWnd, NULL, hInstance, NULL); 127 50, 80, 320, 220, hWnd, NULL, hInstance, NULL);
128 video::SExposedVideoData videodata((key=='b')?hIrrlichtWindow:0); 128 video::SExposedVideoData videodata((key=='b')?hIrrlichtWindow:0);
129 129
130 /* 130 /*
131 So now that we have some window, we can create an Irrlicht device 131 So now that we have some window, we can create an Irrlicht device
132 inside of it. We use Irrlicht createEx() function for this. We only 132 inside of it. We use Irrlicht createEx() function for this. We only
133 need the handle (HWND) to that window, set it as windowsID parameter 133 need the handle (HWND) to that window, set it as windowsID parameter
134 and start up the engine as usual. That's it. 134 and start up the engine as usual. That's it.
135 */ 135 */
136 // create irrlicht device in the button window 136 // create irrlicht device in the button window
137 137
138 irr::SIrrlichtCreationParameters param; 138 irr::SIrrlichtCreationParameters param;
139 param.DriverType = driverType; 139 param.DriverType = driverType;
140 if (key=='a') 140 if (key=='a')
141 param.WindowId = reinterpret_cast<void*>(hIrrlichtWindow); 141 param.WindowId = reinterpret_cast<void*>(hIrrlichtWindow);
142 142
143 irr::IrrlichtDevice* device = irr::createDeviceEx(param); 143 irr::IrrlichtDevice* device = irr::createDeviceEx(param);
144 if (!device) 144 if (!device)
145 return 1; 145 return 1;
146 146
147 // setup a simple 3d scene 147 // setup a simple 3d scene
148 148
149 irr::scene::ISceneManager* smgr = device->getSceneManager(); 149 irr::scene::ISceneManager* smgr = device->getSceneManager();
150 video::IVideoDriver* driver = device->getVideoDriver(); 150 video::IVideoDriver* driver = device->getVideoDriver();
151 151
152 if (driverType==video::EDT_OPENGL) 152 if (driverType==video::EDT_OPENGL)
153 { 153 {
154 HDC HDc=GetDC(hIrrlichtWindow); 154 HDC HDc=GetDC(hIrrlichtWindow);
155 PIXELFORMATDESCRIPTOR pfd={0}; 155 PIXELFORMATDESCRIPTOR pfd={0};
156 pfd.nSize=sizeof(PIXELFORMATDESCRIPTOR); 156 pfd.nSize=sizeof(PIXELFORMATDESCRIPTOR);
157 int pf = GetPixelFormat(HDc); 157 int pf = GetPixelFormat(HDc);
158 DescribePixelFormat(HDc, pf, sizeof(PIXELFORMATDESCRIPTOR), &pfd); 158 DescribePixelFormat(HDc, pf, sizeof(PIXELFORMATDESCRIPTOR), &pfd);
159 pfd.dwFlags |= PFD_DOUBLEBUFFER | PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW; 159 pfd.dwFlags |= PFD_DOUBLEBUFFER | PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW;
160 pfd.cDepthBits=16; 160 pfd.cDepthBits=16;
161 pf = ChoosePixelFormat(HDc, &pfd); 161 pf = ChoosePixelFormat(HDc, &pfd);
162 SetPixelFormat(HDc, pf, &pfd); 162 SetPixelFormat(HDc, pf, &pfd);
163 videodata.OpenGLWin32.HDc = HDc; 163 videodata.OpenGLWin32.HDc = HDc;
164 videodata.OpenGLWin32.HRc=wglCreateContext(HDc); 164 videodata.OpenGLWin32.HRc=wglCreateContext(HDc);
165 wglShareLists((HGLRC)driver->getExposedVideoData().OpenGLWin32.HRc, (HGLRC)videodata.OpenGLWin32.HRc); 165 wglShareLists((HGLRC)driver->getExposedVideoData().OpenGLWin32.HRc, (HGLRC)videodata.OpenGLWin32.HRc);
166 } 166 }
167 scene::ICameraSceneNode* cam = smgr->addCameraSceneNode(); 167 scene::ICameraSceneNode* cam = smgr->addCameraSceneNode();
168 cam->setTarget(core::vector3df(0,0,0)); 168 cam->setTarget(core::vector3df(0,0,0));
169 169
170 scene::ISceneNodeAnimator* anim = 170 scene::ISceneNodeAnimator* anim =
171 smgr->createFlyCircleAnimator(core::vector3df(0,15,0), 30.0f); 171 smgr->createFlyCircleAnimator(core::vector3df(0,15,0), 30.0f);
172 cam->addAnimator(anim); 172 cam->addAnimator(anim);
173 anim->drop(); 173 anim->drop();
174 174
175 scene::ISceneNode* cube = smgr->addCubeSceneNode(20); 175 scene::ISceneNode* cube = smgr->addCubeSceneNode(20);
176 176
177 cube->setMaterialTexture(0, driver->getTexture("../../media/wall.bmp")); 177 cube->setMaterialTexture(0, driver->getTexture("../../media/wall.bmp"));
178 cube->setMaterialTexture(1, driver->getTexture("../../media/water.jpg")); 178 cube->setMaterialTexture(1, driver->getTexture("../../media/water.jpg"));
179 cube->setMaterialFlag( video::EMF_LIGHTING, false ); 179 cube->setMaterialFlag( video::EMF_LIGHTING, false );
180 cube->setMaterialType( video::EMT_REFLECTION_2_LAYER ); 180 cube->setMaterialType( video::EMT_REFLECTION_2_LAYER );
181 181
182 smgr->addSkyBoxSceneNode( 182 smgr->addSkyBoxSceneNode(
183 driver->getTexture("../../media/irrlicht2_up.jpg"), 183 driver->getTexture("../../media/irrlicht2_up.jpg"),
184 driver->getTexture("../../media/irrlicht2_dn.jpg"), 184 driver->getTexture("../../media/irrlicht2_dn.jpg"),
185 driver->getTexture("../../media/irrlicht2_lf.jpg"), 185 driver->getTexture("../../media/irrlicht2_lf.jpg"),
186 driver->getTexture("../../media/irrlicht2_rt.jpg"), 186 driver->getTexture("../../media/irrlicht2_rt.jpg"),
187 driver->getTexture("../../media/irrlicht2_ft.jpg"), 187 driver->getTexture("../../media/irrlicht2_ft.jpg"),
188 driver->getTexture("../../media/irrlicht2_bk.jpg")); 188 driver->getTexture("../../media/irrlicht2_bk.jpg"));
189 189
190 // show and execute dialog 190 // show and execute dialog
191 191
192 ShowWindow(hWnd , SW_SHOW); 192 ShowWindow(hWnd , SW_SHOW);
193 UpdateWindow(hWnd); 193 UpdateWindow(hWnd);
194 194
195 // do message queue 195 // do message queue
196 196
197 /* 197 /*
198 Now the only thing missing is the drawing loop using 198 Now the only thing missing is the drawing loop using
199 IrrlichtDevice::run(). We do this as usual. But instead of this, there 199 IrrlichtDevice::run(). We do this as usual. But instead of this, there
200 is another possibility: You can also simply use your own message loop 200 is another possibility: You can also simply use your own message loop
201 using GetMessage, DispatchMessage and whatever. Calling 201 using GetMessage, DispatchMessage and whatever. Calling
202 Device->run() will cause Irrlicht to dispatch messages internally too. 202 Device->run() will cause Irrlicht to dispatch messages internally too.
203 You need not call Device->run() if you want to do your own message 203 You need not call Device->run() if you want to do your own message
204 dispatching loop, but Irrlicht will not be able to fetch user input 204 dispatching loop, but Irrlicht will not be able to fetch user input
205 then and you have to do it on your own using the window messages, 205 then and you have to do it on your own using the window messages,
206 DirectInput, or whatever. 206 DirectInput, or whatever.
207 */ 207 */
208 208
209 while (device->run()) 209 while (device->run())
210 { 210 {
211 driver->beginScene(true, true, 0, videodata); 211 driver->beginScene(true, true, 0, videodata);
212 smgr->drawAll(); 212 smgr->drawAll();
213 driver->endScene(); 213 driver->endScene();
214 } 214 }
215 215
216 /* 216 /*
217 The alternative, own message dispatching loop without Device->run() 217 The alternative, own message dispatching loop without Device->run()
218 would look like this: 218 would look like this:
219 */ 219 */
220 220
221 /*MSG msg; 221 /*MSG msg;
222 while (true) 222 while (true)
223 { 223 {
224 if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) 224 if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
225 { 225 {
226 TranslateMessage(&msg); 226 TranslateMessage(&msg);
227 DispatchMessage(&msg); 227 DispatchMessage(&msg);
228 228
229 if (msg.message == WM_QUIT) 229 if (msg.message == WM_QUIT)
230 break; 230 break;
231 } 231 }
232 232
233 // advance virtual time 233 // advance virtual time
234 device->getTimer()->tick(); 234 device->getTimer()->tick();
235 235
236 // draw engine picture 236 // draw engine picture
237 driver->beginScene(true, true, 0, (key=='c')?hIrrlichtWindow:0); 237 driver->beginScene(true, true, 0, (key=='c')?hIrrlichtWindow:0);
238 smgr->drawAll(); 238 smgr->drawAll();
239 driver->endScene(); 239 driver->endScene();
240 }*/ 240 }*/
241 241
242 device->closeDevice(); 242 device->closeDevice();
243 device->drop(); 243 device->drop();
244 244
245 return 0; 245 return 0;
246} 246}
247#endif // if windows 247#endif // if windows
248 248
249/* 249/*
250That's it, Irrlicht now runs in your own windows window. 250That's it, Irrlicht now runs in your own windows window.
251**/ 251**/