Jump to content
  • Advertisement
Sign in to follow this  

SOLVED -- Direct3D rendering rectangle with LINESTRIP

This topic is 4531 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've written the following source (I used the Tutorial01_CreateDevice as my basis)
VOID Render()
    if( NULL == g_pd3dDevice )

    // 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

    // 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
I've found the problem, I was passing 5 instead of 4 to DrawPrimitiveUP.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!