   Little help here. (Beginner)
  Hello, I have just started learning DirectX 9 and I have a small problem. Ok, I am trying to create a pyramid and then rotate it. Here's the code:#include <windows.h>#include <d3d9.h>#include <d3dx9.h>#pragma comment (lib, "d3d9.lib")#pragma comment (lib, "d3dx9.lib")#define CUSTFVF (D3DFVF_XYZ)struct ThreeDVertices {float x, y, z;};const char WndCN[] = "DXTEST1WCN";HWND Mhwnd;LPDIRECT3D9 d3d9;LPDIRECT3DDEVICE9 d3dDevice;IDirect3DVertexBuffer9* vBuff;IDirect3DIndexBuffer9* iBuff;unsigned short int rDegree = 0;void initD3D();void renderFrames();void CleanUp();void CGraph();LRESULT CALLBACK WndProc(HWND hwnd, UINT msG, WPARAM wParam, LPARAM lParam) {switch (msG) {case WM_KEYUP:if (LOWORD(wParam) == VK_ESCAPE) DestroyWindow(hwnd);break;case WM_DESTROY:PostQuitMessage(0);break;default:return DefWindowProc(hwnd, msG, wParam, lParam);}return 0;}int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) {MSG Msg;WNDCLASS wC;ZeroMemory(&wC, sizeof(wC));wC.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);wC.hCursor = LoadCursor(NULL, IDC_ARROW);wC.hIcon = LoadIcon(NULL, IDI_APPLICATION);wC.hInstance = hInstance;wC.lpfnWndProc = WndProc;wC.lpszClassName = WndCN;wC.style = 0;if (!RegisterClass(&wC)) {MessageBox(NULL, "Error Registering Window", "Error", MB_ICONERROR);return 0;}Mhwnd = CreateWindow(WndCN, NULL, WS_POPUP, 0, 0, 1024, 768, NULL, NULL, hInstance, NULL);if (Mhwnd == NULL) {MessageBox(NULL, "Error Creating Window", "Error", MB_ICONERROR);return 0;}ShowWindow(Mhwnd, nShowCmd);UpdateWindow(Mhwnd);initD3D();CGraph();while(TRUE) {while (PeekMessage(&Msg, NULL, 0, 0, PM_REMOVE)) {TranslateMessage(&Msg);DispatchMessage(&Msg);}if (Msg.message == WM_QUIT) break;renderFrames();}CleanUp();return 0;}void initD3D() {D3DPRESENT_PARAMETERS d3dInfo;ZeroMemory(&d3dInfo, sizeof(d3dInfo));d3dInfo.BackBufferCount = 1;d3dInfo.BackBufferFormat = D3DFMT_X8R8G8B8;d3dInfo.BackBufferHeight = 768;d3dInfo.BackBufferWidth = 1024;d3dInfo.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT;d3dInfo.hDeviceWindow = Mhwnd;d3dInfo.PresentationInterval = D3DPRESENT_RATE_DEFAULT;d3dInfo.SwapEffect = D3DSWAPEFFECT_DISCARD;d3dInfo.Windowed = FALSE;d3d9 = Direct3DCreate9(D3D_SDK_VERSION);D3DCAPS9 d3dCaps;d3d9->GetDeviceCaps(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, &d3dCaps);int vP;if (d3dCaps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT)vP = D3DCREATE_HARDWARE_VERTEXPROCESSING;elsevP = D3DCREATE_SOFTWARE_VERTEXPROCESSING;d3d9->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, Mhwnd, vP, &d3dInfo, &d3dDevice);d3dDevice->CreateVertexBuffer(5 * sizeof(ThreeDVertices), 0, CUSTFVF, D3DPOOL_MANAGED, &vBuff, NULL);d3dDevice->CreateIndexBuffer(18 * sizeof(WORD), 0, D3DFMT_INDEX16, D3DPOOL_MANAGED, &iBuff, NULL);}void renderFrames() {D3DXMATRIX Rx, Ry;if (rDegree < 360)rDegree++;else rDegree = 1;D3DXMatrixRotationX(&Rx, rDegree * (D3DX_PI / 180));D3DXMatrixRotationY(&Ry, rDegree * (D3DX_PI / 180));Rx *= Ry;d3dDevice->SetTransform(D3DTS_WORLD, &Rx);d3dDevice->Clear(0, 0, D3DCLEAR_TARGET, 0xFFFFFFFF, 1, 0);d3dDevice->BeginScene();d3dDevice->SetFVF(CUSTFVF);d3dDevice->SetStreamSource(0, vBuff, 0, sizeof(ThreeDVertices));d3dDevice->SetIndices(iBuff);d3dDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, 5, 0, 6);d3dDevice->EndScene();d3dDevice->Present(NULL, NULL, NULL, NULL);}void CleanUp() {vBuff->Release();iBuff->Release();d3d9->Release();d3dDevice->Release();}void CGraph() {ThreeDVertices PyramidV[5] = {{-1, -1, -1},{-1, 1, -1},{1, 1, -1},{1, -1, -1},{0, 0, 1}};void* pVData;vBuff->Lock(0, 0, &pVData, 0);memcpy(pVData, PyramidV, sizeof(PyramidV));vBuff->Unlock();WORD* pIData = 0;iBuff->Lock(0, 0, (void**)&pIData, 0);pIData[0] = 0; pIData[1] = 1; pIData[2] = 2;pIData[3] = 0; pIData[4] = 2; pIData[5] = 3;pIData[6] = 4; pIData[7] = 1; pIData[8] = 0;pIData[9] = 3; pIData[10] = 2; pIData[11] = 0;pIData[12] = 1; pIData[13] = 2; pIData[14] = 4;pIData[15] = 0; pIData[16] = 3; pIData[17] = 4;iBuff->Unlock();D3DXVECTOR3 CPos(0, 0, -5);D3DXVECTOR3 CAt(0, 0, 0);D3DXVECTOR3 CUp(0, 1, 0);D3DXMATRIX COut;D3DXMatrixLookAtLH(&COut, &CPos, &CAt, &CUp);d3dDevice->SetTransform(D3DTS_VIEW, &COut);D3DXMATRIX pProj;D3DXMatrixPerspectiveFovLH(&pProj, D3DX_PI * 0.5, 1024 / 768, 1, 1000);d3dDevice->SetTransform(D3DTS_PROJECTION, &pProj);d3dDevice->SetRenderState(D3DRS_FILLMODE, D3DFILL_WIREFRAME);}Now the problem is that, some of the vertices, or should I say edges, disappear and then reappear while rotatating. Can someone explain to me why? Compile it and run, it runs ok but edges disappear and reappear. Please help. Thanks!   
  Some faces were being culled. Add this guy after you create your buffers to see the mesh in it's entirety.d3dDevice->SetRenderState(D3DRS_CULLMODE,D3DCULL_NONE);When a face is oriented away from the camera, it is not rendered. Since you were drawing a wireframe, you saw this happen. If the faces were shaded in, you would not have noticed.Your code is fine, but don't turn off culling unless you have a good reason to!   ;  That works perfect. Thank you so much!!! :)   