代码改变世界

Direct3D 9学习笔记(15)顶点着色器

2012-09-28 22:49  Clingingboy  阅读(690)  评论(0编辑  收藏  举报

 

顶点着色器

image

 

顶点着色器的创建

image

顶点着色器的设置

image

顶点着色器的销毁

image

Demo示例

ID3DXBuffer* shader      = 0;
ID3DXBuffer* errorBuffer = 0;

hr = D3DXCompileShaderFromFile(
    "diffuse.txt",
    0,
    0,
    "Main", // entry point function name
    "vs_1_1",
    D3DXSHADER_DEBUG, 
    &shader,
    &errorBuffer,
    &DiffuseConstTable);

// output any error messages
if( errorBuffer )
{
    ::MessageBox(0, (char*)errorBuffer->GetBufferPointer(), 0, 0);
    d3d::Release<ID3DXBuffer*>(errorBuffer);
}

if(FAILED(hr))
{
    ::MessageBox(0, "D3DXCompileShaderFromFile() - FAILED", 0, 0);
    return false;
}

//
// Create shader
//

hr = Device->CreateVertexShader(
    (DWORD*)shader->GetBufferPointer(),
    &DiffuseShader);

if(FAILED(hr))
{
    ::MessageBox(0, "CreateVertexShader - FAILED", 0, 0);
    return false;
}

d3d::Release<ID3DXBuffer*>(shader);

启用Shader

Device->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffffffff, 1.0f, 0);
Device->BeginScene();

Device->SetVertexShader(DiffuseShader);

Teapot->DrawSubset(0);

Device->EndScene();
Device->Present(0, 0, 0, 0);

 

image