// shaders.cpp : Defines the entry point for the application.
//
#include "stdafx.h"
#include "resource.h"
#include <d3dx9.h>
#include <cassert>
#define MAX_LOADSTRING 100
// Global Variables:
HINSTANCE hInst; // current instance
TCHAR szTitle[MAX_LOADSTRING]; // The title bar text
TCHAR szWindowClass[MAX_LOADSTRING]; // The title bar text
// Foward declarations of functions included in this code module:
ATOM MyRegisterClass(HINSTANCE hInstance);
BOOL InitInstance(HINSTANCE, int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK About(HWND, UINT, WPARAM, LPARAM);
bool ClearDepthStencil();
bool Asm();
bool Hlsl();
bool InitD3D(HWND hWnd);
void ShutdownD3D();
// Globals
PDIRECT3D9 g_pD3D;
PDIRECT3DDEVICE9 g_pd3dDevice;
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
// TODO: Place code here.
MSG msg;
HACCEL hAccelTable;
// Initialize global strings
LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
LoadString(hInstance, IDC_SHADERS, szWindowClass, MAX_LOADSTRING);
MyRegisterClass(hInstance);
// Perform application initialization:
if (!InitInstance (hInstance, nCmdShow))
{
goto END;
}
hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_SHADERS);
// Main message loop:
PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE);
while (msg.message != WM_QUIT)
{
if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
else
{
// if(!Asm())
// break;
if(!Hlsl())
break;
}
}
END:
ShutdownD3D();
return msg.wParam;
}
//
// FUNCTION: MyRegisterClass()
//
// PURPOSE: Registers the window class.
//
// COMMENTS:
//
// This function and its usage is only necessary if you want this code
// to be compatible with Win32 systems prior to the ''RegisterClassEx''
// function that was added to Windows 95. It is important to call this function
// so that the application will get ''well formed'' small icons associated
// with it.
//
ATOM MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = (WNDPROC)WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(hInstance, (LPCTSTR)IDI_SHADERS);
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = NULL;
wcex.lpszMenuName = (LPCSTR)IDC_SHADERS;
wcex.lpszClassName = szWindowClass;
wcex.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);
return RegisterClassEx(&wcex);
}
//
// FUNCTION: InitInstance(HANDLE, int)
//
// PURPOSE: Saves instance handle and creates main window
//
// COMMENTS:
//
// In this function, we save the instance handle in a global variable and
// create and display the main program window.
//
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
HWND hWnd;
hInst = hInstance; // Store instance handle in our global variable
hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
if (!hWnd)
{
return FALSE;
}
// Create device
if(!InitD3D(hWnd))
return FALSE;
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
return TRUE;
}
//
// FUNCTION: WndProc(HWND, unsigned, WORD, LONG)
//
// PURPOSE: Processes messages for the main window.
//
// WM_COMMAND - process the application menu
// WM_PAINT - Paint the main window
// WM_DESTROY - post a quit message and return
//
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc;
switch (message)
{
case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
// Parse the menu selections:
switch (wmId)
{
case IDM_ABOUT:
DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About);
break;
case IDM_EXIT:
DestroyWindow(hWnd);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
break;
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
// TODO: Add any drawing code here...
EndPaint(hWnd, &ps);
break;
case WM_ERASEBKGND:
if(!ClearDepthStencil())
PostQuitMessage(0);
return 1;
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
// Mesage handler for about box.
LRESULT CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_INITDIALOG:
return TRUE;
case WM_COMMAND:
if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
{
EndDialog(hDlg, LOWORD(wParam));
return TRUE;
}
break;
}
return FALSE;
}
bool InitD3D(HWND hWnd)
{
g_pD3D = Direct3DCreate9(D3D_SDK_VERSION);
if(!g_pD3D)
{
assert(g_pD3D);
return false;
}
D3DDISPLAYMODE dm;// Query primary adapter
if(FAILED(g_pD3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &dm)))
{
assert(0);
return false;
}
D3DPRESENT_PARAMETERS pp;
ZeroMemory(&pp, sizeof(pp));
pp.Windowed = TRUE;
pp.SwapEffect = D3DSWAPEFFECT_DISCARD;
pp.BackBufferFormat = dm.Format;
pp.EnableAutoDepthStencil = TRUE;
pp.AutoDepthStencilFormat = D3DFMT_D24S8;
if(FAILED(g_pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,
D3DCREATE_SOFTWARE_VERTEXPROCESSING, &pp, &g_pd3dDevice)))
{
assert(0);
return false;
}
return true;
}
bool ClearDepthStencil()
{
if(FAILED(g_pd3dDevice->Clear(0, NULL, D3DCLEAR_TARGET|D3DCLEAR_STENCIL|D3DCLEAR_ZBUFFER,
D3DCOLOR_XRGB(0,0,0), 1.0f, 0)))
{
assert(0);
return false;
}
return true;
}
void ShutdownD3D()
{
if(g_pd3dDevice)
g_pd3dDevice->Release();
if(g_pD3D)
g_pD3D->Release();
}
bool Asm()
{
if(!ClearDepthStencil())
return false;
if(FAILED(g_pd3dDevice->BeginScene()))
assert(0);
// Update color buffer
g_pd3dDevice->SetRenderState(D3DRS_COLORWRITEENABLE, ~0);
// Z-buffer
g_pd3dDevice->SetRenderState(D3DRS_ZENABLE, D3DZB_TRUE);
g_pd3dDevice->SetRenderState(D3DRS_ZWRITEENABLE, TRUE);
g_pd3dDevice->SetRenderState(D3DRS_ZFUNC, D3DCMP_LESSEQUAL);
g_pd3dDevice->SetRenderState(D3DRS_DEPTHBIAS, 0);// 0 to 16
// Fill/shade/light
g_pd3dDevice->SetRenderState(D3DRS_FILLMODE, D3DFILL_SOLID);
g_pd3dDevice->SetRenderState(D3DRS_SHADEMODE, D3DSHADE_FLAT);
g_pd3dDevice->SetRenderState(D3DRS_LIGHTING, FALSE);
g_pd3dDevice->SetRenderState(D3DRS_COLORVERTEX, FALSE);
// Cull
g_pd3dDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CCW);
// Fog
g_pd3dDevice->SetRenderState(D3DRS_FOGENABLE, FALSE);
g_pd3dDevice->SetRenderState(D3DRS_FOGCOLOR, D3DCOLOR_XRGB(0, 0, 200));
g_pd3dDevice->SetRenderState(D3DRS_FOGTABLEMODE, D3DFOG_LINEAR);
// Stencil
g_pd3dDevice->SetRenderState(D3DRS_STENCILENABLE, FALSE);
g_pd3dDevice->SetRenderState(D3DRS_STENCILFAIL, D3DSTENCILOP_KEEP);
g_pd3dDevice->SetRenderState(D3DRS_STENCILZFAIL, D3DSTENCILOP_KEEP);
g_pd3dDevice->SetRenderState(D3DRS_STENCILPASS, D3DSTENCILOP_KEEP);
g_pd3dDevice->SetRenderState(D3DRS_STENCILFUNC, D3DCMP_ALWAYS);
g_pd3dDevice->SetRenderState(D3DRS_STENCILREF, 0);
g_pd3dDevice->SetRenderState(D3DRS_STENCILMASK, ~0);
g_pd3dDevice->SetRenderState(D3DRS_STENCILWRITEMASK, ~0);
// Alphatest
g_pd3dDevice->SetRenderState(D3DRS_ALPHATESTENABLE, FALSE);
g_pd3dDevice->SetRenderState(D3DRS_ALPHAREF, 0);
g_pd3dDevice->SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_NOTEQUAL);
// Alphablend
g_pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
// Clipping
g_pd3dDevice->SetRenderState(D3DRS_CLIPPING, TRUE);
/***********************/
D3DCAPS9 caps;
g_pd3dDevice->GetDeviceCaps(&caps);
if(caps.VertexShaderVersion < D3DVS_VERSION(1,1))
assert(0);
struct CUSTOMVERTEX
{
float x,y,z;
};
CUSTOMVERTEX poly[] = {
{-1, 1, 0},
{ 1, 1, 0},
{ 1,-1, 0},
{-1,-1, 0}};
D3DVERTEXELEMENT9 decl[] =
{
{0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
D3DDECL_END()
};
PDIRECT3DVERTEXBUFFER9 pVB = NULL;
if(FAILED(g_pd3dDevice->CreateVertexBuffer(4*sizeof(CUSTOMVERTEX), D3DUSAGE_WRITEONLY, 0,
D3DPOOL_DEFAULT, &pVB, 0)))
assert(0);
void* pVertices = NULL;
if(FAILED(pVB->Lock(0, 0, (void**)&pVertices, 0)))
assert(0);
memcpy(pVertices, poly, sizeof(poly));
pVB->Unlock();
PDIRECT3DVERTEXDECLARATION9 pVertexDeclaration = NULL;
if(FAILED(g_pd3dDevice->CreateVertexDeclaration(decl, &pVertexDeclaration)))
assert(0);
if(FAILED(g_pd3dDevice->SetVertexDeclaration(pVertexDeclaration)))
assert(0);
if(FAILED(g_pd3dDevice->SetStreamSource(0, pVB, 0, sizeof(CUSTOMVERTEX))))
assert(0);
// Update vertex shader constants from view projection matrix data.
D3DXMATRIX mat, matView, matProj;
D3DXMatrixLookAtLH(
&matView,
&D3DXVECTOR3(0, 0, -5), // eye
&D3DXVECTOR3(0, 0, 0), // looking at
&D3DXVECTOR3(0, 1, 0)); // up
D3DXMatrixPerspectiveFovLH(
&matProj, // In/Out
D3DXToRadian(80.0f),// Field of view in vertical plane(typically (1/4)pi or 45deg)
1.0f, // Aspect ratio, height / width
0.10f, // Near clipping plane positive value
100.0f);// Far clipping plane positive value
D3DXMatrixMultiply(&mat, &matView, &matProj);
D3DXMatrixTranspose(&mat, &mat);
if(FAILED(g_pd3dDevice->SetVertexShaderConstantF(0, (float*)&mat, 4)))
assert(0);
PDIRECT3DVERTEXSHADER9 pVertexShader = NULL;
LPD3DXBUFFER pCode = NULL; // Buffer with the assembled shader code
LPD3DXBUFFER pErrorMsgs = NULL; // Buffer with error messages
const char vs[] =
"vs_1_1 \n"
"dcl_position v0 \n"
"def c4, 1, 1, 0, 1 \n"
"m4x4 oPos, v0, c0 \n"
"mov oD0, c4 ";
if(FAILED(D3DXAssembleShader(vs, strlen(vs), NULL, NULL, 0, &pCode, &pErrorMsgs)))
assert(0);
if(!pCode)
assert(0);
if(pErrorMsgs)
{
pErrorMsgs->Release();
assert(0);
}
if(FAILED(g_pd3dDevice->CreateVertexShader((DWORD*)pCode->GetBufferPointer(), &pVertexShader)))
assert(0);
pCode->Release();
// Render the output
if(FAILED(g_pd3dDevice->SetVertexShader(pVertexShader)))
assert(0);
if(FAILED(g_pd3dDevice->DrawPrimitive(D3DPT_TRIANGLEFAN, 0, 2)))
assert(0);
if(FAILED(g_pd3dDevice->EndScene()))
assert(0);
g_pd3dDevice->Present(NULL, NULL, NULL, NULL);
if(pVB)
pVB->Release();
if(pVertexShader)
pVertexShader->Release();
if(pVertexDeclaration)
pVertexDeclaration->Release();
return true;
}
bool Hlsl()
{
if(!ClearDepthStencil())
return false;
if(FAILED(g_pd3dDevice->BeginScene()))
assert(0);
// Update color buffer
g_pd3dDevice->SetRenderState(D3DRS_COLORWRITEENABLE, ~0);
// Z-buffer
g_pd3dDevice->SetRenderState(D3DRS_ZENABLE, D3DZB_TRUE);
g_pd3dDevice->SetRenderState(D3DRS_ZWRITEENABLE, TRUE);
g_pd3dDevice->SetRenderState(D3DRS_ZFUNC, D3DCMP_LESSEQUAL);
g_pd3dDevice->SetRenderState(D3DRS_DEPTHBIAS, 0);// 0 to 16
// Fill/shade/light
g_pd3dDevice->SetRenderState(D3DRS_FILLMODE, D3DFILL_SOLID);
g_pd3dDevice->SetRenderState(D3DRS_SHADEMODE, D3DSHADE_FLAT);
g_pd3dDevice->SetRenderState(D3DRS_LIGHTING, FALSE);
g_pd3dDevice->SetRenderState(D3DRS_COLORVERTEX, FALSE);
// Cull
g_pd3dDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CCW);
// Fog
g_pd3dDevice->SetRenderState(D3DRS_FOGENABLE, FALSE);
g_pd3dDevice->SetRenderState(D3DRS_FOGCOLOR, D3DCOLOR_XRGB(0, 0, 200));
g_pd3dDevice->SetRenderState(D3DRS_FOGTABLEMODE, D3DFOG_LINEAR);
// Stencil
g_pd3dDevice->SetRenderState(D3DRS_STENCILENABLE, FALSE);
g_pd3dDevice->SetRenderState(D3DRS_STENCILFAIL, D3DSTENCILOP_KEEP);
g_pd3dDevice->SetRenderState(D3DRS_STENCILZFAIL, D3DSTENCILOP_KEEP);
g_pd3dDevice->SetRenderState(D3DRS_STENCILPASS, D3DSTENCILOP_KEEP);
g_pd3dDevice->SetRenderState(D3DRS_STENCILFUNC, D3DCMP_ALWAYS);
g_pd3dDevice->SetRenderState(D3DRS_STENCILREF, 0);
g_pd3dDevice->SetRenderState(D3DRS_STENCILMASK, ~0);
g_pd3dDevice->SetRenderState(D3DRS_STENCILWRITEMASK, ~0);
// Alphatest
g_pd3dDevice->SetRenderState(D3DRS_ALPHATESTENABLE, FALSE);
g_pd3dDevice->SetRenderState(D3DRS_ALPHAREF, 0);
g_pd3dDevice->SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_NOTEQUAL);
// Alphablend
g_pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
// Clipping
g_pd3dDevice->SetRenderState(D3DRS_CLIPPING, TRUE);
/***********************/
D3DCAPS9 caps;
g_pd3dDevice->GetDeviceCaps(&caps);
if(caps.VertexShaderVersion < D3DVS_VERSION(1,1))
assert(0);
struct CUSTOMVERTEX
{
float x,y,z;
};
CUSTOMVERTEX poly[] = {
{-1, 1, 0},
{ 1, 1, 0},
{ 1,-1, 0},
{-1,-1, 0}};
D3DVERTEXELEMENT9 decl[] =
{
{0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
D3DDECL_END()
};
PDIRECT3DVERTEXBUFFER9 pVB = NULL;
if(FAILED(g_pd3dDevice->CreateVertexBuffer(4*sizeof(CUSTOMVERTEX), D3DUSAGE_WRITEONLY, 0,
D3DPOOL_DEFAULT, &pVB, 0)))
assert(0);
void* pVertices = NULL;
if(FAILED(pVB->Lock(0, 0, (void**)&pVertices, 0)))
assert(0);
memcpy(pVertices, poly, sizeof(poly));
pVB->Unlock();
PDIRECT3DVERTEXDECLARATION9 pVertexDeclaration = NULL;
if(FAILED(g_pd3dDevice->CreateVertexDeclaration(decl, &pVertexDeclaration)))
assert(0);
if(FAILED(g_pd3dDevice->SetVertexDeclaration(pVertexDeclaration)))
assert(0);
if(FAILED(g_pd3dDevice->SetStreamSource(0, pVB, 0, sizeof(CUSTOMVERTEX))))
assert(0);
// Update vertex shader constants from view projection matrix data.
D3DXMATRIX mat, matView, matProj;
D3DXMatrixLookAtLH(
&matView,
&D3DXVECTOR3(0, 0, -5), // eye
&D3DXVECTOR3(0, 0, 0), // looking at
&D3DXVECTOR3(0, 1, 0)); // up
D3DXMatrixPerspectiveFovLH(
&matProj, // In/Out
D3DXToRadian(80.0f),// Field of view in vertical plane(typically (1/4)pi or 45deg)
1.0f, // Aspect ratio, height / width
0.10f, // Near clipping plane positive value
100.0f);// Far clipping plane positive value
D3DXMatrixMultiply(&mat, &matView, &matProj);
D3DXMatrixTranspose(&mat, &mat);
if(FAILED(g_pd3dDevice->SetVertexShaderConstantF(0, (float*)&mat, 4)))
assert(0);
PDIRECT3DVERTEXSHADER9 pVertexShader = NULL;
LPD3DXBUFFER pCode = NULL; // Buffer with the assembled shader code
LPD3DXBUFFER pErrorMsgs = NULL; // Buffer with error messages
const char vs[] =
"struct VS_INPUT \n"
"{ \n"
" float4 position : POSITION; \n"
"}; \n"
" \n"
"struct VS_OUTPUT \n"
"{ \n"
" float4 position : POSITION; \n"
" float3 color : COLOR; \n"
"}; \n"
" \n"
"VS_OUTPUT main(const VS_INPUT v, \n"
" uniform float4x4 mat : c0) \n"
"{ \n"
" VS_OUTPUT o; \n"
" o.position = mul(mat, v.position); \n"
" o.color = float3(1,1,0); \n"
" return o; \n"
"} ";
if(FAILED(D3DXCompileShader(vs, strlen(vs), NULL, NULL, "main", "vs_1_1", 0,
&pCode, &pErrorMsgs, NULL)))
assert(0);
if(!pCode)
assert(0);
if(pErrorMsgs)
{
pErrorMsgs->Release();
assert(0);
}
if(FAILED(g_pd3dDevice->CreateVertexShader((DWORD*)pCode->GetBufferPointer(), &pVertexShader)))
assert(0);
pCode->Release();
// Render the output
if(FAILED(g_pd3dDevice->SetVertexShader(pVertexShader)))
assert(0);
if(FAILED(g_pd3dDevice->DrawPrimitive(D3DPT_TRIANGLEFAN, 0, 2)))
assert(0);
if(FAILED(g_pd3dDevice->EndScene()))
assert(0);
g_pd3dDevice->Present(NULL, NULL, NULL, NULL);
if(pVB)
pVB->Release();
if(pVertexShader)
pVertexShader->Release();
if(pVertexDeclaration)
pVertexDeclaration->Release();
return true;
}
Asm/HLSL sample inside
Just a quad drawn with constant color. Demonstrates how to do write hlsl and asm shader into string ie. memory then compile/assemble the shader and draw the object. Notice, the only difference between the two is in Assemble() and Compile() calls everything else is the same. Data is passed into shaders thru constants, in hlsl using ''uniform'' keyword and '':'' constant syntax. Make a win32 project and paste in the text. Uses dx9 libs so make sure you have them listed in project settings ie. for debugdxguid.lib, d3dx9d.lib, d3d9.lib) for release it''s d3dx9.lib and others stay the same. Have fun
I''m fine with c++/mfc/win32/dx9 for now, they haven''t limited me yet. Someone posted c# code hlsl example on this board, take a look around if you need it.
Duh, no doubt you''ve seen the c# code already as I checked it was posted in your thread topic. Sorry about beeing little slow today
Can''t you just take my c++ dx9 setup/hlsl calls and try to match them to c#/dx9 calls? Give it a try I don''t think the concepts are that radical between c++ and c#, or are they?
Ok, the string hlsl code is same as in c# and c++. What''s c# equivalent for D3DXCompileShader(), CreateVertexBuffer(), VertexBuffer->Lock/Unlock(), CreateVertexDeclaration(), SetVertexDeclaration(), SetStreamSource(), D3DXMatrixPerspectiveFovLH(), D3DXMatrixMultiply(), D3DXMatrixTranspose(), SetVertexShaderConstantF(), CreateVertexShader(), SetVertexShader(), DrawPrimitive(), Begin/End Scene(), Present().
Find c# objects that have these methods. Isn''t there a win32 eqivalent wizard in c# like win forms or something like that that would give you the windowing boilerplate?
Then just follow the order of calls, you don''t have to specifically since dx9 is state machine but it''ll be easier I think. That''s what I would do if I were you instead of waiting for someone to give me what I want. If I did that I would never have hlsl example working, I had to study CG manual and compare stuff to dx9 hlsl to figure stuff out. Don''t be lazy Didn''t meant to offend you just give you some motivation and a start.
Can''t you just take my c++ dx9 setup/hlsl calls and try to match them to c#/dx9 calls? Give it a try I don''t think the concepts are that radical between c++ and c#, or are they?
Ok, the string hlsl code is same as in c# and c++. What''s c# equivalent for D3DXCompileShader(), CreateVertexBuffer(), VertexBuffer->Lock/Unlock(), CreateVertexDeclaration(), SetVertexDeclaration(), SetStreamSource(), D3DXMatrixPerspectiveFovLH(), D3DXMatrixMultiply(), D3DXMatrixTranspose(), SetVertexShaderConstantF(), CreateVertexShader(), SetVertexShader(), DrawPrimitive(), Begin/End Scene(), Present().
Find c# objects that have these methods. Isn''t there a win32 eqivalent wizard in c# like win forms or something like that that would give you the windowing boilerplate?
Then just follow the order of calls, you don''t have to specifically since dx9 is state machine but it''ll be easier I think. That''s what I would do if I were you instead of waiting for someone to give me what I want. If I did that I would never have hlsl example working, I had to study CG manual and compare stuff to dx9 hlsl to figure stuff out. Don''t be lazy Didn''t meant to offend you just give you some motivation and a start.
Ok, out of curiosity I looked at MS dx9 c# docs and I found everything that I would need to convert the above c++ example into c# code. Start with these two namespaces and their classes:
Microsoft.DirectX
- Structures
- Matrix, Vector3, etc.
Microsoft.DirectX.Direct3D
-ShaderLoader.CompileShader
-GraphicsStream
-Device
-VertexShader
-VertexDeclaration
-VertexElement
Read over their documentation then match their methods to my c++ code and proceed from there. There are also tutorials on how to setup windowing environment and direct3d so read them too. Each method spec shows examples how to use it. I know the docs are not the best but you really do have everything you need plus that bit of code someone posted in your original thread. Good luck!
Microsoft.DirectX
- Structures
- Matrix, Vector3, etc.
Microsoft.DirectX.Direct3D
-ShaderLoader.CompileShader
-GraphicsStream
-Device
-VertexShader
-VertexDeclaration
-VertexElement
Read over their documentation then match their methods to my c++ code and proceed from there. There are also tutorials on how to setup windowing environment and direct3d so read them too. Each method spec shows examples how to use it. I know the docs are not the best but you really do have everything you need plus that bit of code someone posted in your original thread. Good luck!
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement