From 71e94ee161447b84c0eaabf6567f8fa62262cd3e Mon Sep 17 00:00:00 2001 From: Mirrorbot Date: Sat, 27 Dec 2025 17:53:06 -0600 Subject: Inital commit --- examples/14.Win32Window/Makefile | 38 ++++ examples/14.Win32Window/Win32Window.cbp | 43 ++++ examples/14.Win32Window/Win32Window.dev | 59 ++++++ examples/14.Win32Window/Win32Window.vcproj | 165 +++++++++++++++ examples/14.Win32Window/Win32Window_vc10.vcxproj | 239 +++++++++++++++++++++ examples/14.Win32Window/Win32Window_vc11.vcxproj | 239 +++++++++++++++++++++ examples/14.Win32Window/Win32Window_vc12.vcxproj | 239 +++++++++++++++++++++ examples/14.Win32Window/Win32Window_vc8.vcproj | 232 +++++++++++++++++++++ examples/14.Win32Window/Win32Window_vc9.vcproj | 232 +++++++++++++++++++++ examples/14.Win32Window/main.cpp | 251 +++++++++++++++++++++++ examples/14.Win32Window/tutorial.html | 210 +++++++++++++++++++ 11 files changed, 1947 insertions(+) create mode 100644 examples/14.Win32Window/Makefile create mode 100644 examples/14.Win32Window/Win32Window.cbp create mode 100644 examples/14.Win32Window/Win32Window.dev create mode 100644 examples/14.Win32Window/Win32Window.vcproj create mode 100644 examples/14.Win32Window/Win32Window_vc10.vcxproj create mode 100644 examples/14.Win32Window/Win32Window_vc11.vcxproj create mode 100644 examples/14.Win32Window/Win32Window_vc12.vcxproj create mode 100644 examples/14.Win32Window/Win32Window_vc8.vcproj create mode 100644 examples/14.Win32Window/Win32Window_vc9.vcproj create mode 100644 examples/14.Win32Window/main.cpp create mode 100644 examples/14.Win32Window/tutorial.html (limited to 'examples/14.Win32Window') diff --git a/examples/14.Win32Window/Makefile b/examples/14.Win32Window/Makefile new file mode 100644 index 0000000..e76f2ff --- /dev/null +++ b/examples/14.Win32Window/Makefile @@ -0,0 +1,38 @@ +# Makefile for Irrlicht Examples +# It's usually sufficient to change just the target name and source file list +# and be sure that CXX is set to a valid compiler +Target = 14.Win32Window +Sources = main.cpp + +# general compiler settings +CPPFLAGS = -I../../include -I/usr/X11R6/include +CXXFLAGS = -O3 -ffast-math +#CXXFLAGS = -g -Wall + +#default target is Linux +all: all_linux + +ifeq ($(HOSTTYPE), x86_64) +LIBSELECT=64 +endif + +# target specific settings +all_linux: LDFLAGS = -L/usr/X11R6/lib$(LIBSELECT) -L../../lib/Linux -lIrrlicht -lGL -lXxf86vm -lXext -lX11 -lXcursor +all_linux clean_linux: SYSTEM=Linux +all_win32: LDFLAGS = -L../../lib/Win32-gcc -lIrrlicht -lopengl32 -lm +all_win32 clean_win32: SYSTEM=Win32-gcc +all_win32 clean_win32: SUF=.exe +# name of the binary - only valid for targets which set SYSTEM +DESTPATH = ../../bin/$(SYSTEM)/$(Target)$(SUF) + +all_linux all_win32: + $(warning Building...) + $(CXX) $(CPPFLAGS) $(CXXFLAGS) $(Sources) -o $(DESTPATH) $(LDFLAGS) + +clean: clean_linux clean_win32 + $(warning Cleaning...) + +clean_linux clean_win32: + @$(RM) $(DESTPATH) + +.PHONY: all all_win32 clean clean_linux clean_win32 diff --git a/examples/14.Win32Window/Win32Window.cbp b/examples/14.Win32Window/Win32Window.cbp new file mode 100644 index 0000000..06f310b --- /dev/null +++ b/examples/14.Win32Window/Win32Window.cbp @@ -0,0 +1,43 @@ + + + + + + diff --git a/examples/14.Win32Window/Win32Window.dev b/examples/14.Win32Window/Win32Window.dev new file mode 100644 index 0000000..6192563 --- /dev/null +++ b/examples/14.Win32Window/Win32Window.dev @@ -0,0 +1,59 @@ +[Project] +FileName=example.dev +Name=Irrlicht Example 14 Win32 Window +UnitCount=1 +Type=1 +Ver=1 +ObjFiles= +Includes=..\..\include +Libs= +PrivateResource= +ResourceIncludes= +MakeIncludes= +Compiler= +CppCompiler= +Linker=../../lib/Win32-gcc/libIrrlicht.a_@@_ +IsCpp=1 +Icon= +ExeOutput=../../bin/Win32-gcc +ObjectOutput=obj +OverrideOutput=1 +OverrideOutputName=14.Win32Window.exe +HostApplication= +Folders= +CommandLine= +IncludeVersionInfo=0 +SupportXPThemes=0 +CompilerSet=0 +CompilerSettings=0000000000000000000000 +UseCustomMakefile=0 +CustomMakefile= + +[Unit1] +FileName=main.cpp +CompileCpp=1 +Folder=Projekt1 +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[VersionInfo] +Major=0 +Minor=1 +Release=1 +Build=1 +LanguageID=1033 +CharsetID=1252 +CompanyName= +FileVersion= +FileDescription=Irrlicht Engine example compiled using DevCpp and gcc +InternalName= +LegalCopyright= +LegalTrademarks= +OriginalFilename= +ProductName= +ProductVersion= +AutoIncBuildNr=0 + diff --git a/examples/14.Win32Window/Win32Window.vcproj b/examples/14.Win32Window/Win32Window.vcproj new file mode 100644 index 0000000..c8576c7 --- /dev/null +++ b/examples/14.Win32Window/Win32Window.vcproj @@ -0,0 +1,165 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/examples/14.Win32Window/Win32Window_vc10.vcxproj b/examples/14.Win32Window/Win32Window_vc10.vcxproj new file mode 100644 index 0000000..0ea47db --- /dev/null +++ b/examples/14.Win32Window/Win32Window_vc10.vcxproj @@ -0,0 +1,239 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + 14.Win32Window + {772FBE05-D05A-467B-9842-BEC409EEA8D0} + Win32Window + + + + Application + false + MultiByte + Windows7.1SDK + + + Application + false + MultiByte + Windows7.1SDK + + + Application + false + MultiByte + Windows7.1SDK + + + Application + false + MultiByte + Windows7.1SDK + + + + + + + + + + + + + + + + + + + + + + + <_ProjectFileVersion>10.0.30319.1 + ..\..\bin\Win32-VisualStudio\ + ..\..\bin\Win64-VisualStudio\ + + + ..\..\bin\Win32-VisualStudio\ + ..\..\bin\Win64-VisualStudio\ + + + AllRules.ruleset + AllRules.ruleset + + + + + AllRules.ruleset + AllRules.ruleset + + + + + + + + .\Debug/Win32Window.tlb + + + + + Disabled + ..\..\include;%(AdditionalIncludeDirectories) + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + EnableFastChecks + MultiThreadedDebug + + + Level3 + EditAndContinue + + + _DEBUG;%(PreprocessorDefinitions) + 0x0c07 + + + opengl32.lib;%(AdditionalDependencies) + ..\..\bin\Win32-VisualStudio\14.Win32Window.exe + ..\..\lib\Win32-visualstudio;%(AdditionalLibraryDirectories) + true + Console + + + + + + + .\Debug/Win32Window.tlb + + + + + Disabled + ..\..\include;%(AdditionalIncludeDirectories) + WIN32;WIN64;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + EnableFastChecks + MultiThreadedDebug + + + Level3 + ProgramDatabase + + + _DEBUG;%(PreprocessorDefinitions) + 0x0c07 + + + opengl32.lib;%(AdditionalDependencies) + ..\..\bin\Win64-VisualStudio\14.Win32Window.exe + ..\..\lib\Win64-visualstudio;%(AdditionalLibraryDirectories) + true + Console + + + + + + + .\Release/Win32Window.tlb + + + + + MaxSpeed + OnlyExplicitInline + ..\..\include;%(AdditionalIncludeDirectories) + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + MultiThreaded + true + + + Level3 + + + NDEBUG;%(PreprocessorDefinitions) + 0x0c07 + + + opengl32.lib;%(AdditionalDependencies) + ..\..\bin\Win32-VisualStudio\14.Win32Window.exe + ..\..\lib\Win32-visualstudio;%(AdditionalLibraryDirectories) + Console + + + + + + + .\Release/Win32Window.tlb + + + + + MaxSpeed + OnlyExplicitInline + ..\..\include;%(AdditionalIncludeDirectories) + WIN32;WIN64;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + MultiThreaded + true + + + Level3 + + + NDEBUG;%(PreprocessorDefinitions) + 0x0c07 + + + opengl32.lib;%(AdditionalDependencies) + ..\..\bin\Win64-VisualStudio\14.Win32Window.exe + ..\..\lib\Win64-visualstudio;%(AdditionalLibraryDirectories) + Console + + + + + + + Disabled + Disabled + %(AdditionalIncludeDirectories) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(PreprocessorDefinitions) + EnableFastChecks + EnableFastChecks + MaxSpeed + MaxSpeed + %(AdditionalIncludeDirectories) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(PreprocessorDefinitions) + + + + + + \ No newline at end of file diff --git a/examples/14.Win32Window/Win32Window_vc11.vcxproj b/examples/14.Win32Window/Win32Window_vc11.vcxproj new file mode 100644 index 0000000..0ea47db --- /dev/null +++ b/examples/14.Win32Window/Win32Window_vc11.vcxproj @@ -0,0 +1,239 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + 14.Win32Window + {772FBE05-D05A-467B-9842-BEC409EEA8D0} + Win32Window + + + + Application + false + MultiByte + Windows7.1SDK + + + Application + false + MultiByte + Windows7.1SDK + + + Application + false + MultiByte + Windows7.1SDK + + + Application + false + MultiByte + Windows7.1SDK + + + + + + + + + + + + + + + + + + + + + + + <_ProjectFileVersion>10.0.30319.1 + ..\..\bin\Win32-VisualStudio\ + ..\..\bin\Win64-VisualStudio\ + + + ..\..\bin\Win32-VisualStudio\ + ..\..\bin\Win64-VisualStudio\ + + + AllRules.ruleset + AllRules.ruleset + + + + + AllRules.ruleset + AllRules.ruleset + + + + + + + + .\Debug/Win32Window.tlb + + + + + Disabled + ..\..\include;%(AdditionalIncludeDirectories) + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + EnableFastChecks + MultiThreadedDebug + + + Level3 + EditAndContinue + + + _DEBUG;%(PreprocessorDefinitions) + 0x0c07 + + + opengl32.lib;%(AdditionalDependencies) + ..\..\bin\Win32-VisualStudio\14.Win32Window.exe + ..\..\lib\Win32-visualstudio;%(AdditionalLibraryDirectories) + true + Console + + + + + + + .\Debug/Win32Window.tlb + + + + + Disabled + ..\..\include;%(AdditionalIncludeDirectories) + WIN32;WIN64;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + EnableFastChecks + MultiThreadedDebug + + + Level3 + ProgramDatabase + + + _DEBUG;%(PreprocessorDefinitions) + 0x0c07 + + + opengl32.lib;%(AdditionalDependencies) + ..\..\bin\Win64-VisualStudio\14.Win32Window.exe + ..\..\lib\Win64-visualstudio;%(AdditionalLibraryDirectories) + true + Console + + + + + + + .\Release/Win32Window.tlb + + + + + MaxSpeed + OnlyExplicitInline + ..\..\include;%(AdditionalIncludeDirectories) + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + MultiThreaded + true + + + Level3 + + + NDEBUG;%(PreprocessorDefinitions) + 0x0c07 + + + opengl32.lib;%(AdditionalDependencies) + ..\..\bin\Win32-VisualStudio\14.Win32Window.exe + ..\..\lib\Win32-visualstudio;%(AdditionalLibraryDirectories) + Console + + + + + + + .\Release/Win32Window.tlb + + + + + MaxSpeed + OnlyExplicitInline + ..\..\include;%(AdditionalIncludeDirectories) + WIN32;WIN64;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + MultiThreaded + true + + + Level3 + + + NDEBUG;%(PreprocessorDefinitions) + 0x0c07 + + + opengl32.lib;%(AdditionalDependencies) + ..\..\bin\Win64-VisualStudio\14.Win32Window.exe + ..\..\lib\Win64-visualstudio;%(AdditionalLibraryDirectories) + Console + + + + + + + Disabled + Disabled + %(AdditionalIncludeDirectories) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(PreprocessorDefinitions) + EnableFastChecks + EnableFastChecks + MaxSpeed + MaxSpeed + %(AdditionalIncludeDirectories) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(PreprocessorDefinitions) + + + + + + \ No newline at end of file diff --git a/examples/14.Win32Window/Win32Window_vc12.vcxproj b/examples/14.Win32Window/Win32Window_vc12.vcxproj new file mode 100644 index 0000000..814a398 --- /dev/null +++ b/examples/14.Win32Window/Win32Window_vc12.vcxproj @@ -0,0 +1,239 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + 14.Win32Window + {772FBE05-D05A-467B-9842-BEC409EEA8D0} + Win32Window + + + + Application + false + MultiByte + Windows7.1SDK + + + Application + false + MultiByte + Windows7.1SDK + + + Application + false + MultiByte + Windows7.1SDK + + + Application + false + MultiByte + Windows7.1SDK + + + + + + + + + + + + + + + + + + + + + + + <_ProjectFileVersion>10.0.30319.1 + ..\..\bin\Win32-VisualStudio\ + ..\..\bin\Win64-VisualStudio\ + + + ..\..\bin\Win32-VisualStudio\ + ..\..\bin\Win64-VisualStudio\ + + + AllRules.ruleset + AllRules.ruleset + + + + + AllRules.ruleset + AllRules.ruleset + + + + + + + + .\Debug/Win32Window.tlb + + + + + Disabled + ..\..\include;%(AdditionalIncludeDirectories) + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + EnableFastChecks + MultiThreadedDebug + + + Level3 + EditAndContinue + + + _DEBUG;%(PreprocessorDefinitions) + 0x0c07 + + + opengl32.lib;%(AdditionalDependencies) + ..\..\bin\Win32-VisualStudio\14.Win32Window.exe + ..\..\lib\Win32-visualstudio;%(AdditionalLibraryDirectories) + true + Console + + + + + + + .\Debug/Win32Window.tlb + + + + + Disabled + ..\..\include;%(AdditionalIncludeDirectories) + WIN32;WIN64;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + EnableFastChecks + MultiThreadedDebug + + + Level3 + ProgramDatabase + + + _DEBUG;%(PreprocessorDefinitions) + 0x0c07 + + + opengl32.lib;%(AdditionalDependencies) + ..\..\bin\Win64-VisualStudio\14.Win32Window.exe + ..\..\lib\Win64-visualstudio;%(AdditionalLibraryDirectories) + true + Console + + + + + + + .\Release/Win32Window.tlb + + + + + MaxSpeed + OnlyExplicitInline + ..\..\include;%(AdditionalIncludeDirectories) + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + MultiThreaded + true + + + Level3 + + + NDEBUG;%(PreprocessorDefinitions) + 0x0c07 + + + opengl32.lib;%(AdditionalDependencies) + ..\..\bin\Win32-VisualStudio\14.Win32Window.exe + ..\..\lib\Win32-visualstudio;%(AdditionalLibraryDirectories) + Console + + + + + + + .\Release/Win32Window.tlb + + + + + MaxSpeed + OnlyExplicitInline + ..\..\include;%(AdditionalIncludeDirectories) + WIN32;WIN64;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + MultiThreaded + true + + + Level3 + + + NDEBUG;%(PreprocessorDefinitions) + 0x0c07 + + + opengl32.lib;%(AdditionalDependencies) + ..\..\bin\Win64-VisualStudio\14.Win32Window.exe + ..\..\lib\Win64-visualstudio;%(AdditionalLibraryDirectories) + Console + + + + + + + Disabled + Disabled + %(AdditionalIncludeDirectories) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(PreprocessorDefinitions) + EnableFastChecks + EnableFastChecks + MaxSpeed + MaxSpeed + %(AdditionalIncludeDirectories) + %(AdditionalIncludeDirectories) + %(PreprocessorDefinitions) + %(PreprocessorDefinitions) + + + + + + \ No newline at end of file diff --git a/examples/14.Win32Window/Win32Window_vc8.vcproj b/examples/14.Win32Window/Win32Window_vc8.vcproj new file mode 100644 index 0000000..efbf43d --- /dev/null +++ b/examples/14.Win32Window/Win32Window_vc8.vcproj @@ -0,0 +1,232 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/examples/14.Win32Window/Win32Window_vc9.vcproj b/examples/14.Win32Window/Win32Window_vc9.vcproj new file mode 100644 index 0000000..2902fba --- /dev/null +++ b/examples/14.Win32Window/Win32Window_vc9.vcproj @@ -0,0 +1,232 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/examples/14.Win32Window/main.cpp b/examples/14.Win32Window/main.cpp new file mode 100644 index 0000000..33d111e --- /dev/null +++ b/examples/14.Win32Window/main.cpp @@ -0,0 +1,251 @@ +/** Example 014 Win32 Window + +This example only runs under MS Windows and demonstrates that Irrlicht can +render inside a win32 window. MFC and .NET Windows.Forms windows are possible, +too. + +In the beginning, we create a windows window using the windows API. I'm not +going to explain this code, because it is windows specific. See the MSDN or a +windows book for details. +*/ + +#include +#ifndef _IRR_WINDOWS_ +#error Windows only example +#else +#include // this example only runs with windows +#include +#include "driverChoice.h" + +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); +} + + +/* + Now ask for the driver and create the Windows specific window. +*/ +int main() +{ + // ask user for driver + video::E_DRIVER_TYPE driverType=driverChoiceConsole(); + if (driverType==video::EDT_COUNT) + return 1; + + printf("Select the render window (some dead window may exist too):\n"\ + " (a) Window with button (via CreationParam)\n"\ + " (b) Window with button (via beginScene)\n"\ + " (c) Own Irrlicht window (default behavior)\n"\ + " (otherKey) exit\n\n"); + + char key; + std::cin >> key; + if (key != 'a' && key != 'b' && key != 'c') + return 1; + + 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); + video::SExposedVideoData videodata((key=='b')?hIrrlichtWindow:0); + + /* + So now that we have some window, we can create an Irrlicht device + inside of it. We use Irrlicht createEx() function for this. We only + need the handle (HWND) to that window, set it as windowsID parameter + and start up the engine as usual. That's it. + */ + // create irrlicht device in the button window + + irr::SIrrlichtCreationParameters param; + param.DriverType = driverType; + if (key=='a') + param.WindowId = reinterpret_cast(hIrrlichtWindow); + + irr::IrrlichtDevice* device = irr::createDeviceEx(param); + if (!device) + return 1; + + // setup a simple 3d scene + + irr::scene::ISceneManager* smgr = device->getSceneManager(); + video::IVideoDriver* driver = device->getVideoDriver(); + + if (driverType==video::EDT_OPENGL) + { + HDC HDc=GetDC(hIrrlichtWindow); + PIXELFORMATDESCRIPTOR pfd={0}; + pfd.nSize=sizeof(PIXELFORMATDESCRIPTOR); + int pf = GetPixelFormat(HDc); + DescribePixelFormat(HDc, pf, sizeof(PIXELFORMATDESCRIPTOR), &pfd); + pfd.dwFlags |= PFD_DOUBLEBUFFER | PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW; + pfd.cDepthBits=16; + pf = ChoosePixelFormat(HDc, &pfd); + SetPixelFormat(HDc, pf, &pfd); + videodata.OpenGLWin32.HDc = HDc; + videodata.OpenGLWin32.HRc=wglCreateContext(HDc); + wglShareLists((HGLRC)driver->getExposedVideoData().OpenGLWin32.HRc, (HGLRC)videodata.OpenGLWin32.HRc); + } + scene::ICameraSceneNode* cam = smgr->addCameraSceneNode(); + cam->setTarget(core::vector3df(0,0,0)); + + scene::ISceneNodeAnimator* anim = + smgr->createFlyCircleAnimator(core::vector3df(0,15,0), 30.0f); + cam->addAnimator(anim); + anim->drop(); + + scene::ISceneNode* cube = smgr->addCubeSceneNode(20); + + cube->setMaterialTexture(0, driver->getTexture("../../media/wall.bmp")); + cube->setMaterialTexture(1, driver->getTexture("../../media/water.jpg")); + cube->setMaterialFlag( video::EMF_LIGHTING, false ); + cube->setMaterialType( video::EMT_REFLECTION_2_LAYER ); + + 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); + + // do message queue + + /* + Now the only thing missing is the drawing loop using + IrrlichtDevice::run(). We do this as usual. But instead of this, there + is another possibility: You can also simply use your own message loop + using GetMessage, DispatchMessage and whatever. Calling + Device->run() will cause Irrlicht to dispatch messages internally too. + You need not call Device->run() if you want to do your own message + dispatching loop, but Irrlicht will not be able to fetch user input + then and you have to do it on your own using the window messages, + DirectInput, or whatever. + */ + + while (device->run()) + { + driver->beginScene(true, true, 0, videodata); + 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, (key=='c')?hIrrlichtWindow:0); + smgr->drawAll(); + driver->endScene(); + }*/ + + device->closeDevice(); + device->drop(); + + return 0; +} +#endif // if windows + +/* +That's it, Irrlicht now runs in your own windows window. +**/ diff --git a/examples/14.Win32Window/tutorial.html b/examples/14.Win32Window/tutorial.html new file mode 100644 index 0000000..819e8ec --- /dev/null +++ b/examples/14.Win32Window/tutorial.html @@ -0,0 +1,210 @@ + + + + + + + +Tutorial 14: Win32 Window + + + + +
+ + + +
+
+
+
Tutorial 14: Win32 Window
+
+
+
+014shot.jpg +
+

This example only runs under MS Windows and demonstrates that Irrlicht can render inside a win32 window. MFC and .NET Windows.Forms windows are possible, too.

+

In the beginning, we create a windows window using the windows API. I'm not going to explain this code, because it is windows specific. See the MSDN or a windows book for details.

#include <irrlicht.h>
#ifndef _IRR_WINDOWS_
#error Windows only example
#else
#include <windows.h> // this example only runs with windows
#include <iostream>
#include "driverChoice.h"
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);
}

Now ask for the driver and create the Windows specific window.

int main()
{
// ask user for driver
video::E_DRIVER_TYPE driverType=driverChoiceConsole();
if (driverType==video::EDT_COUNT)
return 1;
printf("Select the render window (some dead window may exist too):\n"\
" (a) Window with button (via CreationParam)\n"\
" (b) Window with button (via beginScene)\n"\
" (c) Own Irrlicht window (default behavior)\n"\
" (otherKey) exit\n\n");
char key;
std::cin >> key;
if (key != 'a' && key != 'b' && key != 'c')
return 1;
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);
video::SExposedVideoData videodata((key=='b')?hIrrlichtWindow:0);

So now that we have some window, we can create an Irrlicht device inside of it. We use Irrlicht createEx() function for this. We only need the handle (HWND) to that window, set it as windowsID parameter and start up the engine as usual. That's it.

// create irrlicht device in the button window
irr::SIrrlichtCreationParameters param;
param.DriverType = driverType;
if (key=='a')
param.WindowId = reinterpret_cast<void*>(hIrrlichtWindow);
irr::IrrlichtDevice* device = irr::createDeviceEx(param);
if (!device)
return 1;
// setup a simple 3d scene
irr::scene::ISceneManager* smgr = device->getSceneManager();
video::IVideoDriver* driver = device->getVideoDriver();
if (driverType==video::EDT_OPENGL)
{
HDC HDc=GetDC(hIrrlichtWindow);
PIXELFORMATDESCRIPTOR pfd={0};
pfd.nSize=sizeof(PIXELFORMATDESCRIPTOR);
int pf = GetPixelFormat(HDc);
DescribePixelFormat(HDc, pf, sizeof(PIXELFORMATDESCRIPTOR), &pfd);
pfd.dwFlags |= PFD_DOUBLEBUFFER | PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW;
pfd.cDepthBits=16;
pf = ChoosePixelFormat(HDc, &pfd);
SetPixelFormat(HDc, pf, &pfd);
videodata.OpenGLWin32.HDc = HDc;
videodata.OpenGLWin32.HRc=wglCreateContext(HDc);
wglShareLists((HGLRC)driver->getExposedVideoData().OpenGLWin32.HRc, (HGLRC)videodata.OpenGLWin32.HRc);
}
scene::ICameraSceneNode* cam = smgr->addCameraSceneNode();
cam->setTarget(core::vector3df(0,0,0));
scene::ISceneNodeAnimator* anim =
smgr->createFlyCircleAnimator(core::vector3df(0,15,0), 30.0f);
cam->addAnimator(anim);
anim->drop();
scene::ISceneNode* cube = smgr->addCubeSceneNode(20);
cube->setMaterialTexture(0, driver->getTexture("../../media/wall.bmp"));
cube->setMaterialTexture(1, driver->getTexture("../../media/water.jpg"));
cube->setMaterialFlag( video::EMF_LIGHTING, false );
cube->setMaterialType( video::EMT_REFLECTION_2_LAYER );
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);
// do message queue

Now the only thing missing is the drawing loop using IrrlichtDevice::run(). We do this as usual. But instead of this, there is another possibility: You can also simply use your own message loop using GetMessage, DispatchMessage and whatever. Calling Device->run() will cause Irrlicht to dispatch messages internally too. You need not call Device->run() if you want to do your own message dispatching loop, but Irrlicht will not be able to fetch user input then and you have to do it on your own using the window messages, DirectInput, or whatever.

while (device->run())
{
driver->beginScene(true, true, 0, videodata);
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, (key=='c')?hIrrlichtWindow:0); smgr->drawAll(); driver->endScene(); }

device->closeDevice();
device->drop();
return 0;
}
#endif // if windows

That's it, Irrlicht now runs in your own windows window.

+
+ + +

 

+ + -- cgit v1.2.3-70-g09d2