Sign in to follow this  
ext

SOLVED -- Direct3D rendering rectangle with LINESTRIP

Recommended Posts

I've written the following source (I used the Tutorial01_CreateDevice as my basis)
VOID Render()
{
    if( NULL == g_pd3dDevice )
        return;

    // Clear the backbuffer to a black color
    g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,0), 1.0f, 0 );
    
    // Begin the scene
    if( SUCCEEDED( g_pd3dDevice->BeginScene() ) )
    {
        // Rendering of scene objects can happen here
		if( g_isDragging )
		{
				struct Vertex
			{
				float x,y,z,rhw;
				D3DCOLOR color;
			};
			Vertex vertices[5];
			vertices[0].x = g_dragRect.left; // top left
			vertices[0].y = g_dragRect.top;
			vertices[0].z = 1.0f;
			vertices[0].rhw = 1.0f;
			vertices[0].color = D3DCOLOR_XRGB(0,255,0);
			vertices[1].x = g_dragRect.right; // top right
			vertices[1].y = g_dragRect.top;
			vertices[1].z = 1.0f;
			vertices[1].rhw = 1.0f;
			vertices[1].color = D3DCOLOR_XRGB(0,255,0);
			vertices[2].x = g_dragRect.right; // right bottom
			vertices[2].y = g_dragRect.bottom;
			vertices[2].z = 1.0f;
			vertices[2].rhw = 1.0f;
			vertices[2].color = D3DCOLOR_XRGB(0,255,0);
			vertices[3].x = g_dragRect.left; // left bottom
			vertices[3].y = g_dragRect.bottom;
			vertices[3].z = 1.0f;
			vertices[3].rhw = 1.0f;
			vertices[3].color = D3DCOLOR_XRGB(0,255,0);
			vertices[4].x = g_dragRect.left; // top left again
			vertices[4].y = g_dragRect.top;
			vertices[4].z = 1.0f;
			vertices[4].rhw = 1.0f;
			vertices[4].color = D3DCOLOR_XRGB(0,255,0);

			g_pd3dDevice->DrawPrimitiveUP( D3DPT_LINESTRIP, 5, (void*) vertices, sizeof( Vertex ) ); 
		}
		
    
        // End the scene
        g_pd3dDevice->EndScene();
    }

    // Present the backbuffer contents to the display
    g_pd3dDevice->Present( NULL, NULL, NULL, NULL );
}

It's drawing a rectangle by pressing the left mouse button and then moving the mouse. And it's working so far, the only problem is that it's drawing a first line from 0,0 to my first vertex, so I've got 5lines instead of 4. But I want only the four from my rectangle without a line from 0,0 to the first vertex. What should I do to tell d3d that it shouldn't draw this line?

Share this post


Link to post
Share on other sites

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