Ground 생성자 와 Render 함수
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 | Ground::Ground( int _row, int _col, float _size ) { m_iCol = _col; m_iRow = _row; m_dwVertices = (m_iCol+1) * (m_iRow+1); m_dwIndices = m_iCol * m_iRow * 6; GROUNDVERTEX* pGroundVertex = new GROUNDVERTEX[m_dwVertices]; int Index = 0; Vector3 pos(-1.f * m_iCol * _size * 0.5f, 0, m_iRow * _size * 0.5f); for(int z = 0; z <= m_iRow; z++) { for (int x = 0; x <= m_iCol; x++) { pGroundVertex[Index].Position.x = pos.x + (_size * x); pGroundVertex[Index].Position.z = pos.z + -1.f * (_size * z); pGroundVertex[Index].Diffuse = D3DCOLOR_ARGB(255, 50, 50, 50); Index++; } } m_pDevice->CreateVertexBuffer(sizeof(GROUNDVERTEX)*m_dwVertices, 0, D3DFVF_GROUNDVERTEX, D3DPOOL_DEFAULT, &m_pVB, NULL); void* pVertices; m_pVB->Lock(0, 0, &pVertices, NULL); memcpy(pVertices, pGroundVertex, sizeof(GROUNDVERTEX)*m_dwVertices); m_pVB->Unlock(); WORD* pIndex = new WORD[m_dwIndices]; Index = 0; for(int z = 0; z < m_iRow; z++) { for(int x = 0; x < m_iCol; x++) { pIndex[Index++] = WORD(z * (m_iCol + 1) + x); pIndex[Index++] = WORD((z +1) * (m_iCol + 1) + x + 1); pIndex[Index++] = WORD((z +1) * (m_iCol + 1) + x); pIndex[Index++] = WORD(z * (m_iCol + 1) + x); pIndex[Index++] = WORD(z * (m_iCol + 1) + x + 1); pIndex[Index++] = WORD((z +1) * (m_iCol + 1) + x + 1); } } m_pDevice->CreateIndexBuffer(sizeof(WORD)*m_dwIndices, 0, D3DFMT_INDEX16, D3DPOOL_DEFAULT, &m_pIB, NULL); void* pIndeices; m_pIB->Lock(0, 0, &pIndeices, NULL); memcpy(pIndeices, pIndex, sizeof(WORD)*m_dwIndices); m_pIB->Unlock(); delete[] pGroundVertex; delete[] pIndex; } | cs |
결과 화면
아직 버텍스 버퍼와 인덱스 버퍼가 익숙치 않다.
익숙해지려면 좀 더 많이 만들어 봐야겠다.
알록 달록 하구먼 ㅋㅋㅋ
반응형
'Programming > DirectX' 카테고리의 다른 글
SkyBox 만들어보기 (0) | 2016.08.04 |
---|---|
메쉬를 불러와 출력 해보기 (1) | 2016.07.06 |
텍스쳐 출력 해보기 (0) | 2016.07.05 |
머티리얼 & 라이트 & 법선벡터 (0) | 2016.07.03 |
행렬을 이용한 회전 연습 (0) | 2016.07.01 |
버텍스를 이용해 폴리곤 띠우기 (0) | 2016.06.27 |
fatal error C1859: 'pch' 컴파일 에러 (0) | 2016.03.25 |
3장. Direct3D에서의 드로잉 (0) | 2016.01.12 |