changeset 2462:1d04e48651d4

Render split into interface and realization, added Direct3D 11
author a.parshin
date Tue, 12 Aug 2014 21:34:18 +0300
parents ff7f4995aa25
children 0f17a30149ec
files Build/Visual Studio 2012/World of Might and Magic.vcxproj Build/Visual Studio 2012/World of Might and Magic.vcxproj.filters ErrorHandling.h IRender.h LightmapBuilder.cpp Render.cpp Render.h RenderD3D11.cpp RenderD3D11.h RenderStruct.h mm7_2.cpp
diffstat 11 files changed, 866 insertions(+), 184 deletions(-) [+]
line wrap: on
line diff
--- a/Build/Visual Studio 2012/World of Might and Magic.vcxproj	Tue Aug 05 17:00:35 2014 +0600
+++ b/Build/Visual Studio 2012/World of Might and Magic.vcxproj	Tue Aug 12 21:34:18 2014 +0300
@@ -212,6 +212,7 @@
     <ClCompile Include="..\..\Random.cpp" />
     <ClCompile Include="..\..\Registry.cpp" />
     <ClCompile Include="..\..\Render.cpp" />
+    <ClCompile Include="..\..\RenderD3D11.cpp" />
     <ClCompile Include="..\..\SaveLoad.cpp" />
     <ClCompile Include="..\..\Spells.cpp" />
     <ClCompile Include="..\..\SpriteObject.cpp" />
@@ -280,6 +281,7 @@
     <ClInclude Include="..\..\Indoor.h" />
     <ClInclude Include="..\..\IndoorCameraD3D.h" />
     <ClInclude Include="..\..\Indoor_stuff.h" />
+    <ClInclude Include="..\..\IRender.h" />
     <ClInclude Include="..\..\Items.h" />
     <ClInclude Include="..\..\Keyboard.h" />
     <ClInclude Include="..\..\Level\Decoration.h" />
@@ -458,6 +460,7 @@
     <ClInclude Include="..\..\Random.h" />
     <ClInclude Include="..\..\Registry.h" />
     <ClInclude Include="..\..\Render.h" />
+    <ClInclude Include="..\..\RenderD3D11.h" />
     <ClInclude Include="..\..\RenderStruct.h" />
     <ClInclude Include="..\..\SaveLoad.h" />
     <ClInclude Include="..\..\Spells.h" />
--- a/Build/Visual Studio 2012/World of Might and Magic.vcxproj.filters	Tue Aug 05 17:00:35 2014 +0600
+++ b/Build/Visual Studio 2012/World of Might and Magic.vcxproj.filters	Tue Aug 12 21:34:18 2014 +0300
@@ -393,6 +393,7 @@
       <Filter>UI</Filter>
     </ClCompile>
     <ClCompile Include="..\..\DirectX11.cpp" />
+    <ClCompile Include="..\..\RenderD3D11.cpp" />
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="..\..\Level\Decoration.h" />
@@ -970,6 +971,8 @@
     <ClInclude Include="..\..\MapsLongTimer.h" />
     <ClInclude Include="..\..\DirectX11.h" />
     <ClInclude Include="..\..\RenderStruct.h" />
+    <ClInclude Include="..\..\IRender.h" />
+    <ClInclude Include="..\..\RenderD3D11.h" />
   </ItemGroup>
   <ItemGroup>
     <None Include="..\..\Player.swig" />
--- a/ErrorHandling.h	Tue Aug 05 17:00:35 2014 +0600
+++ b/ErrorHandling.h	Tue Aug 12 21:34:18 2014 +0300
@@ -28,7 +28,10 @@
   }
   va_end(va);
 
-  __debugbreak();
+  #ifndef NODEBUG
+    __debugbreak();
+  #endif
+  exit(0);
 }
 
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/IRender.h	Tue Aug 12 21:34:18 2014 +0300
@@ -0,0 +1,169 @@
+#pragma once
+
+#include "lib\legacy_dx\d3d.h"
+#include "OSWindow.h"
+#include "RenderStruct.h"
+#include "VectorTypes.h"
+
+struct IRender
+{
+  public:
+    virtual ~IRender() {}
+
+    virtual bool Initialize(OSWindow *window) = 0;
+
+    virtual void ClearBlack() = 0;
+    virtual void PresentBlackScreen() = 0;
+
+    virtual void SaveWinnersCertificate(const char *a1) = 0;
+    virtual void ClearTarget(unsigned int uColor) = 0;
+    virtual void Present() = 0;
+
+    virtual void _49FD3A_fullscreen() = 0;
+    virtual bool InitializeFullscreen() = 0;
+
+    virtual void CreateZBuffer() = 0;
+    virtual void Release() = 0;
+
+    virtual bool SwitchToWindow() = 0;
+    virtual void RasterLine2D(signed int uX, signed int uY, signed int uZ, signed int uW, unsigned __int16 uColor) = 0;
+    virtual void ClearZBuffer(int a2, int a3) = 0;
+    virtual void SetRasterClipRect(unsigned int uX, unsigned int uY, unsigned int uZ, unsigned int uW) = 0;
+    virtual bool LockSurface_DDraw4(IDirectDrawSurface4 *pSurface, DDSURFACEDESC2 *pDesc, unsigned int uLockFlags) = 0;
+    virtual void GetTargetPixelFormat(DDPIXELFORMAT *pOut) = 0;
+    virtual void LockRenderSurface(void **pOutSurfacePtr, unsigned int *pOutPixelsPerRow) = 0;
+    virtual void UnlockBackBuffer() = 0;
+    virtual void LockFrontBuffer(void **pOutSurface, unsigned int *pOutPixelsPerRow) = 0;
+    virtual void UnlockFrontBuffer() = 0;
+    virtual void RestoreFrontBuffer() = 0;
+    virtual void RestoreBackBuffer() = 0;
+    virtual void BltToFront(RECT *pDstRect, IDirectDrawSurface *pSrcSurface, RECT *pSrcRect, unsigned int uBltFlags) = 0;
+    virtual void BltBackToFontFast(int a2, int a3, RECT *a4) = 0;
+    virtual void BeginSceneD3D() = 0;
+
+    virtual unsigned int GetActorTintColor(float a2, int tint, int a4, int a5, RenderBillboard *a6) = 0;
+
+    virtual void DrawPolygon(unsigned int uNumVertices, struct Polygon *a3, ODMFace *a4, IDirect3DTexture2 *pTexture) = 0;
+    virtual void DrawTerrainPolygon(unsigned int uNumVertices, struct Polygon *a4, IDirect3DTexture2 *a5, bool transparent, bool clampAtTextureBorders) = 0;
+    virtual void DrawIndoorPolygon(unsigned int uNumVertices, struct BLVFace *a3, IDirect3DTexture2 *pHwTex, struct Texture *pTex, int uPackedID, unsigned int uColor, int a8) = 0;
+
+    virtual void MakeParticleBillboardAndPush_BLV(RenderBillboardTransform_local0 *a2, IDirect3DTexture2 *a3, unsigned int uDiffuse, int angle) = 0;
+    virtual void MakeParticleBillboardAndPush_ODM(RenderBillboardTransform_local0 *a2, IDirect3DTexture2 *a3, unsigned int uDiffuse, int angle) = 0;
+
+    virtual void DrawBillboards_And_MaybeRenderSpecialEffects_And_EndScene() = 0;
+    virtual void DrawBillboard_Indoor(RenderBillboardTransform_local0 *pSoftBillboard, Sprite *pSprite, int dimming_level) = 0;
+    virtual void _4A4CC9_AddSomeBillboard(struct stru6_stru1_indoor_sw_billboard *a1, int diffuse) = 0;
+    virtual void TransformBillboardsAndSetPalettesODM() = 0;
+    virtual void DrawBillboardList_BLV() = 0;
+
+    virtual void DrawProjectile(float srcX, float srcY, float a3, float a4, float dstX, float dstY, float a7, float a8, IDirect3DTexture2 *a9) = 0;
+    virtual bool LoadTexture(const char *pName, unsigned int bMipMaps, IDirectDrawSurface4 **pOutSurface, IDirect3DTexture2 **pOutTexture) = 0;
+    virtual bool MoveSpriteToDevice(Sprite *pSprite) = 0;
+
+    virtual void BeginScene() = 0;
+    virtual void EndScene() = 0;
+    virtual void ScreenFade(unsigned int color, float t) = 0;
+
+    virtual void SetTextureClipRect(unsigned int uX, unsigned int uY, unsigned int uZ, unsigned int uW) = 0;
+    virtual void ResetTextureClipRect() = 0;
+    virtual void DrawTextureRGB(unsigned int uOutX, unsigned int uOutY, RGBTexture *a4) = 0;
+    virtual void CreditsTextureScroll(unsigned int pX, unsigned int pY, int move_X, int move_Y, RGBTexture *pTexture) = 0;
+    virtual void DrawTextureIndexed(unsigned int uX, unsigned int uY, struct Texture *a4) = 0;
+
+    virtual void ZBuffer_Fill_2(signed int a2, signed int a3, struct Texture *pTexture, int a5) = 0;
+    virtual void DrawMaskToZBuffer(signed int uOutX, unsigned int uOutY, struct Texture *pTexture, int zVal) = 0;
+    virtual void DrawTextureTransparent(unsigned int uX, unsigned int uY, struct Texture *pTexture) = 0;
+    virtual void DrawAura(unsigned int a2, unsigned int a3, struct Texture *a4, struct Texture *a5, int a6, int a7, int a8) = 0;
+    virtual void _4A65CC(unsigned int x, unsigned int y, struct Texture *a4, struct Texture *a5, int a6, int a7, int a8) = 0;
+
+    virtual void DrawTransparentRedShade(unsigned int a2, unsigned int a3, struct Texture *a4) = 0;
+    virtual void DrawTransparentGreenShade(signed int a2, signed int a3, struct Texture *pTexture) = 0;
+    virtual void DrawFansTransparent(const RenderVertexD3D3 *vertices, unsigned int num_vertices) = 0;
+
+    virtual void DrawMasked(signed int a2, signed int a3, struct Texture *pTexture, unsigned __int16 mask) = 0;
+    virtual void GetLeather(unsigned int a2, unsigned int a3, struct Texture *a4, __int16 height) = 0;
+
+    virtual void DrawTextPalette(int x, int y, unsigned char* font_pixels, int a5, unsigned int uFontHeight, unsigned __int16 *pPalette, int a8) = 0;
+    virtual void DrawText(signed int uOutX, signed int uOutY, unsigned __int8 *pFontPixels, unsigned int uCharWidth, unsigned int uCharHeight, unsigned __int16 *pFontPalette, unsigned __int16 uFaceColor, unsigned __int16 uShadowColor) = 0;
+
+    virtual void FillRectFast(unsigned int uX, unsigned int uY, unsigned int uWidth, unsigned int uHeight, unsigned int uColor16) = 0;
+    virtual void _4A6DF5(unsigned __int16 *pBitmap, unsigned int uBitmapPitch, struct Vec2_int_ *pBitmapXY, void *pTarget, unsigned int uTargetPitch, Vec4_int_ *a7) = 0;
+    virtual void DrawTranslucent(unsigned int a2, unsigned int a3, struct Texture *a4) = 0;
+
+    virtual void DrawBuildingsD3D() = 0;
+
+    virtual void DrawIndoorSky(unsigned int uNumVertices, unsigned int uFaceID = 0) = 0;
+    virtual void DrawOutdoorSkyD3D() = 0;
+    virtual void DrawOutdoorSkyPolygon(unsigned int uNumVertices, struct Polygon *pSkyPolygon, IDirect3DTexture2 *pTexture) = 0;
+    virtual void DrawIndoorSkyPolygon(signed int uNumVertices, struct Polygon *pSkyPolygon, IDirect3DTexture2 *pTexture) = 0;
+
+    virtual void PrepareDecorationsRenderList_ODM() = 0;
+    virtual void DrawSpriteObjects_ODM() = 0;
+
+    virtual void RenderTerrainD3D() = 0;
+
+    virtual void ChangeBetweenWinFullscreenModes() = 0;
+    virtual bool AreRenderSurfacesOk() = 0;
+    virtual bool IsGammaSupported() = 0;
+
+    virtual void SaveScreenshot(const char *pFilename, unsigned int width, unsigned int height) = 0;
+    virtual void PackScreenshot(unsigned int width, unsigned int height, void *out_data, unsigned int data_size, unsigned int *screenshot_size) = 0;
+    virtual void SavePCXScreenshot() = 0;
+
+    virtual int _46À6ÀÑ_GetActorsInViewport(int pDepth) = 0;
+
+    virtual void BeginLightmaps() = 0;
+    virtual void EndLightmaps() = 0;
+    virtual void BeginLightmaps2() = 0;
+    virtual void EndLightmaps2() = 0;
+    virtual bool DrawLightmap(struct Lightmap *pLightmap, struct Vec3_float_ *pColorMult, float z_bias) = 0;
+
+    virtual void BeginDecals() = 0;
+    virtual void EndDecals() = 0;
+    virtual void DrawDecal(struct Decal *pDecal, float z_bias) = 0;
+  
+    virtual void do_draw_debug_line_d3d(const RenderVertexD3D3 *pLineBegin, signed int sDiffuseBegin, const RenderVertexD3D3 *pLineEnd, signed int sDiffuseEnd, float z_stuff) = 0;
+    virtual void DrawLines(const RenderVertexD3D3 *vertices, unsigned int num_vertices) = 0;
+
+    virtual void DrawSpecialEffectsQuad(const RenderVertexD3D3 *vertices, IDirect3DTexture2 *texture) = 0;
+
+    virtual void am_Blt_Copy(RECT *pSrcRect, POINT *pTargetXY, int a3) = 0;
+    virtual void am_Blt_Chroma(RECT *pSrcRect, POINT *pTargetPoint, int a3, int blend_mode) = 0;
+
+
+
+
+
+
+
+
+
+    int *pActiveZBuffer;
+    IDirectDraw4 *pDirectDraw4;
+    IDirectDrawSurface4 *pFrontBuffer4;
+    IDirectDrawSurface4 *pBackBuffer4;
+    void        *pTargetSurface;
+    unsigned int uTargetSurfacePitch;
+    unsigned int bUseColoredLights;
+    unsigned int bTinting;
+    unsigned int bUsingSpecular;
+    uint32_t uFogColor;
+    unsigned int pHDWaterBitmapIDs[7];
+    int hd_water_current_frame;
+    int hd_water_tile_id;
+    void (*pBeforePresentFunction)();
+    uint32_t bFogEnabled;
+    RenderBillboardD3D pBillboardRenderListD3D[1000];
+    unsigned int uNumBillboardsToDraw;
+
+    virtual void WritePixel16(int x, int y, unsigned __int16 color) = 0;
+    virtual unsigned __int16 ReadPixel16(int x, int y) = 0;
+
+    virtual void ToggleTint() = 0;
+    virtual void ToggleColoredLights() = 0;
+
+    virtual unsigned int GetRenderWidth() = 0;
+    virtual unsigned int GetRenderHeight() = 0;
+
+    virtual void Sub01() = 0;
+};
\ No newline at end of file
--- a/LightmapBuilder.cpp	Tue Aug 05 17:00:35 2014 +0600
+++ b/LightmapBuilder.cpp	Tue Aug 12 21:34:18 2014 +0300
@@ -1411,7 +1411,7 @@
    else
     v24 = D3DDP_DONOTLIGHT;
 
-  ErrD3D(pRenderer->pRenderD3D->pDevice->DrawPrimitive(D3DPT_TRIANGLEFAN,
+  ErrD3D(pRenderD3D->pDevice->DrawPrimitive(D3DPT_TRIANGLEFAN,
             D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_SPECULAR | D3DFVF_TEX1,
             a2,
             pLightmap->uNumVertices,
--- a/Render.cpp	Tue Aug 05 17:00:35 2014 +0600
+++ b/Render.cpp	Tue Aug 12 21:34:18 2014 +0300
@@ -44,7 +44,7 @@
 //#pragma comment(lib, "lib\\legacy_dx\\lib\\dxguid.lib")
 
 struct IDirectDrawClipper *pDDrawClipper;
-struct Render *pRenderer; // idb
+struct IRender *pRenderer; // idb
 struct RenderVertexD3D3  pVertices[50];
 int uNumDecorationsDrawnThisFrame; // weak
 RenderBillboard pBillboardRenderList[500];
@@ -143,7 +143,7 @@
   soft_billboard.sParentBillboardID = -1;
   soft_billboard.pTarget = pBLVRenderParams->pRenderTarget;
   soft_billboard.pTargetZ = pBLVRenderParams->pTargetZBuffer;
-  soft_billboard.uTargetPitch = pRenderer->uTargetSurfacePitch;
+  soft_billboard.uTargetPitch = uTargetSurfacePitch;
   soft_billboard.uViewportX = pBLVRenderParams->uViewportX;
   soft_billboard.uViewportY = pBLVRenderParams->uViewportY;
   soft_billboard.uViewportZ = pBLVRenderParams->uViewportZ - 1;
@@ -165,8 +165,8 @@
       v2 = p->HwSpriteID;
       if ( v2 != -1 )
       {
-        if ( pRenderer->pRenderD3D )
-          pRenderer->DrawBillboard_Indoor(&soft_billboard, &pSprites_LOD->pHardwareSprites[v2], p->dimming_level);
+        if ( pRenderD3D )
+          DrawBillboard_Indoor(&soft_billboard, &pSprites_LOD->pHardwareSprites[v2], p->dimming_level);
         else
         {
           soft_billboard.pPalette = PaletteManager::Get_Dark_or_Red_LUT(p->uPalette, p->dimming_level, 1);
@@ -239,7 +239,7 @@
 //  float Light_tile_dist;
 
   //warning: the game uses CW culling by default, ccw is incosistent
-  pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_CULLMODE, D3DCULL_CCW);
+  pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_CULLMODE, D3DCULL_CCW);
 
   static RenderVertexSoft pTerrainVertices[128 * 128];//vertexCountX and vertexCountZ
 
@@ -519,11 +519,11 @@
     billboard.uFlags = pBillboardRenderList[i].field_1E;
     if (pBillboardRenderList[i].HwSpriteID != -1)
     {
-      if (!pRenderer->pRenderD3D) __debugbreak(); // no sw rendering
+      if (!pRenderD3D) __debugbreak(); // no sw rendering
       //if (pRenderer->pRenderD3D)
-        pRenderer->TransformBillboard(&billboard,
-                                      &pSprites_LOD->pHardwareSprites[pBillboardRenderList[i].HwSpriteID],
-                                      pBillboardRenderList[i].dimming_level, &pBillboardRenderList[i]);
+        TransformBillboard(&billboard,
+                           &pSprites_LOD->pHardwareSprites[pBillboardRenderList[i].HwSpriteID],
+                           pBillboardRenderList[i].dimming_level, &pBillboardRenderList[i]);
       /*else
       {
           assert(false);
@@ -664,8 +664,11 @@
             pBillboardRenderList[::uNumBillboardsToDraw].sTintColor = 0;
             if ( !(object->uAttributes & 0x20) )
             {
-              if ( !pRenderer->pRenderD3D )
+              if ( !pRenderD3D )
+              {
+                __debugbreak();
                 pBillboardRenderList[::uNumBillboardsToDraw].sZValue = 0;
+              }
             }
             //if (::uNumBillboardsToDraw >= 500)
             //  return;
@@ -708,8 +711,11 @@
             pBillboardRenderList[::uNumBillboardsToDraw].sTintColor = 0;
             if ( !(object->uAttributes & 0x20) )
             {
-              if ( !pRenderer->pRenderD3D )
+              if ( !pRenderD3D )
+              {
+                __debugbreak();
                 pBillboardRenderList[::uNumBillboardsToDraw].sZValue = 0;
+              }
             }
             //if (::uNumBillboardsToDraw >= 500)
             //  return;
@@ -1034,11 +1040,11 @@
             LOBYTE(v38) = v38 | 0x80;
           if ( v8->uGlowRadius )
           {
-            if ( pRenderer->pRenderD3D && pRenderer->bUseColoredLights )
+            if ( pRenderD3D && bUseColoredLights )
             {
-              v14 = 255;//decor_desc->uColoredLightRed;
-              v15 = 255;//decor_desc->uColoredLightGreen;
-              v16 = 255;//decor_desc->uColoredLightBlue;
+              v14 = /*255;//*/decor_desc->uColoredLightRed;
+              v15 = /*255;//*/decor_desc->uColoredLightGreen;
+              v16 = /*255;//*/decor_desc->uColoredLightBlue;
             }
             else
             {
@@ -1068,10 +1074,13 @@
                 v25 = pViewport->uScreenCenterX - ((signed int)(fixpoint_mul(v24 / v20, v21) + 0x8000) >> 16);
                 v40 = pViewport->uScreenCenterY - ((signed int)(fixpoint_mul(v24 / v20, v22) + 0x8000) >> 16);
                 v41 = fixpoint_mul(v8->scale, v24 / v20);
-                if ( pRenderer->pRenderD3D )
+                if ( pRenderD3D )
                   b = fixpoint_mul(pSprites_LOD->pHardwareSprites[v8->pHwSpriteIDs[(int)v37]].uBufferWidth / 2, v41);
                 else
+                {
+                  __debugbreak();
                   b = fixpoint_mul(pSprites_LOD->pSpriteHeaders[v8->pHwSpriteIDs[(int)v37]].uWidth / 2, v41);
+                }
                 if ( b + v25 >= (signed int)pViewport->uViewportTL_X && v25 - b <= (signed int)pViewport->uViewportBR_X )
                 {
                   if (::uNumBillboardsToDraw >= 500)
@@ -1120,10 +1129,13 @@
                 v25 = pViewport->uScreenCenterX - ((signed int)(fixpoint_mul(v24 / v20, v21) + 0x8000) >> 16);
                 v40 = pViewport->uScreenCenterY - ((signed int)(fixpoint_mul(v24 / v20, v42) + 0x8000) >> 16);
                 v41 = fixpoint_mul(v8->scale, v24 / v20);
-                if ( pRenderer->pRenderD3D )
+                if ( pRenderD3D )
                   b = fixpoint_mul(pSprites_LOD->pHardwareSprites[v8->pHwSpriteIDs[(int)v37]].uBufferWidth / 2, v41);
                 else
+                {
+                  __debugbreak();
                   b = fixpoint_mul(pSprites_LOD->pSpriteHeaders[v8->pHwSpriteIDs[(int)v37]].uWidth / 2, v41);
+                }
                 if ( b + v25 >= (signed int)pViewport->uViewportTL_X && v25 - b <= (signed int)pViewport->uViewportBR_X )
                 {
                   if (::uNumBillboardsToDraw >= 500)
@@ -2249,7 +2261,7 @@
   hd_water_current_frame = 0;
 }
 
-bool Render::Initialize(OSWindow *window, bool bColoredLights, uint32_t uDetailLevel, bool bTinting)
+bool Render::Initialize(OSWindow *window/*, bool bColoredLights, uint32_t uDetailLevel, bool bTinting*/)
 {
   //bUserDirect3D = true;//ReadWindowsRegistryInt("Use D3D", 0);
 
@@ -2260,10 +2272,9 @@
 
   uDesiredDirect3DDevice = ReadWindowsRegistryInt("D3D Device", 0);
 
-  bUseColoredLights = bColoredLights;//ReadWindowsRegistryInt("Colored Lights", 0);
-  uLevelOfDetail = uDetailLevel;//ReadWindowsRegistryInt("Detail Level", 1);
-
-  this->bTinting = bTinting;
+  bUseColoredLights = ReadWindowsRegistryInt("Colored Lights", false);
+  uLevelOfDetail = ReadWindowsRegistryInt("Detail Level", 1);
+  bTinting = ReadWindowsRegistryInt("Tinting", 1) != 0;
 
   bool r1 = pD3DBitmaps.Load(L"data\\d3dbitmap.hwl");
   bool r2 = pD3DSprites.Load(L"data\\d3dsprite.hwl");
@@ -2413,11 +2424,11 @@
               //int for_rad = (pRenderer->uTargetGBits + pRenderer->uTargetBBits );//16 = 8 + 8
 			  //int value = (pRenderer->uTargetRMask & *line_picture_data);//0 = 0xFF0000 & 0x2818
 			  //int result = (pRenderer->uTargetRMask & *line_picture_data) >> (pRenderer->uTargetGBits + pRenderer->uTargetBBits );
-              lineRGB[x] = (pRenderer->uTargetRMask & *line_picture_data) >> (pRenderer->uTargetGBits + pRenderer->uTargetBBits );// + pRenderer->uTargetRBits - 8);
-              lineG[x] = (pRenderer->uTargetGMask & *line_picture_data) >> (pRenderer->uTargetBBits);// + pRenderer->uTargetGBits - 8);
+              lineRGB[x] = (uTargetRMask & *line_picture_data) >> (uTargetGBits + uTargetBBits );// + pRenderer->uTargetRBits - 8);
+              lineG[x] = (uTargetGMask & *line_picture_data) >> (uTargetBBits);// + pRenderer->uTargetGBits - 8);
 			  //int value2 = (pRenderer->uTargetGMask & *line_picture_data); //10240 = 0xFF00 & 0x2818
 			  //int result2 = (pRenderer->uTargetGMask & *line_picture_data) >> (pRenderer->uTargetBBits);
-              lineB[x] = (pRenderer->uTargetBMask & *line_picture_data);// << (8 - pRenderer->uTargetBBits);
+              lineB[x] = (uTargetBMask & *line_picture_data);// << (8 - pRenderer->uTargetBBits);
 		      //int value3 = (pRenderer->uTargetBMask & *line_picture_data);//24 = 0xFF & 0x2818
               line_picture_data += 2;
             }
@@ -2904,7 +2915,7 @@
   //RECT a4; // [sp+18h] [bp-18h]@11
   //struct tagPOINT Point; // [sp+28h] [bp-8h]@11
 
-  if ( !pRenderer->pRenderD3D || this->using_software_screen_buffer )
+  if ( !pRenderD3D || this->using_software_screen_buffer )
   {
     this->pBeforePresentFunction();
     if ( this->pRenderD3D )
@@ -3156,7 +3167,7 @@
   int g_mask = 0x7E0;
   int b_mask = 0x1F;
 
-  if ( !pRenderer->uNumSceneBegins )
+  //if ( !pRenderer->uNumSceneBegins )
   {
     //if ( pRenderer->using_software_screen_buffer )
     //{
@@ -4081,7 +4092,7 @@
       LOBYTE(result) = v9;
       return result;
     }
-    if ( pRenderer->pRenderD3D )
+    if ( pRenderD3D )
       pRenderD3D->HandleLostResources();
     result = pRenderer->pDirectDraw4->RestoreAllSurfaces();
   }
@@ -4929,9 +4940,9 @@
       pVertices[i].texcoord.x = array_50AC10[i].u;
       pVertices[i].texcoord.y = array_50AC10[i].v;
     }
-    pRenderer->pRenderD3D->pDevice->SetTexture(0, pTexture);
-    pRenderer->pRenderD3D->pDevice->DrawPrimitive(D3DPT_TRIANGLEFAN, D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_SPECULAR | D3DFVF_TEX1,
-      pVertices, uNumVertices, D3DDP_DONOTUPDATEEXTENTS | D3DDP_DONOTLIGHT);
+    pRenderD3D->pDevice->SetTexture(0, pTexture);
+    pRenderD3D->pDevice->DrawPrimitive(D3DPT_TRIANGLEFAN, D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_SPECULAR | D3DFVF_TEX1,
+                                       pVertices, uNumVertices, D3DDP_DONOTUPDATEEXTENTS | D3DDP_DONOTLIGHT);
   }
 }
 
@@ -6157,25 +6168,25 @@
   v29[3].specular = 0;
   v29[3].texcoord.x = 0.0;
   v29[3].texcoord.y = 0.0;
-  ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, TRUE));
-  ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, D3DBLEND_ONE));
-  ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, D3DBLEND_ONE));
-  ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DITHERENABLE, FALSE));
-  ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE, FALSE));
-  ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_CULLMODE, D3DCULL_NONE));
-  ErrD3D(pRenderer->pRenderD3D->pDevice->SetTexture(0, a9));
-  ErrD3D(pRenderer->pRenderD3D->pDevice->DrawPrimitive(
+  ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, TRUE));
+  ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, D3DBLEND_ONE));
+  ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, D3DBLEND_ONE));
+  ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DITHERENABLE, FALSE));
+  ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE, FALSE));
+  ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_CULLMODE, D3DCULL_NONE));
+  ErrD3D(pRenderD3D->pDevice->SetTexture(0, a9));
+  ErrD3D(pRenderD3D->pDevice->DrawPrimitive(
     D3DPT_TRIANGLEFAN,
     D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_SPECULAR | D3DFVF_TEX1,
     v29,
     4,
     24));
-  ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, FALSE));
-  ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, D3DBLEND_ONE));
-  ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, D3DBLEND_ZERO));
-  ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DITHERENABLE, TRUE));
-  ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE, TRUE));
-  ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_CULLMODE, D3DCULL_CW));
+  ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, FALSE));
+  ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, D3DBLEND_ONE));
+  ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, D3DBLEND_ZERO));
+  ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DITHERENABLE, TRUE));
+  ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE, TRUE));
+  ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_CULLMODE, D3DCULL_CW));
 }
 
 //----- (004A4CC9) --------------------------------------------------------
@@ -8180,7 +8191,7 @@
     ModalWindow(pGlobalTXT_LocalizationStrings[62], UIMSG_0);// "Might and Magic VII requires your desktop to be in 16bit (32k or 65k) Color mode in order to operate in a window."
     return;
   }*/
-  if ( pRenderer->bWindowMode || pRenderer->pRenderD3D->pAvailableDevices->bIsDeviceCompatible )
+  if ( bWindowMode || pRenderD3D->pAvailableDevices->bIsDeviceCompatible )
   {
     if ( pEventTimer->bPaused )
       dword_6BE364_game_settings_1 |= GAME_SETTINGS_0800;
@@ -8191,12 +8202,12 @@
     else
       pMiscTimer->Pause();
     pMouse->bActive = 0;
-    if ( pRenderer->pRenderD3D )
+    if ( pRenderD3D )
     {
       pBitmaps_LOD->ReleaseHardwareTextures();
       pSprites_LOD->ReleaseAll();
     }
-    if ( pRenderer->bWindowMode )
+    if ( bWindowMode )
     {
       //SetMenu(hWnd, 0);
       //SetWindowLongA(hWnd, -20, 0);
@@ -8212,19 +8223,19 @@
       window->SetWindowedMode(window->GetWidth(), window->GetHeight());
       pRenderer->SwitchToWindow();
     }
-    if ( pRenderer->pRenderD3D )
+    if ( pRenderD3D )
     {
       pBitmaps_LOD->_410423_move_textures_to_device();
       pSprites_LOD->MoveSpritesToVideoMemory();
     }
-    if (!( pPaletteManager->uNumTargetBBits == pRenderer->uTargetBBits
-      && pPaletteManager->uNumTargetGBits == pRenderer->uTargetGBits
-      && pPaletteManager->uNumTargetRBits == pRenderer->uTargetRBits ))
-    {
-      pPaletteManager->SetColorChannelInfo(pRenderer->uTargetRBits, pRenderer->uTargetGBits, pRenderer->uTargetBBits);
+    if (!( pPaletteManager->uNumTargetBBits == uTargetBBits
+      && pPaletteManager->uNumTargetGBits == uTargetGBits
+      && pPaletteManager->uNumTargetRBits == uTargetRBits ))
+    {
+      pPaletteManager->SetColorChannelInfo(uTargetRBits, uTargetGBits, uTargetBBits);
       pPaletteManager->RecalculateAll();
-      pBitmaps_LOD->SetupPalettes(pRenderer->uTargetRBits, pRenderer->uTargetGBits, pRenderer->uTargetBBits);
-      pIcons_LOD->SetupPalettes(pRenderer->uTargetRBits, pRenderer->uTargetGBits, pRenderer->uTargetBBits);
+      pBitmaps_LOD->SetupPalettes(uTargetRBits, uTargetGBits, uTargetBBits);
+      pIcons_LOD->SetupPalettes(uTargetRBits, uTargetGBits, uTargetBBits);
       for (uint i = 0; i < pObjectList->uNumObjects; i++)
       {
         BYTE3(v4) = 0;
@@ -8770,7 +8781,7 @@
   int uNumVertices; // [sp+4Ch] [bp-Ch]@34
   int unused; // [sp+50h] [bp-8h]@3
 
-  if ( !pRenderer->pRenderD3D )
+  if ( !pRenderD3D )
   {
     MessageBoxW(nullptr, L"D3D version of RenderBuildings called in software!", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Odbuild.cpp:73", 0);
   }
@@ -9171,15 +9182,15 @@
 //----- (0045E26C) --------------------------------------------------------
 void Render::SaveScreenshot(const char *pFilename, unsigned int width, unsigned int height)
 {
-  auto pixels = pRenderer->MakeScreenshot(width, height);
-  pRenderer->SavePCXImage(pFilename, pixels, width, height);
+  auto pixels = MakeScreenshot(width, height);
+  SavePCXImage(pFilename, pixels, width, height);
   free(pixels);
 }
 
 void Render::PackScreenshot(unsigned int width, unsigned int height, void *data, unsigned int data_size, unsigned int *out_screenshot_size)
 {
-  auto pixels = pRenderer->MakeScreenshot(150, 112);
-  pRenderer->PackPCXpicture(pixels, 150, 112, data, 1000000, out_screenshot_size);
+  auto pixels = MakeScreenshot(150, 112);
+  PackPCXpicture(pixels, 150, 112, data, 1000000, out_screenshot_size);
   free(pixels);
 }
 
@@ -9234,13 +9245,13 @@
   ErrD3D(pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_ADDRESS, D3DTADDRESS_CLAMP));
 
   if (bUsingSpecular)
-    pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_FOGENABLE, FALSE);
-
-  ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, TRUE));
-  ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DITHERENABLE, FALSE));
-  ErrD3D(pRenderer->pRenderD3D->pDevice->SetTexture(0, pGame->pIndoorCameraD3D->LoadTextureAndGetHardwarePtr("effpar03")));
-  ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, D3DBLEND_ONE));
-  ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, D3DBLEND_ONE));
+    pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_FOGENABLE, FALSE);
+
+  ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, TRUE));
+  ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DITHERENABLE, FALSE));
+  ErrD3D(pRenderD3D->pDevice->SetTexture(0, pGame->pIndoorCameraD3D->LoadTextureAndGetHardwarePtr("effpar03")));
+  ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, D3DBLEND_ONE));
+  ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, D3DBLEND_ONE));
 }
 
 void Render::EndLightmaps()
@@ -9269,10 +9280,10 @@
   ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, TRUE));
   ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DITHERENABLE, FALSE));
 
-  ErrD3D(pRenderer->pRenderD3D->pDevice->SetTexture(0, pGame->pIndoorCameraD3D->LoadTextureAndGetHardwarePtr("effpar03")));
-
-  ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, D3DBLEND_ONE));
-  ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, D3DBLEND_ONE));
+  ErrD3D(pRenderD3D->pDevice->SetTexture(0, pGame->pIndoorCameraD3D->LoadTextureAndGetHardwarePtr("effpar03")));
+
+  ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, D3DBLEND_ONE));
+  ErrD3D(pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, D3DBLEND_ONE));
 }
 
 
--- a/Render.h	Tue Aug 05 17:00:35 2014 +0600
+++ b/Render.h	Tue Aug 12 21:34:18 2014 +0300
@@ -9,142 +9,142 @@
 
 #include "VectorTypes.h"
 
-struct Render
+#include "IRender.h"
+
+struct Render: public IRender
 {
   Render();
-  ~Render();
+  virtual ~Render();
 
   static Render *Create() {return new Render;}
 
-  bool Initialize(OSWindow *window, bool bColoredLights, uint32_t uDetailLevel, bool bTinting);
-
+  virtual bool Initialize(OSWindow *window);
 
-  void ClearBlack();
-  void PresentBlackScreen();
+  virtual void ClearBlack();
+  virtual void PresentBlackScreen();
 
-  void SaveWinnersCertificate(const char *a1);
-  void ClearTarget(unsigned int uColor);
-  void Present();
+  virtual void SaveWinnersCertificate(const char *a1);
+  virtual void ClearTarget(unsigned int uColor);
+  virtual void Present();
 
-  void _49FD3A_fullscreen();
-  bool InitializeFullscreen();
+  virtual void _49FD3A_fullscreen();
+  virtual bool InitializeFullscreen();
 
-  void CreateZBuffer();
-  void Release();
+  virtual void CreateZBuffer();
+  virtual void Release();
 
-  bool SwitchToWindow();
-  void RasterLine2D(signed int uX, signed int uY, signed int uZ, signed int uW, unsigned __int16 uColor);
-  void ClearZBuffer(int a2, int a3);
-  void SetRasterClipRect(unsigned int uX, unsigned int uY, unsigned int uZ, unsigned int uW);
-  bool LockSurface_DDraw4(IDirectDrawSurface4 *pSurface, DDSURFACEDESC2 *pDesc, unsigned int uLockFlags);
-  void GetTargetPixelFormat(DDPIXELFORMAT *pOut);
-  void LockRenderSurface(void **pOutSurfacePtr, unsigned int *pOutPixelsPerRow);
-  void UnlockBackBuffer();
-  void LockFrontBuffer(void **pOutSurface, unsigned int *pOutPixelsPerRow);
-  void UnlockFrontBuffer();
-  void RestoreFrontBuffer();
-  void RestoreBackBuffer();
-  void BltToFront(RECT *pDstRect, IDirectDrawSurface *pSrcSurface, RECT *pSrcRect, unsigned int uBltFlags);
-  void BltBackToFontFast(int a2, int a3, RECT *a4);
-  void BeginSceneD3D();
+  virtual bool SwitchToWindow();
+  virtual void RasterLine2D(signed int uX, signed int uY, signed int uZ, signed int uW, unsigned __int16 uColor);
+  virtual void ClearZBuffer(int a2, int a3);
+  virtual void SetRasterClipRect(unsigned int uX, unsigned int uY, unsigned int uZ, unsigned int uW);
+  virtual bool LockSurface_DDraw4(IDirectDrawSurface4 *pSurface, DDSURFACEDESC2 *pDesc, unsigned int uLockFlags);
+  virtual void GetTargetPixelFormat(DDPIXELFORMAT *pOut);
+  virtual void LockRenderSurface(void **pOutSurfacePtr, unsigned int *pOutPixelsPerRow);
+  virtual void UnlockBackBuffer();
+  virtual void LockFrontBuffer(void **pOutSurface, unsigned int *pOutPixelsPerRow);
+  virtual void UnlockFrontBuffer();
+  virtual void RestoreFrontBuffer();
+  virtual void RestoreBackBuffer();
+  virtual void BltToFront(RECT *pDstRect, IDirectDrawSurface *pSrcSurface, RECT *pSrcRect, unsigned int uBltFlags);
+  virtual void BltBackToFontFast(int a2, int a3, RECT *a4);
+  virtual void BeginSceneD3D();
 
-  unsigned int GetActorTintColor(float a2, int tint, int a4, int a5, RenderBillboard *a6);
+  virtual unsigned int GetActorTintColor(float a2, int tint, int a4, int a5, RenderBillboard *a6);
 
-  void DrawPolygon(unsigned int uNumVertices, struct Polygon *a3, ODMFace *a4, IDirect3DTexture2 *pTexture);
-  void DrawTerrainPolygon(unsigned int uNumVertices, struct Polygon *a4, IDirect3DTexture2 *a5, bool transparent, bool clampAtTextureBorders);
-  void DrawIndoorPolygon(unsigned int uNumVertices, struct BLVFace *a3, IDirect3DTexture2 *pHwTex, struct Texture *pTex, int uPackedID, unsigned int uColor, int a8);
+  virtual void DrawPolygon(unsigned int uNumVertices, struct Polygon *a3, ODMFace *a4, IDirect3DTexture2 *pTexture);
+  virtual void DrawTerrainPolygon(unsigned int uNumVertices, struct Polygon *a4, IDirect3DTexture2 *a5, bool transparent, bool clampAtTextureBorders);
+  virtual void DrawIndoorPolygon(unsigned int uNumVertices, struct BLVFace *a3, IDirect3DTexture2 *pHwTex, struct Texture *pTex, int uPackedID, unsigned int uColor, int a8);
 
-  void MakeParticleBillboardAndPush_BLV(RenderBillboardTransform_local0 *a2, IDirect3DTexture2 *a3, unsigned int uDiffuse, int angle);
-  void MakeParticleBillboardAndPush_ODM(RenderBillboardTransform_local0 *a2, IDirect3DTexture2 *a3, unsigned int uDiffuse, int angle);
+  virtual void MakeParticleBillboardAndPush_BLV(RenderBillboardTransform_local0 *a2, IDirect3DTexture2 *a3, unsigned int uDiffuse, int angle);
+  virtual void MakeParticleBillboardAndPush_ODM(RenderBillboardTransform_local0 *a2, IDirect3DTexture2 *a3, unsigned int uDiffuse, int angle);
 
-  void DrawBillboards_And_MaybeRenderSpecialEffects_And_EndScene();
-  void DrawBillboard_Indoor(RenderBillboardTransform_local0 *pSoftBillboard, Sprite *pSprite, int dimming_level);
-  void _4A4CC9_AddSomeBillboard(struct stru6_stru1_indoor_sw_billboard *a1, int diffuse);
-  void TransformBillboardsAndSetPalettesODM();
-  void DrawBillboardList_BLV();
+  virtual void DrawBillboards_And_MaybeRenderSpecialEffects_And_EndScene();
+  virtual void DrawBillboard_Indoor(RenderBillboardTransform_local0 *pSoftBillboard, Sprite *pSprite, int dimming_level);
+  virtual void _4A4CC9_AddSomeBillboard(struct stru6_stru1_indoor_sw_billboard *a1, int diffuse);
+  virtual void TransformBillboardsAndSetPalettesODM();
+  virtual void DrawBillboardList_BLV();
 
-  void DrawProjectile(float srcX, float srcY, float a3, float a4, float dstX, float dstY, float a7, float a8, IDirect3DTexture2 *a9);
-  bool LoadTexture(const char *pName, unsigned int bMipMaps, IDirectDrawSurface4 **pOutSurface, IDirect3DTexture2 **pOutTexture);
-  bool MoveSpriteToDevice(Sprite *pSprite);
+  virtual void DrawProjectile(float srcX, float srcY, float a3, float a4, float dstX, float dstY, float a7, float a8, IDirect3DTexture2 *a9);
+  virtual bool LoadTexture(const char *pName, unsigned int bMipMaps, IDirectDrawSurface4 **pOutSurface, IDirect3DTexture2 **pOutTexture);
+  virtual bool MoveSpriteToDevice(Sprite *pSprite);
 
-  void BeginScene();
-  void EndScene();
-  void ScreenFade(unsigned int color, float t);
+  virtual void BeginScene();
+  virtual void EndScene();
+  virtual void ScreenFade(unsigned int color, float t);
 
-  void SetTextureClipRect(unsigned int uX, unsigned int uY, unsigned int uZ, unsigned int uW);
-  void ResetTextureClipRect();
-  void DrawTextureRGB(unsigned int uOutX, unsigned int uOutY, RGBTexture *a4);
-  void CreditsTextureScroll(unsigned int pX, unsigned int pY, int move_X, int move_Y, RGBTexture *pTexture);
-  void DrawTextureIndexed(unsigned int uX, unsigned int uY, struct Texture *a4);
+  virtual void SetTextureClipRect(unsigned int uX, unsigned int uY, unsigned int uZ, unsigned int uW);
+  virtual void ResetTextureClipRect();
+  virtual void DrawTextureRGB(unsigned int uOutX, unsigned int uOutY, RGBTexture *a4);
+  virtual void CreditsTextureScroll(unsigned int pX, unsigned int pY, int move_X, int move_Y, RGBTexture *pTexture);
+  virtual void DrawTextureIndexed(unsigned int uX, unsigned int uY, struct Texture *a4);
 
-  void ZBuffer_Fill_2(signed int a2, signed int a3, struct Texture *pTexture, int a5);
-  void DrawMaskToZBuffer(signed int uOutX, unsigned int uOutY, struct Texture *pTexture, int zVal);
-  void DrawTextureTransparent(unsigned int uX, unsigned int uY, struct Texture *pTexture);
-  void DrawAura(unsigned int a2, unsigned int a3, struct Texture *a4, struct Texture *a5, int a6, int a7, int a8);
-  void _4A65CC(unsigned int x, unsigned int y, struct Texture *a4, struct Texture *a5, int a6, int a7, int a8);
+  virtual void ZBuffer_Fill_2(signed int a2, signed int a3, struct Texture *pTexture, int a5);
+  virtual void DrawMaskToZBuffer(signed int uOutX, unsigned int uOutY, struct Texture *pTexture, int zVal);
+  virtual void DrawTextureTransparent(unsigned int uX, unsigned int uY, struct Texture *pTexture);
+  virtual void DrawAura(unsigned int a2, unsigned int a3, struct Texture *a4, struct Texture *a5, int a6, int a7, int a8);
+  virtual void _4A65CC(unsigned int x, unsigned int y, struct Texture *a4, struct Texture *a5, int a6, int a7, int a8);
 
-  void DrawTransparentRedShade(unsigned int a2, unsigned int a3, struct Texture *a4);
-  void DrawTransparentGreenShade(signed int a2, signed int a3, struct Texture *pTexture);
-  void DrawFansTransparent(const RenderVertexD3D3 *vertices, unsigned int num_vertices);
+  virtual void DrawTransparentRedShade(unsigned int a2, unsigned int a3, struct Texture *a4);
+  virtual void DrawTransparentGreenShade(signed int a2, signed int a3, struct Texture *pTexture);
+  virtual void DrawFansTransparent(const RenderVertexD3D3 *vertices, unsigned int num_vertices);
 
-  void DrawMasked(signed int a2, signed int a3, struct Texture *pTexture, unsigned __int16 mask);
-  void GetLeather(unsigned int a2, unsigned int a3, struct Texture *a4, __int16 height);
+  virtual void DrawMasked(signed int a2, signed int a3, struct Texture *pTexture, unsigned __int16 mask);
+  virtual void GetLeather(unsigned int a2, unsigned int a3, struct Texture *a4, __int16 height);
 
-  void DrawTextPalette(int x, int y, unsigned char* font_pixels, int a5, unsigned int uFontHeight, unsigned __int16 *pPalette, int a8);
-  void DrawText(signed int uOutX, signed int uOutY, unsigned __int8 *pFontPixels, unsigned int uCharWidth, unsigned int uCharHeight, unsigned __int16 *pFontPalette, unsigned __int16 uFaceColor, unsigned __int16 uShadowColor);
+  virtual void DrawTextPalette(int x, int y, unsigned char* font_pixels, int a5, unsigned int uFontHeight, unsigned __int16 *pPalette, int a8);
+  virtual void DrawText(signed int uOutX, signed int uOutY, unsigned __int8 *pFontPixels, unsigned int uCharWidth, unsigned int uCharHeight, unsigned __int16 *pFontPalette, unsigned __int16 uFaceColor, unsigned __int16 uShadowColor);
 
-  void FillRectFast(unsigned int uX, unsigned int uY, unsigned int uWidth, unsigned int uHeight, unsigned int uColor16);
-  void _4A6DF5(unsigned __int16 *pBitmap, unsigned int uBitmapPitch, struct Vec2_int_ *pBitmapXY, void *pTarget, unsigned int uTargetPitch, Vec4_int_ *a7);
-  void DrawTranslucent(unsigned int a2, unsigned int a3, struct Texture *a4);
+  virtual void FillRectFast(unsigned int uX, unsigned int uY, unsigned int uWidth, unsigned int uHeight, unsigned int uColor16);
+  virtual void _4A6DF5(unsigned __int16 *pBitmap, unsigned int uBitmapPitch, struct Vec2_int_ *pBitmapXY, void *pTarget, unsigned int uTargetPitch, Vec4_int_ *a7);
+  virtual void DrawTranslucent(unsigned int a2, unsigned int a3, struct Texture *a4);
 
-  void DrawBuildingsD3D();
+  virtual void DrawBuildingsD3D();
   //struct BSPModel *DrawBuildingsSW();
   //int OnOutdoorRedrawSW();
 
-  void DrawIndoorSky(unsigned int uNumVertices, unsigned int uFaceID);
-  void DrawOutdoorSkyD3D();
+  virtual void DrawIndoorSky(unsigned int uNumVertices, unsigned int uFaceID);
+  virtual void DrawOutdoorSkyD3D();
   //int DrawSkySW(struct Span *a1, Polygon *a2, int a3);
-  void DrawOutdoorSkyPolygon(unsigned int uNumVertices, struct Polygon *pSkyPolygon, IDirect3DTexture2 *pTexture);
-  void DrawIndoorSkyPolygon(signed int uNumVertices, struct Polygon *pSkyPolygon, IDirect3DTexture2 *pTexture);
+  virtual void DrawOutdoorSkyPolygon(unsigned int uNumVertices, struct Polygon *pSkyPolygon, IDirect3DTexture2 *pTexture);
+  virtual void DrawIndoorSkyPolygon(signed int uNumVertices, struct Polygon *pSkyPolygon, IDirect3DTexture2 *pTexture);
 
-  void PrepareDecorationsRenderList_ODM();
-  void DrawSpriteObjects_ODM();
+  virtual void PrepareDecorationsRenderList_ODM();
+  virtual void DrawSpriteObjects_ODM();
 
   //float DrawBezierTerrain();
-  void RenderTerrainD3D();
-  void DrawTerrainD3D(int a1, int edx0, int a3, int unk4);
+  virtual void RenderTerrainD3D();
   //void DrawTerrainSW(int a1, int a2, int a3, int a4);
 
   //void ExecOutdoorDrawSW();
-  void ChangeBetweenWinFullscreenModes();
-  bool AreRenderSurfacesOk();
-  bool IsGammaSupported();
+  virtual void ChangeBetweenWinFullscreenModes();
+  virtual bool AreRenderSurfacesOk();
+  virtual bool IsGammaSupported();
 
-  void SaveScreenshot(const char *pFilename, unsigned int width, unsigned int height);
-  void PackScreenshot(unsigned int width, unsigned int height, void *out_data, unsigned int data_size, unsigned int *screenshot_size);
-  void SavePCXScreenshot();
+  virtual void SaveScreenshot(const char *pFilename, unsigned int width, unsigned int height);
+  virtual void PackScreenshot(unsigned int width, unsigned int height, void *out_data, unsigned int data_size, unsigned int *screenshot_size);
+  virtual void SavePCXScreenshot();
 
-  int _46À6ÀÑ_GetActorsInViewport(int pDepth);
+  virtual int _46À6ÀÑ_GetActorsInViewport(int pDepth);
 
-  void BeginLightmaps();
-  void EndLightmaps();  
-  void BeginLightmaps2();
-  void EndLightmaps2();
-  bool DrawLightmap(struct Lightmap *pLightmap, struct Vec3_float_ *pColorMult, float z_bias);
+  virtual void BeginLightmaps();
+  virtual void EndLightmaps();  
+  virtual void BeginLightmaps2();
+  virtual void EndLightmaps2();
+  virtual bool DrawLightmap(struct Lightmap *pLightmap, struct Vec3_float_ *pColorMult, float z_bias);
 
-  void BeginDecals();
-  void EndDecals();
-  void DrawDecal(struct Decal *pDecal, float z_bias);
+  virtual void BeginDecals();
+  virtual void EndDecals();
+  virtual void DrawDecal(struct Decal *pDecal, float z_bias);
   
-  void do_draw_debug_line_d3d(const RenderVertexD3D3 *pLineBegin, signed int sDiffuseBegin, const RenderVertexD3D3 *pLineEnd, signed int sDiffuseEnd, float z_stuff);
-  void DrawLines(const RenderVertexD3D3 *vertices, unsigned int num_vertices);
+  virtual void do_draw_debug_line_d3d(const RenderVertexD3D3 *pLineBegin, signed int sDiffuseBegin, const RenderVertexD3D3 *pLineEnd, signed int sDiffuseEnd, float z_stuff);
+  virtual void DrawLines(const RenderVertexD3D3 *vertices, unsigned int num_vertices);
 
-  void DrawSpecialEffectsQuad(const RenderVertexD3D3 *vertices, IDirect3DTexture2 *texture);
+  virtual void DrawSpecialEffectsQuad(const RenderVertexD3D3 *vertices, IDirect3DTexture2 *texture);
 
-  void am_Blt_Copy(RECT *pSrcRect, POINT *pTargetXY, int a3);
-  void am_Blt_Chroma(RECT *pSrcRect, POINT *pTargetPoint, int a3, int blend_mode);
+  virtual void am_Blt_Copy(RECT *pSrcRect, POINT *pTargetXY, int a3);
+  virtual void am_Blt_Chroma(RECT *pSrcRect, POINT *pTargetPoint, int a3, int blend_mode);
 
-  public:
+  public:/*
     int *pActiveZBuffer;
     IDirectDraw4 *pDirectDraw4;
     IDirectDrawSurface4 *pFrontBuffer4;
@@ -161,9 +161,9 @@
     void (*pBeforePresentFunction)();
     uint32_t bFogEnabled;
     RenderBillboardD3D pBillboardRenderListD3D[1000];
-    unsigned int uNumBillboardsToDraw;
+    unsigned int uNumBillboardsToDraw;*/
 
-    inline void WritePixel16(int x, int y, unsigned __int16 color)
+    virtual void WritePixel16(int x, int y, unsigned __int16 color)
     {
       if (ddpfPrimarySuface.dwRGBBitCount == 32)
       {
@@ -178,7 +178,7 @@
       else __debugbreak();
     }
 
-    inline unsigned __int16 ReadPixel16(int x, int y)
+    virtual unsigned __int16 ReadPixel16(int x, int y)
     {
       if (ddpfPrimarySuface.dwRGBBitCount == 32)
       {
@@ -193,13 +193,13 @@
       else __debugbreak();
     }
 
-    inline void ToggleTint()          {bTinting = !bTinting;}
-    inline void ToggleColoredLights() {bUseColoredLights = !bUseColoredLights;}
+    virtual void ToggleTint()          {bTinting = !bTinting;}
+    virtual void ToggleColoredLights() {bUseColoredLights = !bUseColoredLights;}
 
-    inline unsigned int GetRenderWidth() {return window->GetWidth();}
-    inline unsigned int GetRenderHeight() {return window->GetHeight();}
+    virtual unsigned int GetRenderWidth() {return window->GetWidth();}
+    virtual unsigned int GetRenderHeight() {return window->GetHeight();}
 
-    inline void Sub01()
+    virtual void Sub01()
     {
       if (pRenderD3D && !bWindowMode)
         _49FD3A_fullscreen();
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/RenderD3D11.cpp	Tue Aug 12 21:34:18 2014 +0300
@@ -0,0 +1,320 @@
+#include <d3dcompiler.h>
+#include <comdef.h> // _com_error
+
+#include "ErrorHandling.h"
+#include "RenderD3D11.h"
+#include "mm7_data.h"
+
+#define ErrorD3D(x)\
+{\
+  HRESULT hr = x;\
+  if (FAILED(hr))\
+  {\
+    _com_error com_error(hr);\
+    Error("HRESULT = %08X\n%S", hr, com_error.ErrorMessage());\
+  }\
+}
+
+
+RenderD3D11::RenderD3D11() {}
+RenderD3D11::~RenderD3D11() {}
+
+
+void RenderD3D11::ClearBlack() {__debugbreak();}
+void RenderD3D11::SaveWinnersCertificate(const char *a1) {__debugbreak();}
+void RenderD3D11::Present() {__debugbreak();}
+void RenderD3D11::_49FD3A_fullscreen() {__debugbreak();}
+bool RenderD3D11::InitializeFullscreen() {__debugbreak(); return 0;}
+void RenderD3D11::CreateZBuffer() {__debugbreak();}
+void RenderD3D11::Release() {__debugbreak();}
+void RenderD3D11::RasterLine2D(signed int uX, signed int uY, signed int uZ, signed int uW, unsigned __int16 uColor) {__debugbreak();}
+void RenderD3D11::ClearZBuffer(int a2, int a3) {__debugbreak();}
+void RenderD3D11::SetRasterClipRect(unsigned int uX, unsigned int uY, unsigned int uZ, unsigned int uW) {__debugbreak();}
+bool RenderD3D11::LockSurface_DDraw4(IDirectDrawSurface4 *pSurface, DDSURFACEDESC2 *pDesc, unsigned int uLockFlags) {__debugbreak(); return 0;}
+void RenderD3D11::GetTargetPixelFormat(DDPIXELFORMAT *pOut) {__debugbreak();}
+void RenderD3D11::LockRenderSurface(void **pOutSurfacePtr, unsigned int *pOutPixelsPerRow) {__debugbreak();}
+void RenderD3D11::UnlockBackBuffer() {__debugbreak();}
+void RenderD3D11::LockFrontBuffer(void **pOutSurface, unsigned int *pOutPixelsPerRow) {__debugbreak();}
+void RenderD3D11::UnlockFrontBuffer() {__debugbreak();}
+void RenderD3D11::RestoreFrontBuffer() {__debugbreak();}
+void RenderD3D11::RestoreBackBuffer() {__debugbreak();}
+void RenderD3D11::BltToFront(RECT *pDstRect, IDirectDrawSurface *pSrcSurface, RECT *pSrcRect, unsigned int uBltFlags) {__debugbreak();}
+void RenderD3D11::BltBackToFontFast(int a2, int a3, RECT *a4) {__debugbreak();}
+void RenderD3D11::BeginSceneD3D() {__debugbreak();}
+unsigned int RenderD3D11::GetActorTintColor(float a2, int tint, int a4, int a5, RenderBillboard *a6) {__debugbreak(); return 0;}
+void RenderD3D11::DrawPolygon(unsigned int uNumVertices, struct Polygon *a3, ODMFace *a4, IDirect3DTexture2 *pTexture) {__debugbreak();}
+void RenderD3D11::DrawTerrainPolygon(unsigned int uNumVertices, struct Polygon *a4, IDirect3DTexture2 *a5, bool transparent, bool clampAtTextureBorders) {__debugbreak();}
+void RenderD3D11::DrawIndoorPolygon(unsigned int uNumVertices, struct BLVFace *a3, IDirect3DTexture2 *pHwTex, struct Texture *pTex, int uPackedID, unsigned int uColor, int a8) {__debugbreak();}
+void RenderD3D11::MakeParticleBillboardAndPush_BLV(RenderBillboardTransform_local0 *a2, IDirect3DTexture2 *a3, unsigned int uDiffuse, int angle) {__debugbreak();}
+void RenderD3D11::MakeParticleBillboardAndPush_ODM(RenderBillboardTransform_local0 *a2, IDirect3DTexture2 *a3, unsigned int uDiffuse, int angle) {__debugbreak();}
+void RenderD3D11::DrawBillboards_And_MaybeRenderSpecialEffects_And_EndScene() {__debugbreak();}
+void RenderD3D11::DrawBillboard_Indoor(RenderBillboardTransform_local0 *pSoftBillboard, Sprite *pSprite, int dimming_level) {__debugbreak();}
+void RenderD3D11::_4A4CC9_AddSomeBillboard(struct stru6_stru1_indoor_sw_billboard *a1, int diffuse) {__debugbreak();}
+void RenderD3D11::TransformBillboardsAndSetPalettesODM() {__debugbreak();}
+void RenderD3D11::DrawBillboardList_BLV() {__debugbreak();}
+void RenderD3D11::DrawProjectile(float srcX, float srcY, float a3, float a4, float dstX, float dstY, float a7, float a8, IDirect3DTexture2 *a9) {__debugbreak();}
+bool RenderD3D11::LoadTexture(const char *pName, unsigned int bMipMaps, IDirectDrawSurface4 **pOutSurface, IDirect3DTexture2 **pOutTexture) {__debugbreak(); return 0;}
+bool RenderD3D11::MoveSpriteToDevice(Sprite *pSprite) {__debugbreak(); return 0;}
+void RenderD3D11::ScreenFade(unsigned int color, float t) {__debugbreak();}
+void RenderD3D11::SetTextureClipRect(unsigned int uX, unsigned int uY, unsigned int uZ, unsigned int uW) {__debugbreak();}
+void RenderD3D11::ResetTextureClipRect() {__debugbreak();}
+void RenderD3D11::CreditsTextureScroll(unsigned int pX, unsigned int pY, int move_X, int move_Y, RGBTexture *pTexture) {__debugbreak();}
+void RenderD3D11::DrawTextureIndexed(unsigned int uX, unsigned int uY, struct Texture *a4) {__debugbreak();}
+void RenderD3D11::ZBuffer_Fill_2(signed int a2, signed int a3, struct Texture *pTexture, int a5) {__debugbreak();}
+void RenderD3D11::DrawMaskToZBuffer(signed int uOutX, unsigned int uOutY, struct Texture *pTexture, int zVal) {__debugbreak();}
+void RenderD3D11::DrawTextureTransparent(unsigned int uX, unsigned int uY, struct Texture *pTexture) {__debugbreak();}
+void RenderD3D11::DrawAura(unsigned int a2, unsigned int a3, struct Texture *a4, struct Texture *a5, int a6, int a7, int a8) {__debugbreak();}
+void RenderD3D11::_4A65CC(unsigned int x, unsigned int y, struct Texture *a4, struct Texture *a5, int a6, int a7, int a8) {__debugbreak();}
+void RenderD3D11::DrawTransparentRedShade(unsigned int a2, unsigned int a3, struct Texture *a4) {__debugbreak();}
+void RenderD3D11::DrawTransparentGreenShade(signed int a2, signed int a3, struct Texture *pTexture) {__debugbreak();}
+void RenderD3D11::DrawFansTransparent(const RenderVertexD3D3 *vertices, unsigned int num_vertices) {__debugbreak();}
+void RenderD3D11::DrawMasked(signed int a2, signed int a3, struct Texture *pTexture, unsigned __int16 mask) {__debugbreak();}
+void RenderD3D11::GetLeather(unsigned int a2, unsigned int a3, struct Texture *a4, __int16 height) {__debugbreak();}
+void RenderD3D11::DrawTextPalette(int x, int y, unsigned char* font_pixels, int a5, unsigned int uFontHeight, unsigned __int16 *pPalette, int a8) {__debugbreak();}
+void RenderD3D11::DrawText(signed int uOutX, signed int uOutY, unsigned __int8 *pFontPixels, unsigned int uCharWidth, unsigned int uCharHeight, unsigned __int16 *pFontPalette, unsigned __int16 uFaceColor, unsigned __int16 uShadowColor) {__debugbreak();}
+void RenderD3D11::FillRectFast(unsigned int uX, unsigned int uY, unsigned int uWidth, unsigned int uHeight, unsigned int uColor16) {__debugbreak();}
+void RenderD3D11::_4A6DF5(unsigned __int16 *pBitmap, unsigned int uBitmapPitch, struct Vec2_int_ *pBitmapXY, void *pTarget, unsigned int uTargetPitch, Vec4_int_ *a7) {__debugbreak();}
+void RenderD3D11::DrawTranslucent(unsigned int a2, unsigned int a3, struct Texture *a4) {__debugbreak();}
+void RenderD3D11::DrawBuildingsD3D() {__debugbreak();}
+void RenderD3D11::DrawIndoorSky(unsigned int uNumVertices, unsigned int uFaceID) {__debugbreak();}
+void RenderD3D11::DrawOutdoorSkyD3D() {__debugbreak();}
+void RenderD3D11::DrawOutdoorSkyPolygon(unsigned int uNumVertices, struct Polygon *pSkyPolygon, IDirect3DTexture2 *pTexture) {__debugbreak();}
+void RenderD3D11::DrawIndoorSkyPolygon(signed int uNumVertices, struct Polygon *pSkyPolygon, IDirect3DTexture2 *pTexture) {__debugbreak();}
+void RenderD3D11::PrepareDecorationsRenderList_ODM() {__debugbreak();}
+void RenderD3D11::DrawSpriteObjects_ODM() {__debugbreak();}
+void RenderD3D11::RenderTerrainD3D() {__debugbreak();}
+void RenderD3D11::ChangeBetweenWinFullscreenModes() {__debugbreak();}
+bool RenderD3D11::AreRenderSurfacesOk() {__debugbreak(); return 0;}
+void RenderD3D11::SaveScreenshot(const char *pFilename, unsigned int width, unsigned int height) {__debugbreak();}
+void RenderD3D11::PackScreenshot(unsigned int width, unsigned int height, void *out_data, unsigned int data_size, unsigned int *screenshot_size) {__debugbreak();}
+void RenderD3D11::SavePCXScreenshot() {__debugbreak();}
+int RenderD3D11::_46À6ÀÑ_GetActorsInViewport(int pDepth) {__debugbreak(); return 0;}
+void RenderD3D11::BeginLightmaps() {__debugbreak();}
+void RenderD3D11::EndLightmaps() {__debugbreak();}
+void RenderD3D11::BeginLightmaps2() {__debugbreak();}
+void RenderD3D11::EndLightmaps2() {__debugbreak();}
+bool RenderD3D11::DrawLightmap(struct Lightmap *pLightmap, struct Vec3_float_ *pColorMult, float z_bias) {__debugbreak(); return 0;}
+void RenderD3D11::BeginDecals() {__debugbreak();}
+void RenderD3D11::EndDecals() {__debugbreak();}
+void RenderD3D11::DrawDecal(struct Decal *pDecal, float z_bias) {__debugbreak();}
+void RenderD3D11::do_draw_debug_line_d3d(const RenderVertexD3D3 *pLineBegin, signed int sDiffuseBegin, const RenderVertexD3D3 *pLineEnd, signed int sDiffuseEnd, float z_stuff) {__debugbreak();}
+void RenderD3D11::DrawLines(const RenderVertexD3D3 *vertices, unsigned int num_vertices) {__debugbreak();}
+void RenderD3D11::DrawSpecialEffectsQuad(const RenderVertexD3D3 *vertices, IDirect3DTexture2 *texture) {__debugbreak();}
+void RenderD3D11::am_Blt_Copy(RECT *pSrcRect, POINT *pTargetXY, int a3) {__debugbreak();}
+void RenderD3D11::am_Blt_Chroma(RECT *pSrcRect, POINT *pTargetPoint, int a3, int blend_mode) {__debugbreak();}
+
+void RenderD3D11::Sub01() {__debugbreak();}
+
+
+
+
+
+void RenderD3D11::PresentBlackScreen()
+{
+  ClearTarget(0xFF000000);
+  ErrorD3D(pSwapChain->Present(0, 0));
+}
+
+void RenderD3D11::BeginScene() {}
+void RenderD3D11::EndScene() {}
+
+void RenderD3D11::ClearTarget(unsigned int uColor)
+{
+  float clear_color[] =
+  {
+    ((uColor & 0x00FF0000) >> 16) / 255.0f,
+    ((uColor & 0x0000FF00) >> 8) / 255.0f,
+    ((uColor & 0x000000FF) >> 0) / 255.0f,
+    ((uColor & 0xFF000000) >> 24) / 255.0f
+  };
+  d3dc->ClearRenderTargetView(primary_srv, clear_color);
+}
+
+
+void RenderD3D11::DrawTextureRGB(unsigned int uOutX, unsigned int uOutY, RGBTexture *a4)
+{
+  __debugbreak();
+}
+
+bool RenderD3D11::IsGammaSupported()
+{
+  return false;
+}
+
+struct
+{
+  unsigned char restore_resolution;
+  unsigned char  _saved_screen_bpp;
+  unsigned short _saved_screen_width;
+  unsigned short _saved_screen_height;
+} on_exit;
+
+void ChangeResolution(int new_width, int new_height, int new_bpp)
+{
+  if (!on_exit.restore_resolution)
+  {
+    on_exit.restore_resolution = true;
+
+    auto hdc = GetDC(nullptr);
+    {
+      on_exit._saved_screen_width = GetDeviceCaps(hdc, HORZRES);
+      on_exit._saved_screen_height = GetDeviceCaps(hdc, VERTRES);
+      on_exit._saved_screen_bpp = GetDeviceCaps(hdc, BITSPIXEL);
+    }
+    ReleaseDC(nullptr, hdc);
+  }
+
+  DEVMODEA dm;
+  dm.dmSize = sizeof(dm);
+  dm.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
+  dm.dmBitsPerPel = new_bpp;
+  dm.dmPelsWidth = new_width;
+  dm.dmPelsHeight = new_height;
+      
+  if (ChangeDisplaySettingsA(&dm, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL)
+    Error("ChangeDisplaySettingsA");
+}
+
+__declspec(noreturn) void ExitApp()
+{
+  if (on_exit.restore_resolution)
+    ChangeResolution(on_exit._saved_screen_width, on_exit._saved_screen_height, on_exit._saved_screen_bpp);
+
+  ExitProcess(0);
+}
+
+
+
+bool RenderD3D11::SwitchToWindow()
+{
+  if (on_exit.restore_resolution)
+  {
+    on_exit.restore_resolution = false;
+    ChangeResolution(on_exit._saved_screen_width, on_exit._saved_screen_height, on_exit._saved_screen_bpp);
+  }
+  return true;
+}
+
+
+
+
+bool RenderD3D11::Initialize(OSWindow *window)
+{
+  this->window = window;
+
+  auto d3d_lib = LoadLibraryW(L"d3d11.dll");
+  if (!d3d_lib)
+    return Error("d3d11.dll is missing"), false;
+
+
+  DXGI_SWAP_CHAIN_DESC swapChainDesc;
+  memset(&swapChainDesc, 0, sizeof(swapChainDesc));
+  swapChainDesc.BufferDesc.Width = window->GetWidth();
+  swapChainDesc.BufferDesc.Height = window->GetHeight();
+  //swapChainDesc.BufferDesc.RefreshRate.Numerator = 0;
+  //swapChainDesc.BufferDesc.RefreshRate.Denominator = 0;
+  swapChainDesc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
+  //swapChainDesc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
+  //swapChainDesc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
+  swapChainDesc.SampleDesc.Count = 1;
+  //swapChainDesc.SampleDesc.Quality = 0;
+  swapChainDesc.BufferUsage =  DXGI_USAGE_RENDER_TARGET_OUTPUT;
+  swapChainDesc.BufferCount = 2;
+  swapChainDesc.OutputWindow = window->GetApiHandle();
+  swapChainDesc.Windowed = true;
+  //swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
+  //swapChainDesc.Flags = 0;
+
+
+  D3D_FEATURE_LEVEL requested_feature_level =  D3D_FEATURE_LEVEL_11_0,
+                    received_feature_level;
+
+  unsigned int device_flags = 0;//D3D11_CREATE_DEVICE_DISABLE_GPU_TIMEOUT;
+  #ifndef NODEBUG
+    device_flags |= D3D11_CREATE_DEVICE_DEBUG /*| D3D11_CREATE_DEVICE_DEBUGGABLE*/;
+  #endif
+
+  HRESULT (__stdcall *dll_D3D11CreateDeviceAndSwapChain)(IDXGIAdapter* pAdapter, D3D_DRIVER_TYPE DriverType, HMODULE Software, UINT Flags, CONST D3D_FEATURE_LEVEL* pFeatureLevels, UINT FeatureLevels, UINT SDKVersion, CONST DXGI_SWAP_CHAIN_DESC* pSwapChainDesc, IDXGISwapChain** ppSwapChain, ID3D11Device** ppDevice, D3D_FEATURE_LEVEL* pFeatureLevel, ID3D11DeviceContext** ppImmediateContext);
+  dll_D3D11CreateDeviceAndSwapChain = (decltype(dll_D3D11CreateDeviceAndSwapChain))GetProcAddress(d3d_lib, "D3D11CreateDeviceAndSwapChain");
+  ErrorD3D(dll_D3D11CreateDeviceAndSwapChain(nullptr, D3D_DRIVER_TYPE_HARDWARE, nullptr, device_flags, &requested_feature_level, 1, D3D11_SDK_VERSION, &swapChainDesc, &pSwapChain, &d3dd, &received_feature_level, &d3dc));
+
+      /*if (fullscreen)
+      {
+        extern void ChangeResolution(int new_dith, int new_height, int new_bpp);
+        ChangeResolution(target_window->GetWidth(), target_window->GetHeight(), 32);
+
+        target_window->SetPosition(0, 0);
+        target_window->SetTopmost(true);
+      }
+      ErrorD3D(pSwapChain->SetFullscreenState(fullscreen, nullptr));*/
+
+
+  ID3D11Texture2D *pSwapChainSurface;
+  {
+    ErrorD3D(pSwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (void **)&pSwapChainSurface));
+    ErrorD3D(d3dd->CreateRenderTargetView(pSwapChainSurface, nullptr, &primary_srv));
+  }
+  pSwapChainSurface->Release();
+
+
+  D3D11_TEXTURE2D_DESC z_desc;
+  memset(&z_desc, 0, sizeof(z_desc));
+  z_desc.Width = window->GetWidth();
+  z_desc.Height = window->GetHeight();
+  z_desc.MipLevels = 1;
+  z_desc.ArraySize = 1;
+  z_desc.Format = DXGI_FORMAT_D32_FLOAT;
+  z_desc.SampleDesc.Count = 1;
+  //z_desc.SampleDesc.Quality = 0;
+  //z_desc.Usage = D3D11_USAGE_DEFAULT;
+  z_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
+  //z_desc.CPUAccessFlags = 0;
+  //z_desc.MiscFlags = 0;
+
+  ID3D11Texture2D *depth_surface;
+  ErrorD3D(d3dd->CreateTexture2D(&z_desc, nullptr, &depth_surface));
+
+  D3D11_DEPTH_STENCIL_VIEW_DESC depth_srv_desc;
+  memset(&depth_srv_desc, 0, sizeof(depth_srv_desc));
+  depth_srv_desc.Format = DXGI_FORMAT_D32_FLOAT;
+  depth_srv_desc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
+  //depth_srv_desc.Texture2D.MipSlice = 0;
+  ErrorD3D(d3dd->CreateDepthStencilView(depth_surface, &depth_srv_desc, &depth_srv));
+
+  d3dc->OMSetRenderTargets(1, &primary_srv, depth_srv);
+  d3dc->ClearDepthStencilView(depth_srv, D3D11_CLEAR_DEPTH, 1.0f, 0);
+
+
+
+  D3D11_RASTERIZER_DESC d3drs_desc;
+  memset(&d3drs_desc, 0, sizeof(d3drs_desc));
+  d3drs_desc.FillMode = D3D11_FILL_SOLID;
+  d3drs_desc.CullMode = D3D11_CULL_NONE;
+  //d3drs_desc.FrontCounterClockwise = false;
+  //d3drs_desc.DepthBias = 0;
+  //d3drs_desc.DepthBiasClamp = 0.0f;
+  //d3drs_desc.SlopeScaledDepthBias = 0.0f;
+  //d3drs_desc.DepthClipEnable = true;
+  //d3drs_desc.ScissorEnable = false;
+  //d3drs_desc.MultisampleEnable = false;
+  //d3drs_desc.AntialiasedLineEnable = false;
+
+  ID3D11RasterizerState *d3drs;
+  ErrorD3D(d3dd->CreateRasterizerState(&d3drs_desc, &d3drs));
+  d3dc->RSSetState(d3drs);
+  d3drs->Release();
+
+
+
+  D3D11_VIEWPORT viewport;
+  memset(&viewport, 0, sizeof(viewport));
+  viewport.TopLeftX = game_viewport_x;
+  viewport.TopLeftY = game_viewport_y;
+  viewport.Width    = game_viewport_width;
+  viewport.Height   = game_viewport_height;
+  //viewport.MinDepth = 0;
+  viewport.MaxDepth = 1;
+  d3dc->RSSetViewports(1, &viewport);
+
+  return true;
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/RenderD3D11.h	Tue Aug 12 21:34:18 2014 +0300
@@ -0,0 +1,172 @@
+#pragma once
+
+#include <cstdint>
+#include <cstdio>
+
+#include "lib\legacy_dx\d3d.h"
+#include <d3d11.h>
+
+#include "OSWindow.h"
+#include "RenderStruct.h"
+
+#include "VectorTypes.h"
+
+#include "IRender.h"
+
+struct RenderD3D11: public IRender
+{
+  RenderD3D11();
+  virtual ~RenderD3D11();
+
+  static RenderD3D11 *Create() {return new RenderD3D11;}
+
+  virtual bool Initialize(OSWindow *window);
+
+  virtual void ClearBlack();
+  virtual void PresentBlackScreen();
+
+  virtual void SaveWinnersCertificate(const char *a1);
+  virtual void ClearTarget(unsigned int uColor);
+  virtual void Present();
+
+  virtual void _49FD3A_fullscreen();
+  virtual bool InitializeFullscreen();
+
+  virtual void CreateZBuffer();
+  virtual void Release();
+
+  virtual bool SwitchToWindow();
+  virtual void RasterLine2D(signed int uX, signed int uY, signed int uZ, signed int uW, unsigned __int16 uColor);
+  virtual void ClearZBuffer(int a2, int a3);
+  virtual void SetRasterClipRect(unsigned int uX, unsigned int uY, unsigned int uZ, unsigned int uW);
+  virtual bool LockSurface_DDraw4(IDirectDrawSurface4 *pSurface, DDSURFACEDESC2 *pDesc, unsigned int uLockFlags);
+  virtual void GetTargetPixelFormat(DDPIXELFORMAT *pOut);
+  virtual void LockRenderSurface(void **pOutSurfacePtr, unsigned int *pOutPixelsPerRow);
+  virtual void UnlockBackBuffer();
+  virtual void LockFrontBuffer(void **pOutSurface, unsigned int *pOutPixelsPerRow);
+  virtual void UnlockFrontBuffer();
+  virtual void RestoreFrontBuffer();
+  virtual void RestoreBackBuffer();
+  virtual void BltToFront(RECT *pDstRect, IDirectDrawSurface *pSrcSurface, RECT *pSrcRect, unsigned int uBltFlags);
+  virtual void BltBackToFontFast(int a2, int a3, RECT *a4);
+  virtual void BeginSceneD3D();
+
+  virtual unsigned int GetActorTintColor(float a2, int tint, int a4, int a5, RenderBillboard *a6);
+
+  virtual void DrawPolygon(unsigned int uNumVertices, struct Polygon *a3, ODMFace *a4, IDirect3DTexture2 *pTexture);
+  virtual void DrawTerrainPolygon(unsigned int uNumVertices, struct Polygon *a4, IDirect3DTexture2 *a5, bool transparent, bool clampAtTextureBorders);
+  virtual void DrawIndoorPolygon(unsigned int uNumVertices, struct BLVFace *a3, IDirect3DTexture2 *pHwTex, struct Texture *pTex, int uPackedID, unsigned int uColor, int a8);
+
+  virtual void MakeParticleBillboardAndPush_BLV(RenderBillboardTransform_local0 *a2, IDirect3DTexture2 *a3, unsigned int uDiffuse, int angle);
+  virtual void MakeParticleBillboardAndPush_ODM(RenderBillboardTransform_local0 *a2, IDirect3DTexture2 *a3, unsigned int uDiffuse, int angle);
+
+  virtual void DrawBillboards_And_MaybeRenderSpecialEffects_And_EndScene();
+  virtual void DrawBillboard_Indoor(RenderBillboardTransform_local0 *pSoftBillboard, Sprite *pSprite, int dimming_level);
+  virtual void _4A4CC9_AddSomeBillboard(struct stru6_stru1_indoor_sw_billboard *a1, int diffuse);
+  virtual void TransformBillboardsAndSetPalettesODM();
+  virtual void DrawBillboardList_BLV();
+
+  virtual void DrawProjectile(float srcX, float srcY, float a3, float a4, float dstX, float dstY, float a7, float a8, IDirect3DTexture2 *a9);
+  virtual bool LoadTexture(const char *pName, unsigned int bMipMaps, IDirectDrawSurface4 **pOutSurface, IDirect3DTexture2 **pOutTexture);
+  virtual bool MoveSpriteToDevice(Sprite *pSprite);
+
+  virtual void BeginScene();
+  virtual void EndScene();
+  virtual void ScreenFade(unsigned int color, float t);
+
+  virtual void SetTextureClipRect(unsigned int uX, unsigned int uY, unsigned int uZ, unsigned int uW);
+  virtual void ResetTextureClipRect();
+  virtual void DrawTextureRGB(unsigned int uOutX, unsigned int uOutY, RGBTexture *a4);
+  virtual void CreditsTextureScroll(unsigned int pX, unsigned int pY, int move_X, int move_Y, RGBTexture *pTexture);
+  virtual void DrawTextureIndexed(unsigned int uX, unsigned int uY, struct Texture *a4);
+
+  virtual void ZBuffer_Fill_2(signed int a2, signed int a3, struct Texture *pTexture, int a5);
+  virtual void DrawMaskToZBuffer(signed int uOutX, unsigned int uOutY, struct Texture *pTexture, int zVal);
+  virtual void DrawTextureTransparent(unsigned int uX, unsigned int uY, struct Texture *pTexture);
+  virtual void DrawAura(unsigned int a2, unsigned int a3, struct Texture *a4, struct Texture *a5, int a6, int a7, int a8);
+  virtual void _4A65CC(unsigned int x, unsigned int y, struct Texture *a4, struct Texture *a5, int a6, int a7, int a8);
+
+  virtual void DrawTransparentRedShade(unsigned int a2, unsigned int a3, struct Texture *a4);
+  virtual void DrawTransparentGreenShade(signed int a2, signed int a3, struct Texture *pTexture);
+  virtual void DrawFansTransparent(const RenderVertexD3D3 *vertices, unsigned int num_vertices);
+
+  virtual void DrawMasked(signed int a2, signed int a3, struct Texture *pTexture, unsigned __int16 mask);
+  virtual void GetLeather(unsigned int a2, unsigned int a3, struct Texture *a4, __int16 height);
+
+  virtual void DrawTextPalette(int x, int y, unsigned char* font_pixels, int a5, unsigned int uFontHeight, unsigned __int16 *pPalette, int a8);
+  virtual void DrawText(signed int uOutX, signed int uOutY, unsigned __int8 *pFontPixels, unsigned int uCharWidth, unsigned int uCharHeight, unsigned __int16 *pFontPalette, unsigned __int16 uFaceColor, unsigned __int16 uShadowColor);
+
+  virtual void FillRectFast(unsigned int uX, unsigned int uY, unsigned int uWidth, unsigned int uHeight, unsigned int uColor16);
+  virtual void _4A6DF5(unsigned __int16 *pBitmap, unsigned int uBitmapPitch, struct Vec2_int_ *pBitmapXY, void *pTarget, unsigned int uTargetPitch, Vec4_int_ *a7);
+  virtual void DrawTranslucent(unsigned int a2, unsigned int a3, struct Texture *a4);
+
+  virtual void DrawBuildingsD3D();
+
+  virtual void DrawIndoorSky(unsigned int uNumVertices, unsigned int uFaceID);
+  virtual void DrawOutdoorSkyD3D();
+  virtual void DrawOutdoorSkyPolygon(unsigned int uNumVertices, struct Polygon *pSkyPolygon, IDirect3DTexture2 *pTexture);
+  virtual void DrawIndoorSkyPolygon(signed int uNumVertices, struct Polygon *pSkyPolygon, IDirect3DTexture2 *pTexture);
+
+  virtual void PrepareDecorationsRenderList_ODM();
+  virtual void DrawSpriteObjects_ODM();
+
+  virtual void RenderTerrainD3D();
+
+  virtual void ChangeBetweenWinFullscreenModes();
+  virtual bool AreRenderSurfacesOk();
+  virtual bool IsGammaSupported();
+
+  virtual void SaveScreenshot(const char *pFilename, unsigned int width, unsigned int height);
+  virtual void PackScreenshot(unsigned int width, unsigned int height, void *out_data, unsigned int data_size, unsigned int *screenshot_size);
+  virtual void SavePCXScreenshot();
+
+  virtual int _46À6ÀÑ_GetActorsInViewport(int pDepth);
+
+  virtual void BeginLightmaps();
+  virtual void EndLightmaps();  
+  virtual void BeginLightmaps2();
+  virtual void EndLightmaps2();
+  virtual bool DrawLightmap(struct Lightmap *pLightmap, struct Vec3_float_ *pColorMult, float z_bias);
+
+  virtual void BeginDecals();
+  virtual void EndDecals();
+  virtual void DrawDecal(struct Decal *pDecal, float z_bias);
+  
+  virtual void do_draw_debug_line_d3d(const RenderVertexD3D3 *pLineBegin, signed int sDiffuseBegin, const RenderVertexD3D3 *pLineEnd, signed int sDiffuseEnd, float z_stuff);
+  virtual void DrawLines(const RenderVertexD3D3 *vertices, unsigned int num_vertices);
+
+  virtual void DrawSpecialEffectsQuad(const RenderVertexD3D3 *vertices, IDirect3DTexture2 *texture);
+
+  virtual void am_Blt_Copy(RECT *pSrcRect, POINT *pTargetXY, int a3);
+  virtual void am_Blt_Chroma(RECT *pSrcRect, POINT *pTargetPoint, int a3, int blend_mode);
+
+  public:
+
+    virtual void WritePixel16(int x, int y, unsigned __int16 color)
+    {
+__debugbreak();
+    }
+
+    virtual unsigned __int16 ReadPixel16(int x, int y)
+    {
+__debugbreak(); return 0;
+    }
+
+    virtual void ToggleTint()          {}
+    virtual void ToggleColoredLights() {}
+
+    virtual unsigned int GetRenderWidth() {return window->GetWidth();}
+    virtual unsigned int GetRenderHeight() {return window->GetHeight();}
+
+    virtual void Sub01();
+
+
+  protected:
+    OSWindow *window;
+
+    IDXGISwapChain          *pSwapChain;
+    ID3D11Device            *d3dd;
+    ID3D11DeviceContext     *d3dc;
+    ID3D11RenderTargetView  *primary_srv;
+    ID3D11DepthStencilView  *depth_srv;
+};
--- a/RenderStruct.h	Tue Aug 05 17:00:35 2014 +0600
+++ b/RenderStruct.h	Tue Aug 12 21:34:18 2014 +0300
@@ -287,7 +287,7 @@
 bool PauseGameDrawing();
 
 extern struct IDirectDrawClipper *pDDrawClipper;
-extern struct Render *pRenderer; // idb
+extern struct IRender *pRenderer; // idb
 extern struct pUnkTerrain *Unks;
 
 
--- a/mm7_2.cpp	Tue Aug 05 17:00:35 2014 +0600
+++ b/mm7_2.cpp	Tue Aug 12 21:34:18 2014 +0300
@@ -9,7 +9,6 @@
 #include "UI\UIPartyCreation.h"
 #include "GUIButton.h"
 
-
 #include "mm7_data.h"
 #include "Sprites.h"
 
@@ -67,6 +66,7 @@
 #include "LuaVM.h"
 #include "MMT.h"
 #include "Registry.h"
+#include "RenderD3D11.h"
 
 //int __stdcall aWinProc(HWND hWnd, UINT Msg, WPARAM wParam, unsigned int lParam);
 int __stdcall InsertMM7CDDialogFunc(HWND hDlg, int a2, __int16 a3, int a4);
@@ -1418,7 +1418,11 @@
   pEventTimer->Initialize();
   window = OSWindow::Create(L"Might and Magic® Trilogy", game_width, game_height);//Create  game window
 
-  pRenderer = Render::Create();//Create DirectX
+  bool use_d3d11 = false;
+  if (use_d3d11)
+    pRenderer = RenderD3D11::Create();
+  else
+    pRenderer = Render::Create();//Create DirectX
   if (!pRenderer)
   {
     Log::Warning(L"Render creation failed");
@@ -1428,11 +1432,8 @@
   {
     //bool bWindowMode = ReadWindowsRegistryInt("startinwindow", false);
     //uint uDefaultDevice = ReadWindowsRegistryInt("D3D Device", 1);
-    bool bColoredLights = ReadWindowsRegistryInt("Colored Lights", false);
-    uint uLevelOfDetail = ReadWindowsRegistryInt("Detail Level", 1);
-    uint bTinting = ReadWindowsRegistryInt("Tinting", 1) != 0;
 
-    if (!pRenderer->Initialize(window, bColoredLights, uLevelOfDetail, bTinting))
+    if (!pRenderer->Initialize(window/*, bColoredLights, uLevelOfDetail, bTinting*/))
     {
       Log::Warning(L"Render failed to initialize");
       return false;