Sign in to follow this  

I want to draw a red line

This topic is 4225 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I want to draw a red line,but it does not show.Why? As below is a part of source code. I must use D3DFVF_XYZRHW,becuase I use in 2D. typedef struct { FLOAT x, y, z; // 2-D coordinates FLOAT rhw; // rhw DWORD color; // The vertex color } sVertexSelect; #define VERTEXFVF_SELECT (D3DFVF_XYZRHW|D3DFVF_DIFFUSE) IDirect3DVertexBuffer9 *m_pVB_SelectRect; void CAppDraw::DrawSelectLine() { BYTE *Ptr; COLORREF crRed=RGB(255,0,0); sVertexSelect Verts_Select[2]= { {1.0f,1.0f,1.0f,1.0f,crRed}, {1.0f,100.0f,1.0f,1.0f,crRed}, }; m_pVB_SelectRect->Lock(0,0, (void**)&Ptr, 0); memcpy(Ptr, Verts_Select, sizeof(Verts_Select)); m_pVB_SelectRect->Unlock(); m_pD3DDevice->SetTexture(0, NULL); m_pD3DDevice->SetStreamSource( 0, m_pVB_SelectRect,0, sizeof(sVertexSelect) ); m_pD3DDevice->SetFVF( VERTEXFVF_SELECT ); m_pD3DDevice->DrawPrimitive( D3DPT_LINELIST, 0, 1 ); } BOOL CAppDraw::DoFrame() { // Clear device backbuffer m_pD3DDevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_RGBA(0,64,128,255), 1.0f, 0); // Begin scene if(SUCCEEDED(m_pD3DDevice->BeginScene())) { DrawSelectLine(); // End the scene m_pD3DDevice->EndScene(); } // Display the scene m_pD3DDevice->Present(NULL, NULL, NULL, NULL); return TRUE; }

Share this post


Link to post
Share on other sites
Do you get the same result if you set the Z component in both your vertices to 0.5? If you haven't provided any clipping planes DX falls back to the default ones at 0.0 (near) and 1.0 (far). Placing your vertices at Z = 0.5 should save them from unwanted clipping.

Share this post


Link to post
Share on other sites
This is a wild guess. It appears your using 32 bit color from the function D3DCOLOR_RGBA(0,64,128,255) in Clear(), but your RGB() function doesn't have an alpha parameter. crRed could have no alpha value and therefore be rendered transparent. You could instead try using D3DCOLOR_RGBA(255,0,0,255), assuming that function generates the correct DirectX color format.

[Edited by - StormArmageddon on July 12, 2006 6:42:42 PM]

Share this post


Link to post
Share on other sites
StormArmageddon is right in that the RGB() macro returns a 32 bit color (DWORD/COLORREF/D3DCOLOR) with no alpha. From MSDN you get that the macro returns a value of the form 0x00bbggrr. However for this to cause the line to disappear either of the ALPHATESTENABLE or ALPHABLENDENABLE render states bust be TRUE or the alpha will not be taken into consideration.

Share this post


Link to post
Share on other sites
Instead of drawing a line, try a one sided poly to get width. What you might also want to consider is a billboard of a large/long poly, but only aligned along 1 or two axis to get the required affect. This could be quite a bit more flexible then just drawing a line. Billboards aren't necessarily just for trees and objects aligned on the ground towards the camera. I use them for example on the flame exhaust coming out the back of space ships, or the electrical energy beam coming out of some weapons.

Share this post


Link to post
Share on other sites
If you want to keep it simple, try out the ID3DXLine interface. It lets you draw a multisegment line from an array of D3DXVECTOR2 positions in screen coordinates. It uses triangles to draw the line so you can specify any with for the line to be drawn, along with antialias, line pattern and color.

Create an object from the ID3DXLine interface using D3DXCreateLine(). Then each frame between BeginScene() and EndScene() you call ID3DXLine::Begin(), make any number of calls to ID3DXLine::Draw() and finally call ID3DXLine::End(). It follows the exact same procedure as the ID3DXSprite interface, if you're familiar with that one.

Share this post


Link to post
Share on other sites

This topic is 4225 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this