Create a gist now

Instantly share code, notes, and snippets.

@mirichi /polygon.rb Secret
Created Nov 20, 2016

What would you like to do?
三角形描画記念
require "fiddle/import"
require 'fiddle/types'
width = 320
height = 240
# WindowsAPIのインターフェイス
module WinAPI
extend Fiddle::Importer
dlload "gdi32", "ole32", "user32", "kernel32"
include Fiddle::Win32Types
# 型の定義
typealias "HMENU", "unsigned int"
typealias "HICON", "unsigned int"
typealias "HCURSOR", "unsigned int"
typealias "HBRUSH", "unsigned int"
typealias "HMODULE", "unsigned int"
typealias "WNDPROC", "void *"
typealias "LPVOID", "void *"
typealias "LPMSG", "void *"
typealias "WINBOOL", "int"
typealias "LONG", "long"
typealias "WPARAM", "void *"
typealias "LPARAM", "void *"
typealias "LRESULT", "void *"
typealias "LPRECT", "void *"
# WindowsAPIの定義
extern "HWND CreateWindowExA(DWORD, LPCSTR, LPCSTR, DWORD, DWORD, DWORD, int, int, HWND, HMENU, HINSTANCE, LPVOID)"
extern "ATOM RegisterClassExA(void *)"
extern "HMODULE GetModuleHandleA(LPCSTR)"
extern "UINT DefWindowProcA(HWND, UINT, UINT, LONG)"
extern "WINBOOL GetMessageA(LPMSG, HWND, UINT, UINT)"
extern "WINBOOL TranslateMessage(LPMSG)"
extern "LRESULT DispatchMessageA(LPMSG)"
extern "HCURSOR SetCursor(HCURSOR)"
extern "HCURSOR LoadCursorA(HINSTANCE, LPCSTR)"
extern "WINBOOL AdjustWindowRect(LPRECT, DWORD, WINBOOL)"
extern "void PostQuitMessage(int)"
extern "WINBOOL DestroyWindow(HWND)"
# 構造体の定義
WNDCLASSEX = struct([
"UINT cbSize",
"UINT style",
"WNDPROC lpfnWndProc",
"int cbClsExtra",
"int cbWndExtra",
"HINSTANCE hInstance",
"HICON hIcon",
"HCURSOR hCursor",
"HBRUSH hbrBackground",
"LPCSTR lpszMenuName",
"LPCSTR lpszClassName",
"HICON hIconSm"
])
MSG = struct([
"HWND hwnd",
"UINT message",
"WPARAM wParam",
"LPARAM lParam",
"DWORD time",
"LONG x",
"LONG y"
])
RECT = struct([
"LONG left",
"LONG top",
"LONG right",
"LONG bottom"
])
GUID = struct([
"unsigned long Data1",
"unsigned short Data2",
"unsigned short Data3",
"unsigned char Data4[8]"
])
# 使いそうな定数の定義
CS_VREDRAW = 0x0001
CS_HREDRAW = 0x0002
CS_DBLCLKS = 0x0008
CS_OWNDC = 0x0020
CS_CLASSDC = 0x0040
CS_PARENTDC = 0x0080
CS_NOCLOSE = 0x0200
CS_SAVEBITS = 0x0800
CS_BYTEALIGNCLIENT = 0x1000
CS_BYTEALIGNWINDOW = 0x2000
CS_GLOBALCLASS = 0x4000
CS_IME = 0x00010000
CS_DROPSHADOW = 0x00020000
COLOR_SCROLLBAR = 0
COLOR_BACKGROUND = 1
COLOR_ACTIVECAPTION = 2
COLOR_INACTIVECAPTION = 3
COLOR_MENU = 4
COLOR_WINDOW = 5
COLOR_WINDOWFRAME = 6
COLOR_MENUTEXT = 7
COLOR_WINDOWTEXT = 8
COLOR_CAPTIONTEXT = 9
COLOR_ACTIVEBORDER = 10
COLOR_INACTIVEBORDER = 11
COLOR_APPWORKSPACE = 12
COLOR_HIGHLIGHT = 13
COLOR_HIGHLIGHTTEXT = 14
COLOR_BTNFACE = 15
COLOR_BTNSHADOW = 16
COLOR_GRAYTEXT = 17
COLOR_BTNTEXT = 18
COLOR_INACTIVECAPTIONTEXT = 19
COLOR_BTNHIGHLIGHT = 20
COLOR_3DDKSHADOW = 21
COLOR_3DLIGHT = 22
COLOR_INFOTEXT = 23
COLOR_INFOBK = 24
COLOR_HOTLIGHT = 26
COLOR_GRADIENTACTIVECAPTION = 27
COLOR_GRADIENTINACTIVECAPTION = 28
COLOR_MENUHILIGHT = 29
COLOR_MENUBAR = 30
COLOR_DESKTOP = COLOR_BACKGROUND
COLOR_3DFACE = COLOR_BTNFACE
COLOR_3DSHADOW = COLOR_BTNSHADOW
COLOR_3DHIGHLIGHT = COLOR_BTNHIGHLIGHT
COLOR_3DHILIGHT = COLOR_BTNHIGHLIGHT
COLOR_BTNHILIGHT = COLOR_BTNHIGHLIGHT
WS_OVERLAPPED = 0x00000000
WS_POPUP = 0x80000000
WS_CHILD = 0x40000000
WS_MINIMIZE = 0x20000000
WS_VISIBLE = 0x10000000
WS_DISABLED = 0x08000000
WS_CLIPSIBLINGS = 0x04000000
WS_CLIPCHILDREN = 0x02000000
WS_MAXIMIZE = 0x01000000
WS_CAPTION = 0x00C00000
WS_BORDER = 0x00800000
WS_DLGFRAME = 0x00400000
WS_VSCROLL = 0x00200000
WS_HSCROLL = 0x00100000
WS_SYSMENU = 0x00080000
WS_THICKFRAME = 0x00040000
WS_GROUP = 0x00020000
WS_TABSTOP = 0x00010000
WS_MINIMIZEBOX = 0x00020000
WS_MAXIMIZEBOX = 0x00010000
WS_TILED = WS_OVERLAPPED
WS_ICONIC = WS_MINIMIZE
WS_SIZEBOX = WS_THICKFRAME
WS_OVERLAPPEDWINDOW = (WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX)
WS_TILEDWINDOW = WS_OVERLAPPEDWINDOW
WS_POPUPWINDOW = (WS_POPUP | WS_BORDER | WS_SYSMENU)
WS_CHILDWINDOW = (WS_CHILD)
CW_USEDEFAULT = 0x80000000
WM_NULL = 0x0000
WM_CREATE = 0x0001
WM_DESTROY = 0x0002
WM_MOVE = 0x0003
WM_SIZE = 0x0005
WM_ACTIVATE = 0x0006
WA_INACTIVE = 0
WA_ACTIVE = 1
WA_CLICKACTIVE = 2
WM_SETFOCUS = 0x0007
WM_KILLFOCUS = 0x0008
WM_ENABLE = 0x000A
WM_SETREDRAW = 0x000B
WM_SETTEXT = 0x000C
WM_GETTEXT = 0x000D
WM_GETTEXTLENGTH = 0x000E
WM_PAINT = 0x000F
WM_CLOSE = 0x0010
WM_QUIT = 0x0012
WM_ERASEBKGND = 0x0014
WM_SYSCOLORCHANGE = 0x0015
WM_SHOWWINDOW = 0x0018
WM_WININICHANGE = 0x001A
WM_SETTINGCHANGE = WM_WININICHANGE
WM_DEVMODECHANGE = 0x001B
WM_ACTIVATEAPP = 0x001C
WM_FONTCHANGE = 0x001D
WM_TIMECHANGE = 0x001E
WM_CANCELMODE = 0x001F
WM_SETCURSOR = 0x0020
WM_MOUSEACTIVATE = 0x0021
WM_CHILDACTIVATE = 0x0022
WM_QUEUESYNC = 0x0023
IDC_ARROW = 32512
IDC_IBEAM = 32513
IDC_WAIT = 32514
IDC_CROSS = 32515
IDC_UPARROW = 32516
IDC_SIZE = 32640
IDC_ICON = 32641
IDC_SIZENWSE = 32642
IDC_SIZENESW = 32643
IDC_SIZEWE = 32644
IDC_SIZENS = 32645
IDC_SIZEALL = 32646
IDC_NO = 32648
IDC_HAND = 32649
IDC_APPSTARTING = 32650
IDC_HELP = 32651
end
# ウィンドウプロシージャ
class WndProc < Fiddle::Closure
def call(hWnd, msg, wParam, lParam)
case msg
when WinAPI::WM_CLOSE
WinAPI::DestroyWindow(hWnd)
when WinAPI::WM_DESTROY
WinAPI::PostQuitMessage(0)
else
return WinAPI::DefWindowProcA(hWnd, msg, wParam, lParam)
end
return 0
end
end
# 実行中のプログラムのインスタンスハンドル取得
hInstance = WinAPI::GetModuleHandleA(nil)
# ウィンドウプロシージャ
wndproc = WndProc.new(Fiddle::TYPE_LONG, [-Fiddle::TYPE_INT, -Fiddle::TYPE_INT, -Fiddle::TYPE_INT, Fiddle::TYPE_INT])
# WNDCLASSEX構造体作成
wcex = WinAPI::WNDCLASSEX.malloc
wcex.cbSize = WinAPI::WNDCLASSEX.size
wcex.style = WinAPI::CS_HREDRAW | WinAPI::CS_VREDRAW
wcex.lpfnWndProc = wndproc
wcex.cbClsExtra = 0
wcex.cbWndExtra = 0
wcex.hInstance = hInstance
wcex.hIcon = 0
wcex.hIconSm = 0
wcex.hCursor = 0
wcex.hbrBackground = WinAPI::COLOR_WINDOW
wcex.lpszMenuName = nil
wcex.lpszClassName = "test"
# (Windowsの)クラス定義
WinAPI::RegisterClassExA(wcex)
# ウィンドウサイズ計算
rect = WinAPI::RECT.malloc
rect.top = 0
rect.left = 0
rect.right = width
rect.bottom = height
WinAPI::AdjustWindowRect(rect, WinAPI::WS_OVERLAPPED | WinAPI::WS_CAPTION | WinAPI::WS_SYSMENU | WinAPI::WS_MINIMIZEBOX, 0);
# ウィンドウ作成
hWnd = WinAPI::CreateWindowExA(0, "test", "Test Window",
WinAPI::WS_OVERLAPPED | WinAPI::WS_CAPTION | WinAPI::WS_SYSMENU | WinAPI::WS_MINIMIZEBOX | WinAPI::WS_VISIBLE,
WinAPI::CW_USEDEFAULT, WinAPI::CW_USEDEFAULT,
rect.right - rect.left, rect.bottom - rect.top,
0, 0, hInstance, 0 );
# カーソル設定
WinAPI::SetCursor(WinAPI::LoadCursorA(0, WinAPI::IDC_ARROW))
# Direct3D9のインターフェイス
module D3D9
extend Fiddle::Importer
dlload "d3d9"
include Fiddle::Win32Types
# 型の定義
typealias "HMENU", "unsigned int"
typealias "HICON", "unsigned int"
typealias "HCURSOR", "unsigned int"
typealias "HBRUSH", "unsigned int"
typealias "HMODULE", "unsigned int"
typealias "WNDPROC", "void *"
typealias "LPVOID", "void *"
typealias "LPMSG", "void *"
typealias "WINBOOL", "int"
typealias "LONG", "long"
typealias "WPARAM", "void *"
typealias "LPARAM", "void *"
typealias "LRESULT", "void *"
typealias "HRESULT", "long"
typealias "LPRECT", "void *"
typealias "D3DCOLOR", "DWORD"
# 関数
extern "void* Direct3DCreate9(UINT)"
# 構造体の定義
D3DPRESENT_PARAMETERS = struct([
"UINT BackBufferWidth",
"UINT BackBufferHeight",
"int BackBufferFormat",
"UINT BackBufferCount",
"int MultiSampleType",
"DWORD MultiSampleQuality",
"int SwapEffect",
"HWND hDeviceWindow",
"WINBOOL Windowed",
"WINBOOL EnableAutoDepthStencil",
"int AutoDepthStencilFormat",
"DWORD Flags",
"UINT FullScreen_RefreshRateInHz",
"UINT PresentationInterval"
])
D3DVIEWPORT9 = struct([
"DWORD X",
"DWORD Y",
"DWORD Width",
"DWORD Height",
"float MinZ",
"float MaxZ"
])
# 定数
D3D_SDK_VERSION = 32
D3DFMT_UNKNOWN = 0
D3DFMT_D24S8 = 75
D3DMULTISAMPLE_NONE = 0
D3DSWAPEFFECT_DISCARD = 1
D3DPRESENT_INTERVAL_IMMEDIATE = 0x80000000
D3DADAPTER_DEFAULT = 0
D3DDEVTYPE_HAL = 1
D3DCREATE_MIXED_VERTEXPROCESSING = 0x00000080
D3DCLEAR_TARGET = 0x00000001
D3DCLEAR_ZBUFFER = 0x00000002
D3DCLEAR_STENCIL = 0x00000004
D3DFVF_RESERVED0 = 0x0001
D3DFVF_POSITION_MASK = 0x400E
D3DFVF_XYZ = 0x0002
D3DFVF_XYZRHW = 0x0004
D3DFVF_XYZB1 = 0x0006
D3DFVF_XYZB2 = 0x0008
D3DFVF_XYZB3 = 0x000a
D3DFVF_XYZB4 = 0x000c
D3DFVF_XYZB5 = 0x000e
D3DFVF_XYZW = 0x4002
D3DFVF_NORMAL = 0x0010
D3DFVF_PSIZE = 0x0020
D3DFVF_DIFFUSE = 0x0040
D3DFVF_SPECULAR = 0x0080
D3DFVF_TEXCOUNT_MASK = 0x0f00
D3DFVF_TEXCOUNT_SHIFT = 8
D3DFVF_TEX0 = 0x0000
D3DFVF_TEX1 = 0x0100
D3DFVF_TEX2 = 0x0200
D3DFVF_TEX3 = 0x0300
D3DFVF_TEX4 = 0x0400
D3DFVF_TEX5 = 0x0500
D3DFVF_TEX6 = 0x0600
D3DFVF_TEX7 = 0x0700
D3DFVF_TEX8 = 0x0800
D3DFVF_LASTBETA_UBYTE4 = 0x1000
D3DFVF_LASTBETA_D3DCOLOR = 0x8000
D3DFVF_RESERVED2 = 0x6000
D3DPT_POINTLIST = 1
D3DPT_LINELIST = 2
D3DPT_LINESTRIP = 3
D3DPT_TRIANGLELIST = 4
D3DPT_TRIANGLESTRIP = 5
D3DPT_TRIANGLEFAN = 6
# マクロ
def self.D3DCOLOR_ARGB(a,b,c,d)
((a & 0xff) << 24) + ((b & 0xff) << 16) + ((c & 0xff) << 8) + (d & 0xff)
end
def self.D3DCOLOR_XRGB(r,g,b)
D3DCOLOR_ARGB(0xff,r,g,b)
end
end
# COMオブジェクトをラップする
class COM
attr_accessor :ptr
def ref
@ptr = Fiddle::Pointer.malloc(Fiddle::SIZEOF_VOIDP)
@ptr.ref
end
# i番目の関数のアドレスを差すFiddle::Pointerを返す
def get_func_ptr(i)
(@ptr.ptr + i * Fiddle::SIZEOF_VOIDP).ptr
end
# とりあえず動的に適当に呼べるようにしてみた。いずれ何とかしたい
def method_missing(m, *args)
functions = self.class.class_variable_get(:@@functions)
func = Fiddle::Function.new(self.get_func_ptr(functions[m][0]),
functions[m][2],
functions[m][1],
Fiddle::Function::STDCALL)
func.call(@ptr, *args)
end
end
# IDirect3D9インターフェイス
class IDirect3D9 < COM
@@functions = {
:QueryInterface => [0, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP]],
:AddRef => [1, -Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP]],
:Release => [2, -Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP]],
:RegisterSoftwareDevice => [3, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP]],
:GetAdapterCount => [4, -Fiddle::TYPE_INT, [Fiddle::TYPE_VOIDP]],
:GetAdapterIdentifier => [5, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, -Fiddle::TYPE_INT, -Fiddle::TYPE_INT, Fiddle::TYPE_VOIDP]],
:GetAdapterModeCount => [6, -Fiddle::TYPE_INT, [Fiddle::TYPE_VOIDP, -Fiddle::TYPE_INT, Fiddle::TYPE_INT]],
:EnumAdapterModes => [7, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, -Fiddle::TYPE_INT, Fiddle::TYPE_INT, -Fiddle::TYPE_INT, Fiddle::TYPE_VOIDP]],
:GetAdapterDisplayMode => [8, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, -Fiddle::TYPE_INT, Fiddle::TYPE_VOIDP]],
:CheckDeviceType => [9, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, -Fiddle::TYPE_INT, Fiddle::TYPE_INT, Fiddle::TYPE_INT, Fiddle::TYPE_INT, Fiddle::TYPE_INT]],
:CheckDeviceFormat => [10, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, -Fiddle::TYPE_INT, Fiddle::TYPE_INT, Fiddle::TYPE_INT, -Fiddle::TYPE_INT, Fiddle::TYPE_INT, Fiddle::TYPE_INT]],
:CheckDeviceMultiSampleType => [11, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, -Fiddle::TYPE_INT, Fiddle::TYPE_INT, Fiddle::TYPE_INT, Fiddle::TYPE_INT, Fiddle::TYPE_INT, Fiddle::TYPE_VOIDP]],
:CheckDepthStencilMatch => [12, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, -Fiddle::TYPE_INT, Fiddle::TYPE_INT, Fiddle::TYPE_INT, Fiddle::TYPE_INT, Fiddle::TYPE_INT]],
:CheckDeviceFormatConversion => [13, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, -Fiddle::TYPE_INT, Fiddle::TYPE_INT, Fiddle::TYPE_INT, Fiddle::TYPE_INT]],
:GetDeviceCaps => [14, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, -Fiddle::TYPE_INT, Fiddle::TYPE_INT, Fiddle::TYPE_VOIDP]],
:GetAdapterMonitor => [15, Fiddle::TYPE_VOIDP, [Fiddle::TYPE_VOIDP, -Fiddle::TYPE_INT]],
:CreateDevice => [16, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, -Fiddle::TYPE_INT, Fiddle::TYPE_INT, -Fiddle::TYPE_INT, -Fiddle::TYPE_INT, Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP]],
}
end
# IDirect3DDevice9インターフェイス
class IDirect3DDevice9 < COM
@@functions = {
:QueryInterface => [0, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP]],
:AddRef => [1, -Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP]],
:Release => [2, -Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP]],
:TestCooperativeLevel => [3, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP]],
:GetAvailableTextureMem => [4, -Fiddle::TYPE_INT, [Fiddle::TYPE_VOIDP]],
:EvictManagedResources => [5, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP]],
:GetDirect3D => [6, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP]],
:GetDeviceCaps => [7, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP]],
:GetDisplayMode => [8, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, -Fiddle::TYPE_INT, Fiddle::TYPE_VOIDP]],
:GetCreationParameters => [9, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP]],
:SetCursorProperties => [10, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, -Fiddle::TYPE_INT, -Fiddle::TYPE_INT, Fiddle::TYPE_VOIDP]],
:SetCursorPosition => [11, Fiddle::TYPE_VOID, [Fiddle::TYPE_VOIDP, Fiddle::TYPE_INT, Fiddle::TYPE_INT, -Fiddle::TYPE_INT]],
:ShowCursor => [12, Fiddle::TYPE_INT, [Fiddle::TYPE_VOIDP, Fiddle::TYPE_INT]],
:CreateAdditionalSwapChain => [13, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP]],
:GetSwapChain => [14, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, -Fiddle::TYPE_INT, Fiddle::TYPE_VOIDP]],
:GetNumberOfSwapChains => [15, -Fiddle::TYPE_INT, [Fiddle::TYPE_VOIDP]],
:Reset => [16, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP]],
:Present => [17, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP, -Fiddle::TYPE_INT, Fiddle::TYPE_VOIDP]],
:GetBackBuffer => [18, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, -Fiddle::TYPE_INT, -Fiddle::TYPE_INT, Fiddle::TYPE_INT, Fiddle::TYPE_VOIDP]],
:GetRasterStatus => [19, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, -Fiddle::TYPE_INT, Fiddle::TYPE_VOIDP]],
:SetDialogBoxMode => [20, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, Fiddle::TYPE_INT]],
:SetGammaRamp => [21, Fiddle::TYPE_VOID, [Fiddle::TYPE_VOIDP, -Fiddle::TYPE_INT, -Fiddle::TYPE_INT, Fiddle::TYPE_VOIDP]],
:GetGammaRamp => [22, Fiddle::TYPE_VOID, [Fiddle::TYPE_VOIDP, -Fiddle::TYPE_INT, Fiddle::TYPE_VOIDP]],
:CreateTexture => [23, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, -Fiddle::TYPE_INT, -Fiddle::TYPE_INT, -Fiddle::TYPE_INT, -Fiddle::TYPE_INT, Fiddle::TYPE_INT, Fiddle::TYPE_INT, Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP]],
:CreateVolumeTexture => [24, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, -Fiddle::TYPE_INT, -Fiddle::TYPE_INT, -Fiddle::TYPE_INT, -Fiddle::TYPE_INT, -Fiddle::TYPE_INT, Fiddle::TYPE_INT, Fiddle::TYPE_INT, Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP]],
:CreateCubeTexture => [25, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, -Fiddle::TYPE_INT, -Fiddle::TYPE_INT, -Fiddle::TYPE_INT, Fiddle::TYPE_INT, Fiddle::TYPE_INT, Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP]],
:CreateVertexBuffer => [26, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, -Fiddle::TYPE_INT, -Fiddle::TYPE_INT, -Fiddle::TYPE_INT, Fiddle::TYPE_INT, Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP]],
:CreateIndexBuffer => [27, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, -Fiddle::TYPE_INT, -Fiddle::TYPE_INT, Fiddle::TYPE_INT, Fiddle::TYPE_INT, Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP]],
:CreateRenderTarget => [28, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, -Fiddle::TYPE_INT, -Fiddle::TYPE_INT, Fiddle::TYPE_INT, Fiddle::TYPE_INT, -Fiddle::TYPE_INT, Fiddle::TYPE_INT, Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP]],
:CreateDepthStencilSurface => [29, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, -Fiddle::TYPE_INT, -Fiddle::TYPE_INT, Fiddle::TYPE_INT, Fiddle::TYPE_INT, -Fiddle::TYPE_INT, Fiddle::TYPE_INT, Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP]],
:UpdateSurface => [30, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP]],
:UpdateTexture => [31, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP]],
:GetRenderTargetData => [32, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP]],
:GetFrontBufferData => [33, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, -Fiddle::TYPE_INT, Fiddle::TYPE_VOIDP]],
:StretchRect => [34, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP, Fiddle::TYPE_INT]],
:ColorFill => [35, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP, -Fiddle::TYPE_INT]],
:CreateOffscreenPlainSurface => [36, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, -Fiddle::TYPE_INT, -Fiddle::TYPE_INT, Fiddle::TYPE_INT, Fiddle::TYPE_INT, Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP]],
:SetRenderTarget => [37, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, -Fiddle::TYPE_INT, Fiddle::TYPE_VOIDP]],
:GetRenderTarget => [38, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, -Fiddle::TYPE_INT, Fiddle::TYPE_VOIDP]],
:SetDepthStencilSurface => [39, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP]],
:GetDepthStencilSurface => [40, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP]],
:BeginScene => [41, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP]],
:EndScene => [42, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP]],
:Clear => [43, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, -Fiddle::TYPE_INT, Fiddle::TYPE_VOIDP, -Fiddle::TYPE_INT, -Fiddle::TYPE_INT, Fiddle::TYPE_FLOAT, -Fiddle::TYPE_INT]],
:SetTransform => [44, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, Fiddle::TYPE_INT, Fiddle::TYPE_VOIDP]],
:GetTransform => [45, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, Fiddle::TYPE_INT, Fiddle::TYPE_VOIDP]],
:MultiplyTransform => [46, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, Fiddle::TYPE_INT, Fiddle::TYPE_VOIDP]],
:SetViewport => [47, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP]],
:GetViewport => [48, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP]],
:SetMaterial => [49, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP]],
:GetMaterial => [50, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP]],
:SetLight => [51, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, -Fiddle::TYPE_INT, Fiddle::TYPE_VOIDP]],
:GetLight => [52, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, -Fiddle::TYPE_INT, Fiddle::TYPE_VOIDP]],
:LightEnable => [53, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, -Fiddle::TYPE_INT, Fiddle::TYPE_INT]],
:GetLightEnable => [54, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, -Fiddle::TYPE_INT, Fiddle::TYPE_VOIDP]],
:SetClipPlane => [55, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, -Fiddle::TYPE_INT, Fiddle::TYPE_VOIDP]],
:GetClipPlane => [56, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, -Fiddle::TYPE_INT, Fiddle::TYPE_VOIDP]],
:SetRenderState => [57, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, Fiddle::TYPE_INT, -Fiddle::TYPE_INT]],
:GetRenderState => [58, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, Fiddle::TYPE_INT, Fiddle::TYPE_VOIDP]],
:CreateStateBlock => [59, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, Fiddle::TYPE_INT, Fiddle::TYPE_VOIDP]],
:BeginStateBlock => [60, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP]],
:EndStateBlock => [61, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP]],
:SetClipStatus => [62, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP]],
:GetClipStatus => [63, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP]],
:GetTexture => [64, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, -Fiddle::TYPE_INT, Fiddle::TYPE_VOIDP]],
:SetTexture => [65, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, -Fiddle::TYPE_INT, Fiddle::TYPE_VOIDP]],
:GetTextureStageState => [66, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, -Fiddle::TYPE_INT, Fiddle::TYPE_INT, Fiddle::TYPE_VOIDP]],
:SetTextureStageState => [67, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, -Fiddle::TYPE_INT, Fiddle::TYPE_INT, -Fiddle::TYPE_INT]],
:GetSamplerState => [68, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, -Fiddle::TYPE_INT, Fiddle::TYPE_INT, Fiddle::TYPE_VOIDP]],
:SetSamplerState => [69, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, -Fiddle::TYPE_INT, Fiddle::TYPE_INT, -Fiddle::TYPE_INT]],
:ValidateDevice => [70, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP]],
:SetPaletteEntries => [71, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, -Fiddle::TYPE_INT, Fiddle::TYPE_VOIDP]],
:GetPaletteEntries => [72, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, -Fiddle::TYPE_INT, Fiddle::TYPE_VOIDP]],
:SetCurrentTexturePalette => [73, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, -Fiddle::TYPE_INT]],
:GetCurrentTexturePalette => [74, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP]],
:SetScissorRect => [75, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP]],
:GetScissorRect => [76, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP]],
:SetSoftwareVertexProcessing => [77, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, Fiddle::TYPE_INT]],
:GetSoftwareVertexProcessing => [78, Fiddle::TYPE_INT, [Fiddle::TYPE_VOIDP]],
:SetNPatchMode => [79, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, Fiddle::TYPE_FLOAT]],
:GetNPatchMode => [80, Fiddle::TYPE_FLOAT, [Fiddle::TYPE_VOIDP]],
:DrawPrimitive => [81, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, Fiddle::TYPE_INT, -Fiddle::TYPE_INT, -Fiddle::TYPE_INT]],
:DrawIndexedPrimitive => [82, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, Fiddle::TYPE_INT, Fiddle::TYPE_INT, -Fiddle::TYPE_INT, -Fiddle::TYPE_INT, -Fiddle::TYPE_INT, -Fiddle::TYPE_INT]],
:DrawPrimitiveUP => [83, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, Fiddle::TYPE_INT, -Fiddle::TYPE_INT, Fiddle::TYPE_VOIDP, -Fiddle::TYPE_INT]],
:DrawIndexedPrimitiveUP => [84, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, Fiddle::TYPE_INT, -Fiddle::TYPE_INT, -Fiddle::TYPE_INT, -Fiddle::TYPE_INT, Fiddle::TYPE_VOIDP, Fiddle::TYPE_INT, Fiddle::TYPE_VOIDP, -Fiddle::TYPE_INT]],
:ProcessVertices => [85, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, -Fiddle::TYPE_INT, -Fiddle::TYPE_INT, -Fiddle::TYPE_INT, Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP, -Fiddle::TYPE_INT]],
:CreateVertexDeclaration => [86, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP]],
:SetVertexDeclaration => [87, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP]],
:GetVertexDeclaration => [88, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP]],
:SetFVF => [89, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, -Fiddle::TYPE_INT]],
:GetFVF => [90, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP]],
:CreateVertexShader => [91, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP]],
:SetVertexShader => [92, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP]],
:GetVertexShader => [93, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP]],
:SetVertexShaderConstantF => [94, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, -Fiddle::TYPE_INT, Fiddle::TYPE_VOIDP, -Fiddle::TYPE_INT]],
:GetVertexShaderConstantF => [95, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, -Fiddle::TYPE_INT, Fiddle::TYPE_VOIDP, -Fiddle::TYPE_INT]],
:SetVertexShaderConstantI => [96, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, -Fiddle::TYPE_INT, Fiddle::TYPE_VOIDP, -Fiddle::TYPE_INT]],
:GetVertexShaderConstantI => [97, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, -Fiddle::TYPE_INT, Fiddle::TYPE_VOIDP, -Fiddle::TYPE_INT]],
:SetVertexShaderConstantB => [98, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, -Fiddle::TYPE_INT, Fiddle::TYPE_VOIDP, -Fiddle::TYPE_INT]],
:GetVertexShaderConstantB => [99, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, -Fiddle::TYPE_INT, Fiddle::TYPE_VOIDP, -Fiddle::TYPE_INT]],
:SetStreamSource => [100, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, -Fiddle::TYPE_INT, Fiddle::TYPE_VOIDP, -Fiddle::TYPE_INT, -Fiddle::TYPE_INT]],
:GetStreamSource => [101, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, -Fiddle::TYPE_INT, Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP]],
:SetStreamSourceFreq => [102, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, -Fiddle::TYPE_INT, -Fiddle::TYPE_INT]],
:GetStreamSourceFreq => [103, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, -Fiddle::TYPE_INT, Fiddle::TYPE_VOIDP]],
:SetIndices => [104, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP]],
:GetIndices => [105, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP]],
:CreatePixelShader => [106, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP]],
:SetPixelShader => [107, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP]],
:GetPixelShader => [108, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP]],
:SetPixelShaderConstantF => [109, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, -Fiddle::TYPE_INT, Fiddle::TYPE_VOIDP, -Fiddle::TYPE_INT]],
:GetPixelShaderConstantF => [110, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, -Fiddle::TYPE_INT, Fiddle::TYPE_VOIDP, -Fiddle::TYPE_INT]],
:SetPixelShaderConstantI => [111, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, -Fiddle::TYPE_INT, Fiddle::TYPE_VOIDP, -Fiddle::TYPE_INT]],
:GetPixelShaderConstantI => [112, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, -Fiddle::TYPE_INT, Fiddle::TYPE_VOIDP, -Fiddle::TYPE_INT]],
:SetPixelShaderConstantB => [113, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, -Fiddle::TYPE_INT, Fiddle::TYPE_VOIDP, -Fiddle::TYPE_INT]],
:GetPixelShaderConstantB => [114, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, -Fiddle::TYPE_INT, Fiddle::TYPE_VOIDP, -Fiddle::TYPE_INT]],
:DrawRectPatch => [115, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, -Fiddle::TYPE_INT, Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP]],
:DrawTriPatch => [116, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, -Fiddle::TYPE_INT, Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP]],
:DeletePatch => [117, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, -Fiddle::TYPE_INT]],
:CreateQuery => [118, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, Fiddle::TYPE_INT, Fiddle::TYPE_VOIDP]],
}
end
# IDirect3DTexture9インターフェイス
class IDirect3DTexture9 < COM
@@functions = {
:QueryInterface => [0, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP]],
:AddRef => [1, -Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP]],
:Release => [2, -Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP]],
:GetDevice => [3, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP]],
:SetPrivateData => [4, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP, -Fiddle::TYPE_INT, -Fiddle::TYPE_INT]],
:GetPrivateData => [5, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP]],
:FreePrivateData => [6, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP]],
:SetPriority => [7, -Fiddle::TYPE_INT, [Fiddle::TYPE_VOIDP, -Fiddle::TYPE_INT]],
:GetPriority => [8, -Fiddle::TYPE_INT, [Fiddle::TYPE_VOIDP]],
:PreLoad => [9, Fiddle::TYPE_VOID, [Fiddle::TYPE_VOIDP]],
:GetType => [10, Fiddle::TYPE_INT, [Fiddle::TYPE_VOIDP]],
:SetLOD => [11, -Fiddle::TYPE_INT, [Fiddle::TYPE_VOIDP, -Fiddle::TYPE_INT]],
:GetLOD => [12, -Fiddle::TYPE_INT, [Fiddle::TYPE_VOIDP]],
:GetLevelCount => [13, -Fiddle::TYPE_INT, [Fiddle::TYPE_VOIDP]],
:SetAutoGenFilterType => [14, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, Fiddle::TYPE_INT]],
:GetAutoGenFilterType => [15, Fiddle::TYPE_INT, [Fiddle::TYPE_VOIDP]],
:GenerateMipSubLevels => [16, Fiddle::TYPE_VOID, [Fiddle::TYPE_VOIDP]],
:GetLevelDesc => [17, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, -Fiddle::TYPE_INT, Fiddle::TYPE_VOIDP]],
:GetSurfaceLevel => [18, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, -Fiddle::TYPE_INT, Fiddle::TYPE_VOIDP]],
:LockRect => [19, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, -Fiddle::TYPE_INT, Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP, -Fiddle::TYPE_INT]],
:UnlockRect => [20, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, -Fiddle::TYPE_INT]],
:AddDirtyRect => [21, Fiddle::TYPE_LONG, [Fiddle::TYPE_VOIDP, Fiddle::TYPE_VOIDP]],
}
end
# IDirect3D9インターフェイス生成
d3d9 = IDirect3D9.new
d3d9.ptr = D3D9::Direct3DCreate9(D3D9::D3D_SDK_VERSION)
# CreateDeviceの引数の構造体生成
d3dpp = D3D9::D3DPRESENT_PARAMETERS.malloc
d3dpp.BackBufferWidth = 0
d3dpp.BackBufferHeight = 0
d3dpp.BackBufferFormat = D3D9::D3DFMT_UNKNOWN
d3dpp.BackBufferCount = 2
d3dpp.MultiSampleType = D3D9::D3DMULTISAMPLE_NONE
d3dpp.MultiSampleQuality = 0
d3dpp.SwapEffect = D3D9::D3DSWAPEFFECT_DISCARD
d3dpp.hDeviceWindow = hWnd
d3dpp.Windowed = 1
d3dpp.EnableAutoDepthStencil = 1
d3dpp.AutoDepthStencilFormat = D3D9::D3DFMT_D24S8
d3dpp.Flags = 0
d3dpp.FullScreen_RefreshRateInHz = 0
d3dpp.PresentationInterval = D3D9::D3DPRESENT_INTERVAL_IMMEDIATE
# CreateDevice呼び出しと、返ってきた値からIDirect3DDevice9インターフェイス生成
d3ddevice = IDirect3DDevice9.new
hr = d3d9.CreateDevice(D3D9::D3DADAPTER_DEFAULT,
D3D9::D3DDEVTYPE_HAL,
hWnd,
D3D9::D3DCREATE_MIXED_VERTEXPROCESSING,
d3dpp,
d3ddevice.ref)
# D3DVIEWPORT9作成
vp = D3D9::D3DVIEWPORT9.malloc
vp.X = 0
vp.Y = 0
vp.Width = width
vp.Height = height
vp.MinZ = 0.0
vp.MaxZ = 1.0
# ビューポート設定
hr = d3ddevice.SetViewport(vp)
# 背景色塗りつぶし
d3ddevice.Clear(0, 0, D3D9::D3DCLEAR_TARGET, D3D9::D3DCOLOR_XRGB(0,0,0), 1.0, 0 )
# 三角形用の構造体定義
module D3D9
D3DVERTEX = struct([
"float x",
"float y",
"float z",
"float rhw",
"D3DCOLOR diffuse"
])
end
# 頂点情報
vp = Fiddle::Pointer.malloc(D3D9::D3DVERTEX.size * 3) # 頂点構造体用メモリをまとめて取得
v = Array.new(3){|i|D3D9::D3DVERTEX.new(vp.to_i + D3D9::D3DVERTEX.size * i)} # アドレスを計算してD3DVERTEX構造体を生成
v[0].x = 150
v[0].y = 50
v[0].z = 0
v[0].rhw = 1
v[0].diffuse = 0xffff0000
v[1].x = 200
v[1].y = 150
v[1].z = 0
v[1].rhw = 1
v[1].diffuse = 0xff00ff00
v[2].x = 100
v[2].y = 150
v[2].z = 0
v[2].rhw = 1
v[2].diffuse = 0xff0000ff
# 描画開始
d3ddevice.BeginScene()
# 頂点情報の形を指定
d3ddevice.SetFVF(D3D9::D3DFVF_XYZRHW | D3D9::D3DFVF_DIFFUSE)
# 描画
d3ddevice.DrawPrimitiveUP(D3D9::D3DPT_TRIANGLELIST, 1, vp, D3D9::D3DVERTEX.size)
# 描画終了
d3ddevice.EndScene()
# 画面に反映
d3ddevice.Present(0, 0, 0, 0)
# ウィンドウメッセージ構造体作成
msg = WinAPI::MSG.malloc
# メッセージループ
loop do
if WinAPI::GetMessageA(msg, 0, 0, 0) == 0
break
end
WinAPI::TranslateMessage(msg)
WinAPI::DispatchMessageA(msg)
end
# DirectXのオブジェクトを破棄
d3ddevice.Release()
d3ddevice.ptr = nil
d3d9.Release()
d3d9.ptr = nil
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment