   Bigginer need help from experts
  hi! i am new in D3D8 programming , i have created one square and triangle inside the 3D world but its not working, while i didnt find any error in code or in any place couldnt any one see and tell me what i am doing wrong in it??? it just shows me black screen with no drawing...   #include<windows.h>#include<windowsx.h>#include<d3d8.h>#include<d3dx8.h>#include<stdio.h>#define KEY_UP(vk_code) ((GetAsyncKeyState(vk_code)& 0x8000)?1:0)#define SafeRelease(pObject) if(pObject != NULL) {pObject->Release(); pObject=NULL;}//include dxguid.lib  d3d8.lib  d3dx8.libWNDCLASSEX winclass;    HWND hwnd=NULL;MSG msg;//Direct3d stuff    LPDIRECT3D8 lpd3d=NULL;LPDIRECT3DDEVICE8 dDevice;D3DDISPLAYMODE d3ddm;    D3DPRESENT_PARAMETERS d3dpp;    LPDIRECT3DVERTEXBUFFER8 verbuff;D3DXMATRIX world,view,projection;struct farhan{    FLOAT x,y,z;DWORD colour;};//you should add dxguid.lib and ddraw.h in project :@LRESULT CALLBACK WindowProc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam){switch(msg){case WM_CREATE:{//do initialization stuff here//return successreturn(0);}break;case WM_PAINT:{//return successreturn(0);}break;case WM_DESTROY:{//kill the application,this sends a WM_QUIT messagePostQuitMessage(0);//return successreturn(0);}break;   case WM_KEYDOWN:{int vcode=LOWORD(wparam);} break;default:break;}//END SWITCHreturn DefWindowProc(hwnd,msg,wparam,lparam);}int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine, int nShowCmd){    //my first direct draw's object//Stupid windows structure first fill in the window class structurewinclass.cbSize =sizeof(WNDCLASSEX);winclass.style =CS_DBLCLKS |CS_OWNDC |CS_HREDRAW |CS_VREDRAW;winclass.lpfnWndProc =WindowProc;winclass.cbClsExtra =0;winclass.cbWndExtra =0;winclass.hInstance =hInstance;winclass.hIcon =LoadIcon(NULL,IDI_APPLICATION);winclass.hCursor =LoadCursor(NULL,IDC_ARROW);winclass.hbrBackground =(HBRUSH) GetStockObject(BLACK_BRUSH);winclass.lpszMenuName =NULL;winclass.lpszClassName ="Farhan Class";winclass.hIconSm =LoadIcon(NULL,IDI_APPLICATION);//////////////////////////////////////////////////////////////////Step 1 register windowsif(!(RegisterClassEx(&winclass))){MessageBox(hwnd,"YOUR REGISTER CLASS HAS PROBLEM","WARN",MB_OK);return 0;}//////////////////////////////////////////////////////////////////////create the window,bail if problemif (!(hwnd =CreateWindowEx(NULL,//extended style"Farhan Class",//class"Your Basic Window ",//titleWS_POPUP//WS_OVERLAPPEDWINDOW |WS_VISIBLE,0,0,//initial x,y640,480,//initial width,heightNULL,//handle to parentNULL,//handle to menuhInstance,//instance of this applicationNULL)))//extra creation parms{MessageBox(hwnd,"YOUR Creating CLASS HAS PROBLEM","WARN",MB_OK);return(0);}///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////   D3D INITIALIZATION///////////////////////////////////////////////////////////////////if(FAILED(lpd3d=Direct3DCreate8(D3D_SDK_VERSION))){return 0;}if(FAILED(lpd3d->GetAdapterDisplayMode(D3DADAPTER_DEFAULT,&d3ddm))){return 0;}//d3dpp.Windowed=TRUE;//d3dpp.SwapEffect=D3DSWAPEFFECT_COPY_VSYNC;//d3dpp.BackBufferFormat=d3ddm.Format;   ZeroMemory(&d3dpp,sizeof(d3dpp));   //Whether we're full-screen or windowed these are the same.   d3dpp.SwapEffect= D3DSWAPEFFECT_DISCARD; // Throw away previous frames, we don't need them   d3dpp.hDeviceWindow  = hwnd;  //This is our main (and only) window  d3dpp.Windowed=FALSE;d3dpp.BackBufferWidth=640;d3dpp.BackBufferHeight=480;d3dpp.BackBufferFormat=D3DFMT_R5G6B5;/*   if(SUCCEEDED(lpd3d->CheckDeviceType(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,D3DFMT_R5G6B5,D3DFMT_R5G6B5,FALSE))){ MessageBox(hwnd,"RGB device HAS PROBLEM","WARN",MB_OK); return 0;   }*/if(lpd3d->CreateDevice(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,hwnd,  D3DCREATE_SOFTWARE_VERTEXPROCESSING,&d3dpp,&dDevice)){ //MessageBox(hwnd,"YOUR device HAS PROBLEM","WARN",MB_OK);return 0;}//////////////////////////////////////////////////////////////////////////we are creating an array of our own structure actully it is a vertex bufferfarhan triangleSquarework[]={{  0.0f,  1.0f, 0.0f, 0x00FF0000 }, // x, y, z, color   {  1.0f, -1.0f, 0.0f, 0x0000FF00 },   { -1.0f, -1.0f, 0.0f, 0x000000FF },   { -1.0f, -1.0f, 0.0f, 0x000000FF },   { -1.0f,  1.0f, 0.0f, 0x000000FF },   {  1.0f, -1.0f, 0.0f, 0x000000FF },   {  1.0f,  1.0f, 0.0f, 0x000000FF }}; dDevice->SetRenderState(D3DRS_LIGHTING,FALSE);if(FAILED(dDevice->CreateVertexBuffer(7*sizeof(farhan),D3DUSAGE_WRITEONLY   ,D3DFVF_XYZRHW|D3DFVF_DIFFUSE,D3DPOOL_MANAGED,&verbuff))){return 0;}///Set the camera//////////////////////////////if(FAILED(D3DXMatrixLookAtLH(&view, &D3DXVECTOR3(0.0f,0.0f,-8.0f),&D3DXVECTOR3(0.0f,0.0f,0.0f), &D3DXVECTOR3(0.0f,1.0f,0.0f)))) { return 0;}if(FAILED(dDevice->SetTransform(D3DTS_VIEW,&view))){return 0;}////////////////////////////////////////////////////////Set the Projection ////////////////D3DXMatrixPerspectiveFovLH(&projection,D3DX_PI/4,float(640)/float(480),1.0f,100.0f);dDevice->SetTransform(D3DTS_PROJECTION,&projection);//////////////////////////////////////////////////////////unsigned char *pVertices;    //Get a pointer to the vertex buffer vertices and lock the vertex bufferif(FAILED(verbuff->Lock(0,0,&pVertices, 0)))    {   return 0;    }    //Copy our stored vertices values into the vertex buffer    memcpy(pVertices,triangleSquarework, sizeof(triangleSquarework));    //Unlock the vertex bufferverbuff->Unlock();while(TRUE){dDevice->Clear(0,0,D3DCLEAR_TARGET,D3DCOLOR_XRGB(0,0,0),1.0f,0);//Now clear the backbuffer with rgb colours if(SUCCEEDED(dDevice->BeginScene())){dDevice->SetVertexShader(D3DFVF_XYZRHW|D3DFVF_DIFFUSE);dDevice->SetStreamSource(0,verbuff, sizeof(farhan));D3DXMatrixTranslation(&world,-1.0,0.0f,0.0f);dDevice->SetTransform(D3DTS_WORLD,&world);dDevice->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 1);//dDevice->SetStreamSource(0,verbuff, sizeof(farhan));D3DXMatrixTranslation(&world,1.0,0.0f,0.0f);dDevice->SetTransform(D3DTS_WORLD,&world);dDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 3, 2);dDevice->EndScene();    }else {return 0;}dDevice->Present(0,0,0,0);//now display the backbuffer on screen//clean up the whole memoryif(PeekMessage(&msg,NULL,0,0,PM_REMOVE)){if (msg.message ==WM_QUIT)break;//translate any accelerator keysif(KEY_UP(VK_ESCAPE))//MessageBox(NULL,"HEY YOU","WHAT",MB_OK);break;TranslateMessage(&msg);//send the message to the window procDispatchMessage(&msg);}}verbuff->Release();verbuff=NULL;dDevice->Release();dDevice=NULL;lpd3d->Release();lpd3d=NULL;return 0;}[edited by - Superpig on February 15, 2004 8:38:28 AM]
  Well, for one thing, that D3DFVF_XYZRHW should just D3DFVF_XYZ. ;  Thanks alot!!!!! it was small thing that i was forget to remove rhw 