14. Win32Window
Posted 2007/09/15 19:28 by 수달--------------------------------------------------------------------------
튜토리얼 : 14. 32비트 윈도형 예제
-------------------------------
이 예제는 윈도OS에서만 실행되며, IRRLICHT가 Win32 체제에서 어떻게 구현되는지 보여준다.
#include <irrlicht.h>
#include <windows.h> // this example only runs with windows
using namespace irr;
#pragma comment(lib, "irrlicht.lib")
HWND hOKButton;
HWND hWnd;
static LRESULT CALLBACK CustomWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_COMMAND:
{
HWND hwndCtl = (HWND)lParam;
int code = HIWORD(wParam);
if (hwndCtl == hOKButton)
{
DestroyWindow(hWnd);
PostQuitMessage(0);
return 0;
}
}
break;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hWnd, message, wParam, lParam);
}
int main()
//int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hpre, LPSTR cmd, int cc)
{
HINSTANCE hInstance = 0;
// create dialog
const char* Win32ClassName = "CIrrlichtWindowsTestDialog";
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = (WNDPROC)CustomWndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = DLGWINDOWEXTRA;
wcex.hInstance = hInstance;
wcex.hIcon = NULL;
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW);
wcex.lpszMenuName = 0;
wcex.lpszClassName = Win32ClassName;
wcex.hIconSm = 0;
RegisterClassEx(&wcex);
DWORD style = WS_SYSMENU | WS_BORDER | WS_CAPTION |
WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_MAXIMIZEBOX | WS_MINIMIZEBOX | WS_SIZEBOX;
int windowWidth = 440;
int windowHeight = 380;
hWnd = CreateWindow( Win32ClassName, "Irrlicht Win32 window example",
style, 100, 100, windowWidth, windowHeight,
NULL, NULL, hInstance, NULL);
RECT clientRect;
GetClientRect(hWnd, &clientRect);
windowWidth = clientRect.right;
windowHeight = clientRect.bottom;
// create ok button
hOKButton = CreateWindow("BUTTON", "OK - Close", WS_CHILD | WS_VISIBLE | BS_TEXT,
windowWidth - 160, windowHeight - 40, 150, 30, hWnd, NULL, hInstance, NULL);
// create some text
CreateWindow("STATIC", "This is Irrlicht running inside a standard Win32 window.\n"\
"Also mixing with MFC and .NET Windows.Forms is possible.",
WS_CHILD | WS_VISIBLE, 20, 20, 400, 40, hWnd, NULL, hInstance, NULL);
// create window to put irrlicht in
HWND hIrrlichtWindow = CreateWindow("BUTTON", "", WS_CHILD | WS_VISIBLE | BS_OWNERDRAW,
50, 80, 320, 220, hWnd, NULL, hInstance, NULL);
// create irrlicht device in the button window
irr::SIrrlichtCreationParameters param;
param.WindowId = reinterpret_cast<s32>(hIrrlichtWindow); // hColorButton
param.DriverType = video::EDT_OPENGL;
irr::IrrlichtDevice* device = irr::createDeviceEx(param);
// setup a simple 3d scene
irr::scene::ISceneManager*smgr = device->getSceneManager();
video::IVideoDriver* driver = device->getVideoDriver();
scene::ICameraSceneNode* cam = smgr->addCameraSceneNode();
cam->setTarget(core::vector3df(0,0,0));
scene::ISceneNodeAnimator* anim = smgr->createFlyCircleAnimator(core::vector3df(0,10,0), 30.0f);
cam->addAnimator(anim);
anim->drop();
scene::ISceneNode* cube = smgr->addTestSceneNode(25);
cube->setMaterialTexture(0, driver->getTexture("../../media/rockwall.bmp"));
smgr->addSkyBoxSceneNode(
driver->getTexture("../../media/irrlicht2_up.jpg"),
driver->getTexture("../../media/irrlicht2_dn.jpg"),
driver->getTexture("../../media/irrlicht2_lf.jpg"),
driver->getTexture("../../media/irrlicht2_rt.jpg"),
driver->getTexture("../../media/irrlicht2_ft.jpg"),
driver->getTexture("../../media/irrlicht2_bk.jpg"));
// show and execute dialog
ShowWindow(hWnd , SW_SHOW);
UpdateWindow(hWnd);
메세지 큐를 넣는 곳. 하지만 예제처럼 GetMessage를 이용하는 Win32 형식을 사용해도 된다. Device->run()을 호출하면 IRRLICHT는 내부적으로 메세지를 번역처리(dispatch) 해 줄 것이다. (역자 주 : Win32 메세지 처리에서 DispatchMessage()한다. 이에 대해선 www.winapi.co.kr 을 참고하라.) Device->run()을 사용하지 않는다면 IRRLICHT는 사용자의 입력을 처리할 수 없다. 이 경우 개발자는 윈도 메세지나 DirectInput 등 다른 방식으로 처리해야 할 것이다.
while (device->run())
{
driver->beginScene(true, true, 0);
smgr->drawAll();
driver->endScene();
}
// the alternative, own message dispatching loop without Device->run() would
// look like this:
/*MSG msg;
while (true)
{
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
if (msg.message == WM_QUIT)
break;
}
// advance virtual time
device->getTimer()->tick();
// draw engine picture
driver->beginScene(true, true, 0);
smgr->drawAll();
driver->endScene();
}*/
device->closeDevice();
device->drop();
return 0;
}
---------------------------------------------------------------------------
드디어 튜토리얼이 끝났다.
사실 이번 예제는 윈도 개발자를 위한 보너스 같은 것이다.
예제 작성자의 굿 센스에 경의를 보낸다.
그래서인지 설명할 것도 적다. 도리어 윈도 프로그래밍 관련 정보를 보는게 좋겠다.
남은 것이 있다면, examples 폴더에는 여러 예제들 말고 Demo 폴더가 있는 것이다.
데모를 돌려본 결과, 그간의 예제를 한꺼번에 보여주는 것이었다.
음...이런 것에 대해선 읽고 주석을 달게 아닌 것 같다.
예제가 끝났으니, 앞으로는 IRRLICHT 관련 코드와 내용을 (찾으면) 올리도록 하겠다.
또한 IRRLICHT를 이용해 작고 순수한 아마추어 게임을 만드는 과정을 올리고 싶다.
될진 모르겠지만.
'기본 카테고리' 카테고리의 다른 글
일리히트 엔진 시작하기 (0) | 2009.03.19 |
---|---|
Irricht엔진튜토리얼 15. LoadIrrFile (0) | 2009.03.19 |
Irricht엔진튜토리얼 13. RenderToTexture (+06.08.04) (0) | 2009.03.19 |
Irricht엔진튜토리얼 12. TerrainRendering (0) | 2009.03.19 |
Irricht엔진튜토리얼 11. PerPixelLighting (0) | 2009.03.19 |