Directx8 - drawing a square - messing up things [modified]
-
Hello, I wrote a code on directx9 to draw and fill a square using ID3DXLine which looked like that: (I should add that this code is inject/hooked into a game).
ID3DXLine *pLine; void fillrgba(int x, int y, int w, int h, int r, int g, int b, int a) { D3DXVECTOR2 vLine[2]; pLine->SetWidth( w ); pLine->SetAntialias( false ); pLine->SetGLLines( true ); vLine[0].x = x + w/2; vLine[0].y = y; vLine[1].x = x + w/2; vLine[1].y = y + h; pLine->Begin( ); pLine->Draw( vLine, 2, D3DCOLOR_RGBA( r, g, b, a ) ); pLine->End( ); }
But now I have to make it work under DirectX8! And there exist no ID3DXLine, so I tried something like thisfloat PanelWidth = 150.0f; float PanelHeight = 200.0f; pDevice->CreateVertexBuffer(4 * sizeof(PANELVERTEX), D3DUSAGE_WRITEONLY, D3DFVF_PANELVERTEX, D3DPOOL_MANAGED, &g_pVertices); PANELVERTEX* pVertices = NULL; g_pVertices->Lock(0, 4 * sizeof(PANELVERTEX), (BYTE**)&pVertices, 0); //Set all the colors to white pVertices[0].color = pVertices[1].color = pVertices[2].color = pVertices[3].color = 0xffffffff; //Set positions and texture coordinates pVertices[0].x = pVertices[3].x = -PanelWidth / 2.0f; pVertices[1].x = pVertices[2].x = PanelWidth / 2.0f; pVertices[0].y = pVertices[1].y = PanelHeight / 2.0f; pVertices[2].y = pVertices[3].y = -PanelHeight / 2.0f; pVertices[0].z = pVertices[1].z = pVertices[2].z = pVertices[3].z = 1.0f; pVertices[1].u = pVertices[2].u = 1.0f; pVertices[0].u = pVertices[3].u = 0.0f; pVertices[0].v = pVertices[1].v = 0.0f; pVertices[2].v = pVertices[3].v = 1.0f; g_pVertices->Unlock(); pDevice->SetVertexShader(D3DFVF_PANELVERTEX); pDevice->SetStreamSource(0, g_pVertices, sizeof(PANELVERTEX)); pDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);
When I use the above code it messess the game up, is there any similar thing like ID3DXLine in DX8 ? I would rather avoid using vertexes, just make it as easy as possible without the BeginScene()/Endscene() and so on, just like ID3DXLine did. Regards, Pawel -- modified at 4:42 Tuesday 29th August, 2006