Bonjour,
je suis en train de suivre les tutoriels de programmation directX du site: http://www.rastertek.com/
Ils sont vraiment très bien fait mais ils ne sont pas prévu pour les dernières montures de Windows, Visual et DirectX.
Dans la partie qui introduit les shaders et le HLSL, l'auteur du tuto utilise des bibliothèques qui ne sont plus présentes et je doit, j'essaye d'adapter le code.
En l’occurrence, d3d10math.h n'est plus; Vive DirectXMath.h.
La transposition du code n'est pas très compliqué vu que MS fournit une table de conversion sur msdn. Cependant malgré que mon code compile nickel, que le programme s’exécute sans erreur, qu'il se termine proprement, je n'arrive pas à afficher ce p***** de triangle vert. Je bloque .
Voici les parties modifiées par mes soins:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43 void CameraClass::Render() { XMFLOAT3 up, position, lookAt; float yaw, pitch, roll; XMMATRIX rotationMatrix; // Setup the vector that points upwards. up.x = 0.0f; up.y = 1.0f; up.z = 0.0f; // Setup the position of the camera in the world. position.x = m_positionX; position.y = m_positionY; position.z = m_positionZ; // Setup where the camera is looking by default. lookAt.x = 0.0f; lookAt.y = 0.0f; lookAt.z = 1.0f; // Set the yaw (Y axis), pitch (X axis), and roll (Z axis) rotations in radians. pitch = m_rotationX * 0.0174532925f; yaw = m_rotationY * 0.0174532925f; roll = m_rotationZ * 0.0174532925f; // Create the rotation matrix from the yaw, pitch, and roll values. rotationMatrix = XMMatrixRotationRollPitchYaw(pitch, yaw, roll); // Transform the lookAt and up vector by the rotation matrix so the view is correctly rotated at the origin. XMVector3TransformCoord(XMLoadFloat3(&lookAt), rotationMatrix); XMVector3TransformCoord(XMLoadFloat3(&up), rotationMatrix); // Translate the rotated camera position to the location of the viewer. XMStoreFloat3(&lookAt,(XMLoadFloat3(&position) + XMLoadFloat3(&lookAt))); // Finally create the view matrix from the three updated vectors. m_viewMatrix = XMMatrixLookAtLH(XMLoadFloat3(&position), XMLoadFloat3(&lookAt), XMLoadFloat3(&up)); . . . return;
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69 bool ColorShaderClass::InitializeShader(ID3D11Device* device, HWND hwnd, WCHAR* vsFilename, WCHAR* psFilename) { HRESULT result; ID3DBlob* errorMessage; ID3DBlob* vertexShaderBuffer; ID3DBlob* pixelShaderBuffer; D3D11_INPUT_ELEMENT_DESC polygonLayout[2]; unsigned int numElements; D3D11_BUFFER_DESC matrixBufferDesc; // Initialize the pointers this function will use to null. errorMessage = 0; vertexShaderBuffer = 0; pixelShaderBuffer = 0; UINT flags = D3DCOMPILE_ENABLE_STRICTNESS; #if defined( DEBUG ) || defined( _DEBUG ) flags |= D3DCOMPILE_DEBUG; #endif const D3D_SHADER_MACRO defines[] = { "EXAMPLE_DEFINE", "1", NULL, NULL }; // Compile the vertex shader code. result = D3DCompileFromFile(vsFilename, defines, D3D_COMPILE_STANDARD_FILE_INCLUDE, "main", "vs_5_0", flags , 0, &vertexShaderBuffer, &errorMessage); if(FAILED(result)) { // If the shader failed to compile it should have writen something to the error message. if(errorMessage) { OutputShaderErrorMessage(errorMessage, hwnd, vsFilename); } // If there was nothing in the error message then it simply could not find the shader file itself. else { MessageBox(hwnd, (LPCSTR)vsFilename, "Missing Shader File", MB_OK); } return false; } // Compile the pixel shader code. result = D3DCompileFromFile(psFilename, defines, D3D_COMPILE_STANDARD_FILE_INCLUDE, "main", "ps_5_0", flags, 0, &pixelShaderBuffer, &errorMessage); if(FAILED(result)) { // If the shader failed to compile it should have writen something to the error message. if(errorMessage) { OutputShaderErrorMessage(errorMessage, hwnd, psFilename); } // If there was nothing in the error message then it simply could not find the file itself. else { MessageBox(hwnd, (LPCSTR)psFilename, "Missing Shader File", MB_OK); } return false; } . . . return true; }Si quelqu'un a déjà ou est en train de faire la même migration que moi ou que vous avez une idée sur ce qui plante je suis preneur.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 bool ColorShaderClass::SetShaderParameters(ID3D11DeviceContext* deviceContext, XMMATRIX& worldMatrix, XMMATRIX& viewMatrix, XMMATRIX& projectionMatrix) { HRESULT result; D3D11_MAPPED_SUBRESOURCE mappedResource; MatrixBufferType* dataPtr; unsigned int bufferNumber; // Transpose the matrices to prepare them for the shader. worldMatrix = XMMatrixTranspose(worldMatrix); viewMatrix = XMMatrixTranspose(viewMatrix); projectionMatrix = XMMatrixTranspose(projectionMatrix); . . . return true; }
D'avance merci.
Erreur trouvée: Je réinitialisé le buffer après l'avoir paramétré . Shame on me!!
Par contre pour ceux qui veulent migrer leur code Dx10 vers Dx11 version VS2012, mon code fonctionne.
Partager