SetVertexShader DX8 - DX9 Conversion query

Started by
1 comment, last by Sir_Spritely 21 years, 2 months ago
I''m trying to convert a DX8 program to DX9 however I have hit a snag early on with the SetVertexShader and SetVertexShaderConstant functions. Here is the segment of code I''m using,
  
//Create the concatenated transfotmation matrix

	D3DXMATRIX ShaderMatrix = m_matPosition * 
		                  m_matView * m_matProj;

//Get the transpose

D3DXMatrixTranspose(&ShaderMatrix, &ShaderMatrix);

//Pass the transposed matrix to the shader

m_pd3dDevice->SetVertexShaderConstant(0, &ShaderMatrix, 4);

//The various wave parameters for the sine shader. 

//The first value is the phase, 

//the second value alters the wavelength. The third value is

//the amplitude and the last value helps to bias the color.

D3DXVECTOR4 Wave((float)GetTickCount() / 100.0f, 0.25f, 3.0f, 0.1f);
 m_pd3dDevice->SetVertexShaderConstant(4, &Wave, 1);

//These are the values for the scaling shader. 

//The first value is an oscillating value.

float ScaleFactor = 3.0f * sinf((float)GetTickCount() / 1000.0f);
D3DXVECTOR4 Scale(ScaleFactor, ScaleFactor, ScaleFactor, 1.0f); 
m_pd3dDevice->SetVertexShaderConstant(5, &Scale, 1);
	
//Decide which shader

if (!m_WhichShader)
	m_pd3dDevice->SetVertexShader(m_SineShaderHandle);
else
	m_pd3dDevice->SetVertexShader(m_ScaleShaderHandle);

m_pd3dDevice->SetStreamSource(0, m_pMeshVertexBuffer, 0, sizeof(MESH_VERTEX));
m_pd3dDevice->SetIndices(m_pMeshIndexBuffer);

m_pd3dDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, 
						
m_pMesh->GetNumVertices(), 0,
							
m_pMesh->GetNumFaces());
  
I realised that SetVertexShaderConstant was no more so I change the function name to SetVertexShaderConstantF but still came up with errors. The errors from the above code are, C:\Program Files\Microsoft Visual Studio\MyProjects\VertexShader\Application.cpp(117) : error C2664: ''SetVertexShaderConstantF'' : cannot convert parameter 2 from ''struct D3DXMATRIX *'' to ''const float *'' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast C:\Program Files\Microsoft Visual Studio\MyProjects\VertexShader\Application.cpp(124) : error C2039: ''SetVertexShaderConstant'' : is not a member of ''IDirect3DDevice9'' c:\sdks\directx9.0\include\d3d9.h(318) : see declaration of ''IDirect3DDevice9'' C:\Program Files\Microsoft Visual Studio\MyProjects\VertexShader\Application.cpp(130) : error C2039: ''SetVertexShaderConstant'' : is not a member of ''IDirect3DDevice9'' c:\sdks\directx9.0\include\d3d9.h(318) : see declaration of ''IDirect3DDevice9'' C:\Program Files\Microsoft Visual Studio\MyProjects\VertexShader\Application.cpp(134) : error C2664: ''SetVertexShader'' : cannot convert parameter 1 from ''unsigned long'' to ''struct IDirect3DVertexShader9 *'' Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast C:\Program Files\Microsoft Visual Studio\MyProjects\VertexShader\Application.cpp(136) : error C2664: ''SetVertexShader'' : cannot convert parameter 1 from ''unsigned long'' to ''struct IDirect3DVertexShader9 *'' Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast I''ve read the SDK and checked MSDN but I''m still struggling I was wondering if someone could explain the changes needed in plain English for me. Thanks, Paul.
Advertisement
BUMP
the first error says parameter 2 of the call to SetVertexShaderConstantF() is incorrect.

so you go to your dx docs and check what parameter 2 is.
it appears your passing it a D3DXMATRIX* and it wants a const float*.

the second and third errors exist because SetVertexShaderConstant() does not exist.

and for the last two errors you are passing it the incorrect type. you may want SetFVF() instead. if you do want to use SetVertexShader() you will need to pass it IDirect3DVertexShader9*

This topic is closed to new replies.

Advertisement