D3D7 sample.
authorJosé Fonseca <jose.r.fonseca@gmail.com>
Thu, 3 May 2012 13:21:55 +0000 (14:21 +0100)
committerJosé Fonseca <jose.r.fonseca@gmail.com>
Thu, 3 May 2012 13:21:55 +0000 (14:21 +0100)
app_driver.py
apps/CMakeLists.txt
apps/d3d7/CMakeLists.txt [new file with mode: 0644]
apps/d3d7/tri.cpp [new file with mode: 0644]
apps/d3d7/tri.ref.txt [new file with mode: 0644]

index 27eb4528394b6ef65ec751f75a6d0022fe48d3d0..67098d8125c932732d86950b32f64d4471ae7a04 100755 (executable)
@@ -175,6 +175,7 @@ class AppDriver(Driver):
         'egl_gl': 'egl',
         'egl_gles1': 'egl',
         'egl_gles2': 'egl',
+        'd3d7': 'd3d7',
         'd3d8': 'd3d8',
         'd3d9': 'd3d9',
     }
index f75c9f851f7ffb2b580324338ce3f95a85c52270..062e4c20f81339166df092424da62d9f75940578 100644 (file)
@@ -39,3 +39,7 @@ endif ()
 if (DirectX_D3D8_FOUND)
     add_subdirectory (d3d8)
 endif ()
+
+if (DirectX_D3D_FOUND)
+    add_subdirectory (d3d7)
+endif ()
diff --git a/apps/d3d7/CMakeLists.txt b/apps/d3d7/CMakeLists.txt
new file mode 100644 (file)
index 0000000..0b73135
--- /dev/null
@@ -0,0 +1,27 @@
+include_directories (
+    ${DirectX_D3D_INCLUDE_DIR}
+)
+
+link_libraries (
+    ${DirectX_DDRAW_LIBRARY}
+)
+
+set (api d3d7)
+
+set (targets
+    tri
+)
+
+foreach (target ${targets})
+    add_executable (${api}_${target} ${target}.cpp)
+    set_target_properties (${api}_${target} PROPERTIES OUTPUT_NAME ${target})
+
+    if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${target}.ref.txt)
+        add_app_test(
+            NAME ${api}_${target}
+            TARGET ${api}_${target}
+            REF ${target}.ref.txt
+        )
+    endif ()
+endforeach (target)
+
diff --git a/apps/d3d7/tri.cpp b/apps/d3d7/tri.cpp
new file mode 100644 (file)
index 0000000..7852e6e
--- /dev/null
@@ -0,0 +1,201 @@
+/**************************************************************************
+ *
+ * Copyright 2012 Jose Fonseca
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ **************************************************************************/
+
+
+#include <initguid.h>
+
+#include <windows.h>
+
+#include <d3d.h>
+
+
+static LPDIRECTDRAW7 g_pDD = NULL;
+static LPDIRECT3D7 g_pD3D = NULL;
+static LPDIRECT3DDEVICE7 g_pDevice = NULL;
+static LPDIRECTDRAWSURFACE7 g_pddsPrimary;
+static LPDIRECTDRAWSURFACE7 g_pddsBackBuffer;
+static RECT g_rcScreenRect;
+static RECT g_rcViewportRect;
+
+
+int main(int argc, char *argv[])
+{
+    HRESULT hr;
+
+    HINSTANCE hInstance = GetModuleHandle(NULL);
+
+    WNDCLASSEX wc = {
+        sizeof(WNDCLASSEX),
+        CS_CLASSDC,
+        DefWindowProc,
+        0,
+        0,
+        hInstance,
+        NULL,
+        NULL,
+        NULL,
+        NULL,
+        "SimpleDX7",
+        NULL
+    };
+    RegisterClassEx(&wc);
+
+    const int WindowWidth = 250;
+    const int WindowHeight = 250;
+    const int WindowDepth = 4;
+    BOOL Windowed = TRUE;
+
+    DWORD dwStyle = WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_OVERLAPPEDWINDOW;
+
+    RECT rect = {0, 0, WindowWidth, WindowHeight};
+    AdjustWindowRect(&rect, dwStyle, FALSE);
+
+    HWND hWnd = CreateWindow(wc.lpszClassName,
+                             "Simple example using DirectX7",
+                             dwStyle,
+                             CW_USEDEFAULT, CW_USEDEFAULT,
+                             rect.right - rect.left,
+                             rect.bottom - rect.top,
+                             NULL,
+                             NULL,
+                             hInstance,
+                             NULL);
+    if (!hWnd) {
+        return 1;
+    }
+
+    ShowWindow(hWnd, SW_SHOW);
+
+    hr = DirectDrawCreateEx(NULL, (void **)&g_pDD, IID_IDirectDraw7, NULL);
+    if (FAILED(hr)) {
+        return 1;
+    }
+
+    hr = g_pDD->SetCooperativeLevel(hWnd, DDSCL_NORMAL);
+    if (FAILED(hr)) {
+        return 1;
+    }
+
+    /*
+     * Create primary
+     */
+
+    DDSURFACEDESC2 ddsd;
+    ZeroMemory(&ddsd, sizeof ddsd);
+    ddsd.dwSize         = sizeof ddsd;
+    ddsd.dwFlags        = DDSD_CAPS;
+    ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
+
+    hr = g_pDD->CreateSurface(&ddsd, &g_pddsPrimary, NULL);
+    if (FAILED(hr)) {
+        return 1;
+    }
+
+    /*
+     * Create backbuffer
+     */
+
+    ddsd.dwFlags        = DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS;
+    ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
+
+    GetClientRect(hWnd, &g_rcScreenRect);
+    GetClientRect(hWnd, &g_rcViewportRect);
+    ClientToScreen(hWnd, (POINT*)&g_rcScreenRect.left);
+    ClientToScreen(hWnd, (POINT*)&g_rcScreenRect.right);
+    ddsd.dwWidth  = g_rcScreenRect.right - g_rcScreenRect.left;
+    ddsd.dwHeight = g_rcScreenRect.bottom - g_rcScreenRect.top;
+
+    hr = g_pDD->CreateSurface(&ddsd, &g_pddsBackBuffer, NULL);
+    if (FAILED(hr)) {
+        return 1;
+    }
+
+    LPDIRECTDRAWCLIPPER pcClipper;
+    hr = g_pDD->CreateClipper(0, &pcClipper, NULL);
+    if (FAILED(hr)) {
+        return 1;
+    }
+
+    pcClipper->SetHWnd(0, hWnd);
+    g_pddsPrimary->SetClipper(pcClipper);
+    pcClipper->Release();
+
+    /*
+     * Initialize D3D
+     */
+
+    hr = g_pDD->QueryInterface(IID_IDirect3D7, (void **)&g_pD3D);
+    if (FAILED(hr)) {
+        return 1;
+    }
+
+    hr = g_pD3D->CreateDevice(IID_IDirect3DHALDevice, g_pddsBackBuffer, &g_pDevice);
+    if (FAILED(hr)) {
+        g_pD3D->Release();
+        g_pD3D = NULL;
+        return 1;
+    }
+
+    struct Vertex {
+        float x, y, z;
+        DWORD color;
+    };
+
+
+    D3DCOLOR clearColor = D3DRGBA(0.3f, 0.1f, 0.3f, 1.0f);
+    g_pDevice->Clear(0, NULL, D3DCLEAR_TARGET, clearColor, 1.0f, 0);
+    g_pDevice->BeginScene();
+
+    g_pDevice->SetRenderState(D3DRENDERSTATE_LIGHTING, FALSE);
+    g_pDevice->SetRenderState(D3DRENDERSTATE_CULLMODE, D3DCULL_NONE);
+
+    static Vertex vertices[] = {
+        { -0.9f, -0.9f, 0.5f, D3DRGBA(0.8f, 0.0f, 0.0f, 0.1f) },
+        {  0.9f, -0.9f, 0.5f, D3DRGBA(0.0f, 0.9f, 0.0f, 0.1f) },
+        {  0.0f,  0.9f, 0.5f, D3DRGBA(0.0f, 0.0f, 0.7f, 0.1f) },
+    };
+
+    g_pDevice->DrawPrimitive(D3DPT_TRIANGLELIST, D3DFVF_XYZ | D3DFVF_DIFFUSE, vertices, 3, 0);
+
+    g_pDevice->EndScene();
+
+    /*
+     * Present
+     */
+    hr = g_pddsPrimary->Blt(&g_rcScreenRect, g_pddsBackBuffer, &g_rcViewportRect, DDBLT_WAIT, NULL);
+    if (FAILED(hr)) {
+        return 1;
+    }
+
+    g_pDevice->Release();
+    g_pDevice = NULL;
+    g_pD3D->Release();
+    g_pD3D = NULL;
+
+    DestroyWindow(hWnd);
+
+    return 0;
+}
+
diff --git a/apps/d3d7/tri.ref.txt b/apps/d3d7/tri.ref.txt
new file mode 100644 (file)
index 0000000..e69de29