   trying to draw the vertex buffer line
  alot of code i know but i have been trying to learn index buffer and vertexbuffer and now i want to draw those points of the mesh with a LINELIST, do you guys see anything wrong because the line is apearing to the left of the screen.thanks for reading#include <windows.h>#include <windowsx.h>#include <d3d9.h>#include <d3dx9.h>#include <stdio.h>// define the screen resolution and keyboard macros#define SCREEN_WIDTH 800#define SCREEN_HEIGHT 600#define KEY_DOWN(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0)#define KEY_UP(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 0 : 1)// include the Direct3D Library files#pragma comment (lib, "d3d9.lib")#pragma comment (lib, "d3dx9.lib")// global declarationsLPDIRECT3D9 d3d;LPDIRECT3DDEVICE9 d3ddev;LPD3DXMESH meshTeapot;    // define the mesh pointerLPDIRECT3DVERTEXBUFFER9 v_buffer = NULL;//LPDIRECT3DVERTEXBUFFER9 v_buffer = NULL;//LPDIRECT3DINDEXBUFFER9 i_buffer = NULL;//LPDIRECT3DTEXTURE9 texture = NULL;struct CUSTOMVERTEX {FLOAT X, Y, Z, RHW; DWORD COLOR;};#define CUSTOMFVF (D3DFVF_XYZRHW | D3DFVF_DIFFUSE)// function prototypesvoid initD3D(HWND hWnd);void render_frame(void);void cleanD3D(void);void init_graphics(void);void init_light(void);DWORD LockThread(LPVOID param);void BuildLine();//struct CUSTOMVERTEX {FLOAT X, Y, Z; D3DVECTOR NORMAL; FLOAT U, V;};//#define CUSTOMFVF (D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_TEX1)D3DXVECTOR3 GlobalVerticesv0;D3DXVECTOR3 GlobalVerticesv1;// the WindowProc function prototypeLRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);// the entry point for any Windows programint WINAPI WinMain(HINSTANCE hInstance,    HINSTANCE hPrevInstance,    LPSTR lpCmdLine,    int nCmdShow){    HWND hWnd;    WNDCLASSEX wc;    ZeroMemory(&wc, sizeof(WNDCLASSEX));    wc.cbSize = sizeof(WNDCLASSEX);    wc.style = CS_HREDRAW | CS_VREDRAW;    wc.lpfnWndProc = WindowProc;    wc.hInstance = hInstance;    wc.hCursor = LoadCursor(NULL, IDC_ARROW);    wc.lpszClassName = "WindowClass";    RegisterClassEx(&wc);    hWnd = CreateWindowEx(NULL, "WindowClass", "Our Direct3D Program", WS_OVERLAPPEDWINDOW, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, NULL, NULL, hInstance, NULL);    ShowWindow(hWnd, nCmdShow);    // set up and initialize Direct3D    initD3D(hWnd);CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)LockThread,NULL,0,0);    // enter the main loop:    MSG msg;    while(TRUE)    {   while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))   {  TranslateMessage(&msg);  DispatchMessage(&msg);   }   if(msg.message == WM_QUIT)  break;   render_frame();   if(KEY_DOWN(VK_ESCAPE))  PostMessage(hWnd, WM_DESTROY, 0, 0);    }    // clean up DirectX and COM    cleanD3D();    return msg.wParam;}// this is the main message handler for the programLRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam){    switch(message)    {   case WM_DESTROY:  { PostQuitMessage(0); return 0;  } break;    }    return DefWindowProc (hWnd, message, wParam, lParam);}// this function initializes and prepares Direct3D for usevoid initD3D(HWND hWnd){    d3d = Direct3DCreate9(D3D_SDK_VERSION);    D3DPRESENT_PARAMETERS d3dpp;    ZeroMemory(&d3dpp, sizeof(d3dpp));    d3dpp.Windowed = TRUE;    d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;    d3dpp.hDeviceWindow = hWnd;    d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;    d3dpp.BackBufferWidth = SCREEN_WIDTH;    d3dpp.BackBufferHeight = SCREEN_HEIGHT;    d3dpp.EnableAutoDepthStencil = TRUE;    d3dpp.AutoDepthStencilFormat = D3DFMT_D16;    // create a device class using this information and the info from the d3dpp stuct    d3d->CreateDevice(D3DADAPTER_DEFAULT,  D3DDEVTYPE_HAL,  hWnd,  D3DCREATE_SOFTWARE_VERTEXPROCESSING,  &d3dpp,  &d3ddev);    init_graphics();    init_light();    d3ddev->SetRenderState(D3DRS_ZENABLE, TRUE);    d3ddev->SetRenderState(D3DRS_AMBIENT, D3DCOLOR_XRGB(50, 50, 50));    d3ddev->SetSamplerState(0, D3DSAMP_MAXANISOTROPY, 8);    // anisotropic level    d3ddev->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_ANISOTROPIC);    // minification    d3ddev->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);    // magnification    d3ddev->SetSamplerState(0, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR);    // mipmap}// this is the function used to render a single framevoid render_frame(void){    d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);    d3ddev->Clear(0, NULL, D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);    d3ddev->BeginScene();    // select which vertex format we are using    //d3ddev->SetFVF(CUSTOMFVF);    // set the view transform    D3DXMATRIX matView;    D3DXMatrixLookAtLH(&matView,    &D3DXVECTOR3 (0.0f, 2.0f, 6.0f),    // the camera position    &D3DXVECTOR3 (0.0f, 0.0f, 0.0f), // the look-at position    &D3DXVECTOR3 (0.0f, 1.0f, 0.0f));    // the up direction    d3ddev->SetTransform(D3DTS_VIEW, &matView);    // set the projection transform    D3DXMATRIX matProjection;    D3DXMatrixPerspectiveFovLH(&matProjection, D3DXToRadian(45), (FLOAT)SCREEN_WIDTH / (FLOAT)SCREEN_HEIGHT, 1.0f,    // the near view-plane 100.0f);    // the far view-plane    d3ddev->SetTransform(D3DTS_PROJECTION, &matProjection);    // set the world transform    static float index = 0.0f; index+=0.03f;    D3DXMATRIX matRotateY;    D3DXMatrixRotationY(&matRotateY, index);    //d3ddev->SetTransform(D3DTS_WORLD, &(matRotateY));    // select the vertex and index buffers to use    //d3ddev->SetStreamSource(0, v_buffer, 0, sizeof(CUSTOMVERTEX));    //d3ddev->SetIndices(i_buffer);    // set the texture    //d3ddev->SetTexture(0, texture);    BuildLine();// select which vertex format we are using    d3ddev->SetFVF(CUSTOMFVF);   // select the vertex buffer to display   d3ddev->SetStreamSource(0, v_buffer, 0, sizeof(CUSTOMVERTEX));  // copy the vertex buffer to the back buffer  //d3ddev->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 1);  d3ddev->DrawPrimitive(D3DPT_LINELIST, 0, 1);    // draw the teapot    meshTeapot->DrawSubset(0);   //d3ddev->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, 24, 0, 12);d3ddev->EndScene();d3ddev->Present(NULL, NULL, NULL, NULL);}// this is the function that cleans up Direct3D and COMvoid cleanD3D(void){    //v_buffer->Release();    //i_buffer->Release();    //texture->Release();    meshTeapot->Release();    d3ddev->Release();    d3d->Release();}// this is the function that puts the 3D models into video RAMvoid init_graphics(void){    // deleted all the cube code from here    D3DXCreateTeapot(d3ddev, &meshTeapot, NULL);    // create the teapot}// this is the function that sets up the lights and materialsvoid init_light(void){    D3DLIGHT9 light;    // create the light struct    D3DMATERIAL9 material;    // create the material struct    ZeroMemory(&light, sizeof(light));    // clear out the light struct for use    light.Type = D3DLIGHT_DIRECTIONAL;    // make the light type 'directional light'    light.Diffuse = D3DXCOLOR(0.5f, 0.5f, 0.5f, 1.0f);    // set the light's color    light.Direction = D3DXVECTOR3(-1.0f, -0.3f, -1.0f);    d3ddev->SetLight(0, &light);    // send the light struct properties to light #0    d3ddev->LightEnable(0, TRUE);    // turn on light #0    ZeroMemory(&material, sizeof(D3DMATERIAL9));    // clear out the struct for use    material.Diffuse = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);    // set diffuse color to white    material.Ambient = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);    // set ambient color to white    d3ddev->SetMaterial(&material);    // set the globably-used material to &material}DWORD LockThread(LPVOID param){AllocConsole();HANDLE Console;Console = GetStdHandle(STD_OUTPUT_HANDLE);//MessageBox(NULL,"LockThread","",0);HRESULT Result;BYTE* lpbVb;BYTE *lpIB;LPDIRECT3DINDEXBUFFER9 lpIndexBuffer;D3DINDEXBUFFER_DESC ibdesc;int numIndices;DWORD numBytesPerVertex;char Buffer[64];DWORD idxVbVert0, idxVbVert1, idxVbVert2;DWORD Written;Start:Result = meshTeapot->LockVertexBuffer(D3DLOCK_READONLY, (VOID**)&lpbVb);if(FAILED(Result)){//MessageBox(NULL,"Failed to Lock Vertex Buffer","",0);sprintf(Buffer,"%s\n","Failed to Lock Vertex Buffer");WriteConsole(Console,Buffer,strlen(Buffer),&Written,0);}else{//MessageBox(NULL,"Locked Vertex Buffer","",0);sprintf(Buffer,"%s\n","Locked Vertex Buffer");WriteConsole(Console,Buffer,strlen(Buffer),&Written,0);}Result = meshTeapot->LockIndexBuffer ( D3DLOCK_READONLY, (VOID**)&lpIB);if(FAILED(Result)){//MessageBox(NULL,"Failed to Lock Index Buffer","",0);sprintf(Buffer,"%s\n","Failed to Lock Index Buffer");WriteConsole(Console,Buffer,strlen(Buffer),&Written,0);}else{//MessageBox(NULL,"Locked Index Buffer","",0);sprintf(Buffer,"%s\n","Locked Index Buffer");WriteConsole(Console,Buffer,strlen(Buffer),&Written,0);}Result = meshTeapot->GetIndexBuffer( &lpIndexBuffer );if(FAILED(Result)){//MessageBox(NULL,"Failed to get IndexBuffer","",0);sprintf(Buffer,"%s\n","Failed to get IndexBuffer");WriteConsole(Console,Buffer,strlen(Buffer),&Written,0);}else{//MessageBox(NULL,"Got IndexBuffer","",0);sprintf(Buffer,"%s\n","Got IndexBuffer");WriteConsole(Console,Buffer,strlen(Buffer),&Written,0);}Result = lpIndexBuffer->GetDesc( &ibdesc );if(FAILED(Result)){//MessageBox(NULL,"Failed to get Desc","",0);sprintf(Buffer,"%s\n","Failed to get Desc");WriteConsole(Console,Buffer,strlen(Buffer),&Written,0);}else{//MessageBox(NULL,"Got Desc","",0);sprintf(Buffer,"%s\n","Got Desc");WriteConsole(Console,Buffer,strlen(Buffer),&Written,0);}if(ibdesc.Format == D3DFMT_INDEX32){//MessageBox(NULL,"ibdesc.Format 32","",0);numIndices = ibdesc.Size / sizeof(DWORD);sprintf(Buffer,"%s\n","ibdesc.Format 32");WriteConsole(Console,Buffer,strlen(Buffer),&Written,0);    }else{//MessageBox(NULL,"ibdesc.Format 16","",0);numIndices = ibdesc.Size / sizeof(WORD);sprintf(Buffer,"%s\n","ibdesc.Format 16");WriteConsole(Console,Buffer,strlen(Buffer),&Written,0);}numBytesPerVertex = meshTeapot->GetNumBytesPerVertex();    sprintf(Buffer,"%s %d\n","numBytesPerVertex",numBytesPerVertex);WriteConsole(Console,Buffer,strlen(Buffer),&Written,0);    //sprintf(Buffer,"%d\n",numBytesPerVertex);    //MessageBox(NULL,Buffer,"numBytesPerVertex",0);    sprintf(Buffer,"%s %d\n","numIndices",numIndices);WriteConsole(Console,Buffer,strlen(Buffer),&Written,0);for(int i=0; i<numIndices; i += 3 ){if (ibdesc.Format == D3DFMT_INDEX32  ){//32 bit    idxVbVert0 = ((DWORD*)lpIB);idxVbVert1 = ((DWORD*)lpIB)[ i+1 ];idxVbVert2 = ((DWORD*)lpIB)[ i+2 ];sprintf(Buffer,"%s %d\n","idxVbVert0",numIndices);   WriteConsole(Console,Buffer,strlen(Buffer),&Written,0);    }else{  //16 bitidxVbVert0 = ((WORD*)lpIB);idxVbVert1 = ((WORD*)lpIB)[ i+1 ];idxVbVert2 = ((WORD*)lpIB)[ i+2 ];//sprintf(Buffer,"%s %d\n","idxVbVert0",idxVbVert0);   //WriteConsole(Console,Buffer,strlen(Buffer),&Written,0);//sprintf(Buffer,"%s %d\n","idxVbVert1",idxVbVert1);   //WriteConsole(Console,Buffer,strlen(Buffer),&Written,0);}D3DXVECTOR3 v0 = *(D3DXVECTOR3*) &lpbVb[ idxVbVert0 * numBytesPerVertex ];    D3DXVECTOR3 v1 = *(D3DXVECTOR3*) &lpbVb[ idxVbVert1 * numBytesPerVertex ];D3DXVECTOR3 v2 = *(D3DXVECTOR3*) &lpbVb[ idxVbVert2 * numBytesPerVertex ];sprintf(Buffer,"%s %f %f %f\n","v0",v0.x,v0.y,v0.z);WriteConsole(Console,Buffer,strlen(Buffer),&Written,0);sprintf(Buffer,"%s %f %f %f\n","v1",v1.x,v1.y,v1.z);WriteConsole(Console,Buffer,strlen(Buffer),&Written,0);sprintf(Buffer,"%s %f %f %f\n","v2",v2.x,v2.y,v2.z);WriteConsole(Console,Buffer,strlen(Buffer),&Written,0);GlobalVerticesv0 = v0;GlobalVerticesv1 = v1;sprintf(Buffer,"%s %f %f %f \n","GlobalVerticesv0",GlobalVerticesv0.x,GlobalVerticesv0.y,GlobalVerticesv0.z);WriteConsole(Console,Buffer,strlen(Buffer),&Written,0);    //MessageBox(NULL,Buffer,"GlobalVertices",0);Sleep(50);}meshTeapot-&gt;UnlockVertexBuffer();meshTeapot-&gt;UnlockVertexBuffer();goto Start;return 0;}void BuildLine(){CUSTOMVERTEX vertices[] =    {/*//triangle{ 320.0f, 50.0f, 0.5f, 1.0f, D3DCOLOR_XRGB(0, 0, 255), },   { 520.0f, 400.0f, 0.5f, 1.0f, D3DCOLOR_XRGB(0, 255, 0), },   { 120.0f, 400.0f, 0.5f, 1.0f, D3DCOLOR_XRGB(255, 0, 0), },*///{GlobalVerticesv0.x,GlobalVerticesv0.y,GlobalVerticesv0.z,1.0f,D3DCOLOR_XRGB(0, 0, 255), },    { 0.0f, 50.0f, 0.5f, 1.0f, D3DCOLOR_XRGB(0, 255, 0), },{GlobalVerticesv1.x,GlobalVerticesv1.y,GlobalVerticesv1.z, 1.0f, D3DCOLOR_XRGB(0, 0, 255), },   //{ 0.0f, 50.0f, 0.5f, 1.0f, D3DCOLOR_XRGB(0, 255, 0), },   //{ 150.0f, 500.0f, 0.5f, 1.0f, D3DCOLOR_XRGB(255, 0, 0), },    };    // create a vertex buffer interface called v_buffer    d3ddev-&gt;CreateVertexBuffer(3*sizeof(CUSTOMVERTEX), 0, CUSTOMFVF, D3DPOOL_MANAGED, &v_buffer, NULL);    VOID* pVoid;    // a void pointer    // lock v_buffer and load the vertices into it    v_buffer-&gt;Lock(0, 0, (void**)&pVoid, 0);    memcpy(pVoid, vertices, sizeof(vertices));    v_buffer-&gt;Unlock();}</pre>
  There's many, many things wrong there. This is why DirectXTutorial.com is a bad idea.Let's go over them quickly...1. In your CreateThread call, you're casting a function pointer. never do that.2. If you get WM_QUIT and another message in one tick, you'll not notice the WM_QUIT message and your app will never exit.3. PostMessage(hWnd, WM_DESTROY, 0, 0) is not how you destroy a window - that's how you get undefined behaviour. You want DestroyWindow().4. You're not checking the return values for any functions. If something fails, you'll just crash.5. You're not checking if the device supports a 16-bit depth buffer or a 32-bit backbuffer.6. You're not checking if the device can support a 16-bit depth buffer with a 32-bit backbuffer (Some NVidia cards can't).7. You're setting up lighting, but you're using transformed vertices, so the light settings are ignored.8. You're setting up a world matrix, but you're using transformed vertices, so the transform settings are ignored.9. You're setting a texture, but your vertex format doesn't have texture coordinates, so the vertices will take up the colour of the top left texel in the texture.10. You're locking a vertex buffer in another thread, but not specifying D3DCREATE_MULTITHREADED when you create the device - more undefined behaviour. Using multiple threads with D3D is an extremely bad idea anyway.11. For your own sanity, as well as others who read your code - please get rid of the goto. Use while(true) or for(;;) if you need an infinite loop.From what I can tell, your code should be drawing a teapot and a line from (320, 50) to (520, 400). Although because of the multithreaded use of the device without the multithreaded flag, all bets are off as to what's going on. Personally I'm surprised the app doesn't just crash straight away.Also, the Debug Runtimes will be shouting and screaming about a bunch of stuff. You should turn them on and listen to what they have to say.   