Original Post
Hi. I bought the "Programming Role Playing Games with Dx 2nd edition" book and i found problems with its code. Well. i started reading the book and a new project in MSVC so i could follow the book. I copied all the code in the book to make a single polygon to appear, but i have`t got results. There is also a problem, the book has some undeclared variables and things that you never know what do they do, its strange, so i need you to help me with this please. My code is this: /*Main DirectX objects*/ IDirect3D9 *d3dobj; D3DDISPLAYMODE d3ddm; D3DPRESENT_PARAMETERS d3dpp; IDirect3DDevice9 *d3ddev; IDirect3DVertexBuffer9 *d3dvb=NULL; unsigned char *ptr; D3DXMATRIX matWorld, matView, matProj; D3DXMATRIX matRotX, matRotY, matRotZ; D3DXMATRIX matTrans; D3DXMATRIX matScale; D3DMATERIAL9 d3dm; typedef struct { FLOAT x, y, z; D3DCOLOR diffuse; }sVertex; #define VertexFVF (D3DFVF_XYZ | D3DFVF_DIFFUSE) sVertex Verts[4]={ {-100.0f, 100.0f, 100.0f, D3DCOLOR_RGBA(255, 255, 255, 255)}, {100.0f, 100.0f, 100.0f, D3DCOLOR_RGBA(255, 0, 0, 255) }, {100.0f, -100.0f, 100.0f, D3DCOLOR_RGBA(0, 255, 0, 255) }, {-100.0f, -100.0f, 100.0f, D3DCOLOR_RGBA(0, 0, 255, 255) } }; d3dobj=Direct3DCreate9(D3D_SDK_VERSION);//Create the object d3ddm.Width=640;//width d3ddm.Height=480;//height d3ddm.RefreshRate=0;//default refresh rate d3ddm.Format=D3DFMT_R5G6B5;//16 bits if(FAILED(d3dobj->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &d3ddm))) MessageBox(hwnd, "GetAdapterDisplay", "x", MB_OK);//Get the display mode ZeroMemory(&d3dpp, sizeof(D3DPRESENT_PARAMETERS));//Reset all memory d3dpp.Windowed=FALSE;//Windowed mode d3dpp.SwapEffect=D3DSWAPEFFECT_DISCARD;//no swap effect d3dpp.BackBufferFormat=d3ddm.Format;//16bits d3dpp.BackBufferWidth=640;//back buffer d3dpp.BackBufferHeight=480; if(FAILED(d3dobj->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &d3ddev))) MessageBox(hwnd, "Create Device", "", MB_OK); //d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,255,255), 1.0f, 0); if(FAILED(d3ddev->CreateVertexBuffer(sizeof(sVertex)*4, 0, VertexFVF, D3DPOOL_MANAGED, &d3dvb, NULL))) MessageBox(hwnd, "VertexBuffer", "", MB_OK); if(SUCCEEDED(d3dvb->Lock(0, 0, (void**)&ptr, 0))) { memcpy(ptr, Verts, sizeof(Verts)); d3dvb->Unlock(); } if(FAILED(d3ddev->SetStreamSource(0, d3dvb, 0, sizeof(sVertex)))) MessageBox(hwnd, "SetStrem Source", "", MB_OK); if(FAILED(d3ddev->SetFVF(VertexFVF))) MessageBox(hwnd, "FVF", "", MB_OK); D3DXMatrixRotationX(&matRotX, 0); D3DXMatrixRotationY(&matRotY, 0); D3DXMatrixRotationZ(&matRotZ, 0); D3DXMatrixTranslation(&matTrans, 1.0f, 1.0f, 1.0f); D3DXMatrixScaling(&matScale, 1.0f, 1.0f, 1.0f); D3DXMatrixIdentity(&matWorld); D3DXMatrixMultiply(&matWorld, &matWorld, &matScale); D3DXMatrixMultiply(&matWorld, &matWorld, &matRotX); D3DXMatrixMultiply(&matWorld, &matWorld, &matRotY); D3DXMatrixMultiply(&matWorld, &matWorld, &matRotZ); D3DXMatrixMultiply(&matWorld, &matWorld, &matTrans); d3ddev->SetTransform(D3DTS_WORLD, &matWorld); D3DXMatrixRotationX(&matRotX, 0); D3DXMatrixRotationY(&matRotY, 0); D3DXMatrixRotationZ(&matRotZ, 0); D3DXMatrixTranslation(&matTrans, -1, -1, -1); D3DXMatrixIdentity(&matView); D3DXMatrixMultiply(&matView, &matView, &matTrans); D3DXMatrixMultiply(&matView, &matView, &matRotZ); D3DXMatrixMultiply(&matView, &matView, &matRotY); D3DXMatrixMultiply(&matView, &matView, &matRotX); d3ddev->SetTransform(D3DTS_VIEW, &matView); D3DXMatrixPerspectiveFovLH(&matProj, D3DX_PI/4, 640/480, 1.0f, 1000.0f); d3ddev->SetTransform(D3DTS_PROJECTION, &matProj); d3dm.Diffuse.r=d3dm.Ambient.r=1.0f; d3dm.Diffuse.g=d3dm.Ambient.g=1.0f; d3dm.Diffuse.b=d3dm.Ambient.b=0.0f; d3dm.Diffuse.a=d3dm.Ambient.a=1.0f; d3ddev->SetMaterial(&d3dm); d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,255,255), 1.0f, 0); //d3ddev->SetStreamSource(0, d3dvb, 0, sizeof(sVertex)); //d3ddev->SetFVF(VertexFVF); d3ddev->BeginScene(); d3ddev->DrawPrimitive(D3DPT_TRIANGLEFAN, 0, 1); d3ddev->Present( NULL, NULL, NULL, NULL ); d3ddev->EndScene(); I dont know what does it do at all, so i need someone to explain me, becuase the book has poor explanation of this....