Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!
Werbeanzeige
C-/C++-Quelltext |
|
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 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
bool ModelClass::InitializeBuffers(ID3D11Device* device) { VertexType* vertices; unsigned long* indices; D3D11_BUFFER_DESC vertexBufferDesc, indexBufferDesc; D3D11_SUBRESOURCE_DATA vertexData, indexData; HRESULT result; // Set the number of vertices in the vertex array. m_vertexCount = 6; // Set the number of indices in the index array. m_indexCount = 6; // Create the vertex array. vertices = new VertexType[m_vertexCount]; if (!vertices) { return false; } // Create the index array. indices = new unsigned long[m_indexCount]; if (!indices) { return false; } // Load the vertex array with data. vertices[0].position = D3DXVECTOR3(-1.0f, -1.0f, 0.0f); // Bottom left. vertices[0].texture = D3DXVECTOR2(0.0f, 1.0f); vertices[1].position = D3DXVECTOR3(1.0f, 1.0f, 0.0f); // Top left. vertices[1].texture = D3DXVECTOR2(-1.0f, 0.0f); vertices[2].position = D3DXVECTOR3(1.0f, 1.0f, 0.0f); // Top right. vertices[2].texture = D3DXVECTOR2(1.0f, 0.0f); vertices[3].position = D3DXVECTOR3(-1.0f, -1.0f, 0.0f); // Bottom left. vertices[3].texture = D3DXVECTOR2(0.0f, 1.0f); vertices[4].position = D3DXVECTOR3(1.0f, 1.0f, 0.0f); // Top right. vertices[4].texture = D3DXVECTOR2(1.0f, 1.0f); vertices[5].position = D3DXVECTOR3(1.0f, -1.0f, 0.0f); // Bottom right. vertices[5].texture = D3DXVECTOR2(0.0f, 1.0f); // Load the index array with data. indices[0] = 0; // Bottom left. indices[1] = 1; // Top left. indices[2] = 2; // Top right. indices[3] = 3; // Bottom left. indices[4] = 4; // Top right. indices[5] = 5; // Bottom right. // Set up the description of the static vertex buffer. vertexBufferDesc.Usage = D3D11_USAGE_DEFAULT; vertexBufferDesc.ByteWidth = sizeof(VertexType) * m_vertexCount; vertexBufferDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER; vertexBufferDesc.CPUAccessFlags = 0; vertexBufferDesc.MiscFlags = 0; vertexBufferDesc.StructureByteStride = 0; // Give the subresource structure a pointer to the vertex data. vertexData.pSysMem = vertices; vertexData.SysMemPitch = 0; vertexData.SysMemSlicePitch = 0; // Now create the vertex buffer. result = device->CreateBuffer(&vertexBufferDesc, &vertexData, &m_vertexBuffer); if (FAILED(result)) { return false; } // Set up the description of the static index buffer. indexBufferDesc.Usage = D3D11_USAGE_DEFAULT; indexBufferDesc.ByteWidth = sizeof(unsigned long) * m_indexCount; indexBufferDesc.BindFlags = D3D11_BIND_INDEX_BUFFER; indexBufferDesc.CPUAccessFlags = 0; indexBufferDesc.MiscFlags = 0; indexBufferDesc.StructureByteStride = 0; // Give the subresource structure a pointer to the index data. indexData.pSysMem = indices; indexData.SysMemPitch = 0; indexData.SysMemSlicePitch = 0; // Create the index buffer. result = device->CreateBuffer(&indexBufferDesc, &indexData, &m_indexBuffer); if (FAILED(result)) { return false; } // Release the arrays now that the vertex and index buffers have been created and loaded. delete[] vertices; vertices = 0; delete[] indices; indices = 0; return true; } |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
void ModelClass::RenderBuffers(ID3D11DeviceContext* deviceContext) { unsigned int stride; unsigned int offset; // Set vertex buffer stride and offset. stride = sizeof(VertexType); offset = 0; // Set the vertex buffer to active in the input assembler so it can be rendered. deviceContext->IASetVertexBuffers(0, 1, &m_vertexBuffer, &stride, &offset); // Set the index buffer to active in the input assembler so it can be rendered. deviceContext->IASetIndexBuffer(m_indexBuffer, DXGI_FORMAT_R32_UINT, 0); // Set the type of primitive that should be rendered from this vertex buffer, in this case triangles. deviceContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); return; } |
Dein "Top Left" ist nicht top left und wofür Indices, wenn du eh keinen Vertex wiederverwendest?
Alter Hase
Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von »Julién« (24.05.2016, 12:00) aus folgendem Grund: Ich bräuchte einen Lektor.
Alter Hase
Dieser Beitrag wurde bereits 3 mal editiert, zuletzt von »Julién« (24.05.2016, 15:05)
Das Buch von David bezieht sich nur auf DirectX 9, aber wie bereits gesagt, werden dort die Grundlagen besprochen.
Um die Grundlagen kommt bei DirectX/OpenGL/Vulkan/GCM/XNA(?) keiner rum.
Administrator
Vielleicht wird es Zeit für eine Neuauflage Mr. Scherfgen?
Werbeanzeige