Skip to content

Instantly share code, notes, and snippets.

@wrongbranch
Created January 17, 2021 08:35
Show Gist options
  • Save wrongbranch/1e99afa545794f512dd66ee6f3b7470d to your computer and use it in GitHub Desktop.
Save wrongbranch/1e99afa545794f512dd66ee6f3b7470d to your computer and use it in GitHub Desktop.
test_DXSDK_Jun10.cpp
/*
test_DXSDK_Jun10.cpp
"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\bin\Hostx64\x64\cl.exe" -source-charset:utf-8 -execution-charset:utf-8 -EHsc -Fetest_DXSDK_Jun10.exe test_DXSDK_Jun10.cpp -IC:\private\DX9\DXSDK\Include -link /LIBPATH:C:\private\DX9\DXSDK\Lib\x64 /LIBPATH:"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\lib\x64" /LIBPATH:"C:\Program Files (x86)\Windows Kits\10\Lib\10.0.17763.0\ucrt\x64" /LIBPATH:"C:\Program Files (x86)\Windows Kits\10\Lib\10.0.17763.0\um\x64" winmm.lib d3d9.lib d3dx9.lib
C:\private\D3D11 ?
C:\private\DX9\DXSDK
Redist
Jun2010_d3dx9_??_x??.cab
dsetup32.dll (x64 ?)
dsetup.dll (x86 ?)
Developer Runtime
x64 (dll for debug) (release dll are in C:\Windows\System32)
d3d9d.dll
d3dx9d_33.dll
d3dx9d_43.dll
x86 (dll for debug) (release dll are in C:\Windows\SysWOW64)
d3d9d.dll
d3dx9d_33.dll
d3dx9d_43.dll
Lib
x64
x86
Include
*/
#define _USE_MATH_DEFINES
#include <cmath>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <sstream>
#include <vector>
#include <windows.h>
#include <d3d9.h>
// to include d3dx9.h all, funcs in d3dx9math.inl must be encapsulated into dll
#include <d3dx9.h>
using namespace std;
int CleanupDirect3D(
LPDIRECT3D9 pD3D, LPDIRECT3DDEVICE9 pDev, D3DPRESENT_PARAMETERS *pD3Dpp)
{
pDev->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
pDev->SetRenderState(D3DRS_LIGHTING, FALSE);
pDev->SetRenderState(D3DRS_ZENABLE, FALSE);
if(pD3Dpp){ free(pD3Dpp); pD3Dpp = NULL; }
if(pDev){ pDev->Release(); pDev = NULL; }
if(pD3D){ pD3D->Release(); pD3D = NULL; }
return 0;
}
int main(int ac, char **av)
{
LPDIRECT3D9 pD3D = NULL;
LPDIRECT3DDEVICE9 pDev = NULL;
D3DPRESENT_PARAMETERS *pD3Dpp = NULL;
timeBeginPeriod(1); // 1ms
if(!(pD3D = Direct3DCreate9(D3D_SDK_VERSION))){
fprintf(stderr, "Can't create Direct3D.\n");
return 1;
}
D3DPRESENT_PARAMETERS d3dpp;
ZeroMemory(&d3dpp, sizeof(d3dpp));
d3dpp.Windowed = TRUE;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
// d3dpp.FullScreen_refreshRateInHz = 75;
d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_DEFAULT; // rs.InVBlank
d3dpp.BackBufferCount = 1;
d3dpp.BackBufferFormat = D3DFMT_A8R8G8B8; // D3DFMT_X8R8G8B8 D3DFMT_UNKNOWN
d3dpp.BackBufferWidth = 640;
d3dpp.BackBufferHeight = 480;
d3dpp.EnableAutoDepthStencil = TRUE;
d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
HWND hWnd = NULL;
HRESULT hr = pD3D->CreateDevice(
D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,
D3DCREATE_HARDWARE_VERTEXPROCESSING, &d3dpp, &pDev);
if(FAILED(hr)){
hr = pD3D->CreateDevice(
D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,
D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &pDev);
if(FAILED(hr)){
fprintf(stderr, "Can't create Device.\n");
return 2;
}
}
pD3Dpp = (D3DPRESENT_PARAMETERS *)malloc(sizeof(D3DPRESENT_PARAMETERS));
if(!pD3Dpp){
fprintf(stderr, "Can't create PresentParameters.\n");
CleanupDirect3D(pD3D, pDev, pD3Dpp);
return 3;
}
memcpy(pD3Dpp, &d3dpp, sizeof(D3DPRESENT_PARAMETERS));
// D3DXCreateSprite(pDev, (LPD3DXSPRITE *)...);
// D3DXCreateTextureFromFileA(pDev, "E:\\virtual\\cv3_img.png",
// (LPDIRECT3DTEXTURE9 *)...);
DWORD zenable = TRUE, lighting = FALSE, cull = D3DCULL_CCW;
pDev->SetRenderState(D3DRS_ZENABLE, zenable);
pDev->SetRenderState(D3DRS_LIGHTING, lighting);
pDev->SetRenderState(D3DRS_CULLMODE, cull);
pD3D->Release();
timeEndPeriod(1);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment