I want to draw a red line

Started by
7 comments, last by Staffan E 17 years, 11 months ago
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; }
akira32 編程之家 Yahoohttp://tw.myblog.yahoo.com/akira32-akira32
Advertisement
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.
Hack my projects! Oh Yeah! Use an SVN client to check them out.BlockStacker
Also try setting the RHW to 0.5f, see if that helps.

Are you sure your setup code is correct?
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]
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.
Hack my projects! Oh Yeah! Use an SVN client to check them out.BlockStacker
I use D3DCOLOR_RGBA(255,0,0,255),then the red line appears.
Thank StormArmageddon and staaf.
akira32 編程之家 Yahoohttp://tw.myblog.yahoo.com/akira32-akira32
How do I enlarge the width of the line?
akira32 編程之家 Yahoohttp://tw.myblog.yahoo.com/akira32-akira32
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.
3DMUVE is an amateur game development team, and the designer and developer of a new gaming technology “MUVE” for the gaming industry.
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.
Hack my projects! Oh Yeah! Use an SVN client to check them out.BlockStacker

This topic is closed to new replies.

Advertisement