ID3DXEffect* effect; D3DXCreateEffectFromFile(d3dDevice, "basic.fx", NULL, NULL, D3DXSHADER_DEBUG, NULL, &effect, NULL); // Setting up variables and constant table D3DXHANDLE technique = effect->GetTechniqueByName("BasicTechnique"); D3DXHANDLE worldViewProjHandle = effect->GetParameterByName(NULL, "WorldViewProj"); D3DXHANDLE materialColorHandle = effect->GetParameterByName(NULL, "MaterialColor"); // Applying the shader D3DXMATRIX worldViewProj; D3DXMatrixMultiply(&worldViewProj, &worldMatrix, &viewProjMatrix); effect->SetMatrix(worldViewProjHandle, &worldViewProj); effect->SetVector(materialColorHandle, &materialColor); effect->Begin(NULL, NULL); effect->BeginPass(0); mesh->DrawSubset(subset); effect->EndPass(); effect->End();
ID3DXEffect* effect; D3DXCreateEffectFromFile(d3dDevice, "textured.fx", NULL, NULL, D3DXSHADER_DEBUG, NULL, &effect, NULL); // Setting up variables and constant table D3DXHANDLE technique = effect->GetTechniqueByName("TexturedTechnique"); D3DXHANDLE worldViewProjHandle = effect->GetParameterByName(NULL, "WorldViewProj"); D3DXHANDLE textureHandle = effect->GetParameterByName(NULL, "Texture"); // Applying the shader D3DXMATRIX worldViewProj; D3DXMatrixMultiply(&worldViewProj, &worldMatrix, &viewProjMatrix); effect->SetMatrix(worldViewProjHandle, &worldViewProj); IDirect3DTexture9* texture = LoadTexture("texture.png"); // Load texture from file effect->SetTexture(textureHandle, texture); effect->Begin(NULL, NULL); effect->BeginPass(0); mesh->DrawSubset(subset); effect->EndPass(); effect->End(); texture->Release();This example loads a shader file called “textured.fx” that applies a texture map to the 3D mesh. It uses the “Texture” parameter defined in the shader to apply the texture loaded from a file using LoadTexture function. Based on the naming convention used and the API used, this code is likely based on the DirectX 9 package library.