void FSQuad::initVertexBuffer(ID3D11Device* currDevice) { mTotalIndices = 6; D3D11_BUFFER_DESC vBufferStruct, iBufferStruct; D3D11_SUBRESOURCE_DATA vertexData, indexData; vBufferStruct.Usage = D3D11_USAGE_DYNAMIC; vBufferStruct.ByteWidth = sizeof(basicVertex) * mTotalIndices; vBufferStruct.BindFlags = D3D11_BIND_VERTEX_BUFFER; vBufferStruct.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; vBufferStruct.MiscFlags = 0; basicVertex* vertexSet = new basicVertex[mTotalIndices]; int index = 0; /*for(int i = -1; i < 2; i += 2) { for(int j = -1; j < 2; j += 2) { vertexSet[index] = basicVertex(D3DXVECTOR3((float)i, (float)j, 0.0f), D3DXVECTOR2((float)i, (float)j), D3DXVECTOR2((float)i, (float)j)); index++; } }*/ vertexSet[5] = basicVertex(D3DXVECTOR3(-1.0f, -1.0f, 0.0f), D3DXVECTOR2(0.0f, 1.0f), D3DXVECTOR2(-1.0f, -1.0f)); vertexSet[4] = basicVertex(D3DXVECTOR3(1.0f, 1.0f, 0.0f), D3DXVECTOR2(1.0f, 0.0f), D3DXVECTOR2(1.0f, 1.0f)); vertexSet[3] = basicVertex(D3DXVECTOR3(-1.0f, 1.0f, 0.0f), D3DXVECTOR2(0.0f, 0.0f), D3DXVECTOR2(-1.0f, 1.0f)); vertexSet[2] = basicVertex(D3DXVECTOR3(-1.0f, -1.0f, 0.0f), D3DXVECTOR2(0.0f, 1.0f), D3DXVECTOR2(-1.0f, -1.0f)); vertexSet[1] = basicVertex(D3DXVECTOR3(1.0f, -1.0f, 0.0f), D3DXVECTOR2(1.0f, 1.0f), D3DXVECTOR2(1.0f, -1.0f)); vertexSet[0] = basicVertex(D3DXVECTOR3(1.0f, 1.0f, 0.0f), D3DXVECTOR2(1.0f, 0.0f), D3DXVECTOR2(1.0f, 1.0f)); vertexData.pSysMem = &vertexSet[0]; currDevice->CreateBuffer(&vBufferStruct, &vertexData, &mVBuffer); if(vertexSet) { delete [] vertexSet; vertexSet = 0; } iBufferStruct.Usage = D3D11_USAGE_IMMUTABLE; iBufferStruct.ByteWidth = sizeof(unsigned int) * mTotalIndices; iBufferStruct.BindFlags = D3D11_BIND_INDEX_BUFFER; iBufferStruct.CPUAccessFlags = 0; iBufferStruct.MiscFlags = 0; unsigned int indices[] = { 0, 1, 2, 1, 3, 2 }; indexData.pSysMem = &indices[0]; currDevice->CreateBuffer(&iBufferStruct, &indexData, &mIBuffer); }
bool SkyBox::createVertexBuffer(ID3D11Device* currDevice) { mTotalIndices = 36; D3D11_BUFFER_DESC vBufferStruct, iBufferStruct; D3D11_SUBRESOURCE_DATA vertexData, indexData; vBufferStruct.Usage = D3D11_USAGE_DYNAMIC; vBufferStruct.ByteWidth = sizeof(basicVertex) * mTotalIndices; vBufferStruct.BindFlags = D3D11_BIND_VERTEX_BUFFER; vBufferStruct.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; vBufferStruct.MiscFlags = 0; basicVertex* vertexSet = new basicVertex[mTotalIndices]; if(!vertexSet) { return false; } int index = 0; for(int i = -1; i < 2; i += 2) { for(int j = -1; j < 2; j += 2) { for(int k = -1; k < 2; k += 2) { vertexSet[index] = basicVertex(D3DXVECTOR3((float)i, (float)j, (float)k), D3DXVECTOR2((float)i, (float)j), D3DXVECTOR2((float)i, (float)j)); index++; } } } vertexData.pSysMem = &vertexSet[0]; currDevice->CreateBuffer(&vBufferStruct, &vertexData, &mVBuffer); if(!mVBuffer) { return false; } if(vertexSet) { delete [] vertexSet; vertexSet = 0; } iBufferStruct.Usage = D3D11_USAGE_IMMUTABLE; iBufferStruct.ByteWidth = sizeof(unsigned int) * mTotalIndices; iBufferStruct.BindFlags = D3D11_BIND_INDEX_BUFFER; iBufferStruct.CPUAccessFlags = 0; iBufferStruct.MiscFlags = 0; unsigned int indices[] = { 0, 2, 1, 2, 3, 1, // 0, 2, 4, 2, 6, 4, // 2, 3, 6, 3, 7, 6, // 0, 1, 4, 1, 5, 4, // 1, 3, 5, 3, 7, 5, // 4, 6, 5, 6, 7, 5 }; indexData.pSysMem = &indices[0]; currDevice->CreateBuffer(&iBufferStruct, &indexData, &mIBuffer); if(!mIBuffer) { return false; } return true; }