Direct3D Intro - HLSL 1.x Compile Error
来源:互联网 发布:金角大王异步网络框架 编辑:程序博客网 时间:2024/05/24 07:10
On Direct3D9 Project, Following codes will cause failing to compile on Visual Studio 2013
1. Sample Code Snippet
D3DVERTEXELEMENT9 declaration[] =
{
{ 0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 },
{ 0, 12, D3DDECLTYPE_D3DCOLOR, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 0 },
{ 0, 16, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0 },
D3DDECL_END()
};
{
{ 0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 },
{ 0, 12, D3DDECLTYPE_D3DCOLOR, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 0 },
{ 0, 16, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0 },
D3DDECL_END()
};
g_pd3dDevice->CreateVertexDeclaration( declaration, &g_pVertexDeclaration );
HRESULT hr;
LPD3DXBUFFER pCode;
DWORD dwShaderFlags = 0;
LPD3DXBUFFER pBufferErrors = NULL;
LPD3DXBUFFER pCode;
DWORD dwShaderFlags = 0;
LPD3DXBUFFER pBufferErrors = NULL;
// Assemble the vertex shader from the file
hr = D3DXCompileShaderFromFile(L"vertex_shader.vsh", NULL, NULL, "main",
"vs_1_1", dwShaderFlags, &pCode,
&pBufferErrors, &g_pConstantTableVS );
hr = D3DXCompileShaderFromFile(L"vertex_shader.vsh", NULL, NULL, "main",
"vs_1_1", dwShaderFlags, &pCode,
&pBufferErrors, &g_pConstantTableVS );
if( FAILED(hr) )
{
LPVOID pCompilErrors = pBufferErrors->GetBufferPointer();
MessageBox(NULL, (LPCTSTR)pCompilErrors, L"Vertex Shader Compile Error",
MB_OK|MB_ICONEXCLAMATION);
}
{
LPVOID pCompilErrors = pBufferErrors->GetBufferPointer();
MessageBox(NULL, (LPCTSTR)pCompilErrors, L"Vertex Shader Compile Error",
MB_OK|MB_ICONEXCLAMATION);
}
// Create the vertex shader
g_pd3dDevice->CreateVertexShader( (DWORD*)pCode->GetBufferPointer(),
&g_pVertexShader );
pCode->Release();
//
// Create a HLSL based pixel shader.
//
g_pd3dDevice->CreateVertexShader( (DWORD*)pCode->GetBufferPointer(),
&g_pVertexShader );
pCode->Release();
//
// Create a HLSL based pixel shader.
//
// Assemble the vertex shader from the file
hr = D3DXCompileShaderFromFile( L"pixel_shader.psh", NULL, NULL, "main",
"ps_1_1", dwShaderFlags, &pCode,
&pBufferErrors, &g_pConstantTablePS ); // if error, please change ps_1_1 to ps_2_0, retry to compile
hr = D3DXCompileShaderFromFile( L"pixel_shader.psh", NULL, NULL, "main",
"ps_1_1", dwShaderFlags, &pCode,
&pBufferErrors, &g_pConstantTablePS ); // if error, please change ps_1_1 to ps_2_0, retry to compile
if( FAILED(hr) )
{
LPVOID pCompilErrors = pBufferErrors->GetBufferPointer();
MessageBox(NULL, (LPCTSTR)pCompilErrors, L"Pixel Shader Compile Error",
MB_OK|MB_ICONEXCLAMATION);
}
{
LPVOID pCompilErrors = pBufferErrors->GetBufferPointer();
MessageBox(NULL, (LPCTSTR)pCompilErrors, L"Pixel Shader Compile Error",
MB_OK|MB_ICONEXCLAMATION);
}
// Create the vertex shader
g_pd3dDevice->CreatePixelShader( (DWORD*)pCode->GetBufferPointer(),
&g_pPixelShader );
pCode->Release();
g_pd3dDevice->CreatePixelShader( (DWORD*)pCode->GetBufferPointer(),
&g_pPixelShader );
pCode->Release();
2. Vertex Shader
float4x4 worldViewProj;
struct VS_INPUT
{
float3 position : POSITION;
float4 color0 : COLOR0;
float2 texcoord0 : TEXCOORD0;
};
{
float3 position : POSITION;
float4 color0 : COLOR0;
float2 texcoord0 : TEXCOORD0;
};
struct VS_OUTPUT
{
float4 hposition : POSITION;
float4 color0 : COLOR0;
float2 texcoord0 : TEXCOORD0;
};
{
float4 hposition : POSITION;
float4 color0 : COLOR0;
float2 texcoord0 : TEXCOORD0;
};
VS_OUTPUT main( VS_INPUT IN )
{
VS_OUTPUT OUT;
{
VS_OUTPUT OUT;
float4 v = float4( IN.position.x,
IN.position.y,
IN.position.z,
1.0f );
IN.position.y,
IN.position.z,
1.0f );
OUT.hposition = mul( v, worldViewProj );
OUT.color0 = IN.color0;
OUT.texcoord0 = IN.texcoord0;
OUT.color0 = IN.color0;
OUT.texcoord0 = IN.texcoord0;
return OUT;
}
}
3. pixel shader
struct VS_OUTPUT
{
float4 hposition : POSITION;
float4 color0 : COLOR0;
float2 texcoord0 : TEXCOORD0;
};
{
float4 hposition : POSITION;
float4 color0 : COLOR0;
float2 texcoord0 : TEXCOORD0;
};
struct PS_OUTPUT
{
float4 color : COLOR;
};
{
float4 color : COLOR;
};
sampler testTexture;
PS_OUTPUT main( VS_OUTPUT IN )
{
PS_OUTPUT OUT;
{
PS_OUTPUT OUT;
//OUT.color = tex2D( testTexture, IN.texcoord0 ) * IN.color0; // Modulate texel color with vertex color
OUT.color = tex2D( testTexture, IN.texcoord0 ) + IN.color0; // Add texel color to vertex color
OUT.color = tex2D( testTexture, IN.texcoord0 ) + IN.color0; // Add texel color to vertex color
return OUT;
}
}
0 0
- Direct3D Intro - HLSL 1.x Compile Error
- Nasm Assambly Intro - Compile error
- Win10 VS2013 Compile Intro - C2011 Error
- Windows Dev Intro - Direct2D Compile Error
- Direct3D中的HLSL
- Direct3D中的HLSL(上)
- Windows Direct3D Intro - Device Lost
- NASM Intro - Compile and Link
- OpenH264 Intro - Compile on win7
- Writing HLSL Shaders in Direct3D 9
- Compile Error
- Windows Direct3D Intro - Multiple Viewport Render
- HLSL 中的error X3025
- sencha app build Error: Mixed-Mode x-compile
- PJSIP Intro - CSipSimple Compile on ubuntu
- Webrtc Intro - Compile Steps on Linux Generally
- x265 Dev Intro - Compile and Install
- x265 Compile Intro - Compile x265 with Debug Enabled
- 关于getContext()、getApplication()、getApplicationContext()、getActivity()的区别
- 在java方法中改变传递的参数的值
- Linux下perl文件的执行
- MongoDB之集群安装部署与shard操作
- Afinal的详细使用
- Direct3D Intro - HLSL 1.x Compile Error
- window命令提示符快捷键
- 62、Java基础之数组
- iOS 视频相关
- U3d菜单栏变化:Camera的Smooth Follow属性位置,U3d自带地势资源包的导入,天空盒设置
- 第七章:Linux文件与目录管理
- jQuery deferred的实践,ajax请求增加缓存处理
- Flexbox布局笔记
- String,StringBuffer与StringBuilder的区别