Jump to content
  • Advertisement
Sign in to follow this  
Sync Views

DrawPrimitive problem

This topic is 3971 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

Ive got this for drawing the outline of a rectangle. It draws the 1st 3 lines fine but the 4th line goes off the top left of the screen(0,0,0 I presume). If I uncomment the 5th point (same as the 1st) then nothing is drawn at all :(
void draw_rectangle_outline(float x, float y, float w, float h, D3DCOLOR c1, D3DCOLOR c2, D3DCOLOR c3, D3DCOLOR c4)
{
	x -= 0.5f;
	y -= 0.5f;
	cgm::d3d_vertex* vertices;
	cgm::d3d_vertex_buffer->Lock(0, 0, (void**)&vertices, NULL);

	vertices[0].colour = c1;
	vertices[0].x = x;
	vertices[0].y = y;
	vertices[0].z = 0.0;
	vertices[0].rhw = 1.0;
	vertices[0].u = 0.0;
	vertices[0].v = 0.0;

	vertices[1].colour = c2;
	vertices[1].x = x + w;
	vertices[1].y = y;
	vertices[1].z = 0.0;
	vertices[1].rhw = 1.0;
	vertices[1].u = 1.0;
	vertices[1].v = 0.0;

	vertices[2].colour = c3;
	vertices[2].x = x + w;
	vertices[2].y = y + h;
	vertices[2].z = 0.0;
	vertices[2].rhw = 1.0;
	vertices[2].u = 1.0;
	vertices[2].v = 1.0;

	vertices[3].colour = c4;
	vertices[3].x = x;
	vertices[3].y = y + h;
	vertices[3].z = 0.0;
	vertices[3].rhw = 1.0;
	vertices[3].u = 0.0;
	vertices[3].v = 1.0;

	/*vertices[4].colour = c1;
	vertices[4].x = x;
	vertices[4].y = y;
	vertices[4].z = 0.0;
	vertices[4].rhw = 1.0;
	vertices[4].u = 0.0;
	vertices[4].v = 0.0;*/

	cgm::d3d_vertex_buffer->Unlock();
	cgm::d3d_device->SetTexture (0, NULL);
	cgm::d3d_device->DrawPrimitive (D3DPT_LINESTRIP, 0, 4);
}


Share this post


Link to post
Share on other sites
Advertisement
The last parameter to DrawPrimitive() is the number of primitives to draw, not the number of vertices. You're passing in the following line strip (with 4 vertices):

0-------------1
|
|
|
|
3-------------2


Which is 3 lines, not 4. I presume that D3D is reading garbage from the vertex buffer for the final point.

How big is your vertex buffer? And I suggest you use the Debug Runtimes, they'll probably tell you why nothing is being rendered when you put in 5 vertices (Which is the correct number)

Share this post


Link to post
Share on other sites
My copy of the DirectX SDK (November 2007) doesn't seem to have a "d3d9d.lib" file, only "d3d9.lib". Also how do I do this "unmanaged debugging" thing with VS 2008?

EDIT: Turned out it was because the vertex buffer was too small. How large should I make the buffer though? Ive risen it to 10 for now but sooner or later there is bound to be something that breaks that as well...

Anyway I did the directX debug mode thing (although I still havn't worked out what that guid is wanting me to do in VS). I'm getting a bunch of errors that I have no idea what is causeing them or how to solve them :(


Direct3D9: :DoneExclusiveMode
Direct3D9: :====> ENTER: DLLMAIN(00e4e6e0): Process Detach 00000f20, tid=00000df4
Direct3D9: (INFO) :MemFini!
Direct3D9: (WARN) :Memory still allocated! Alloc count = 108
Direct3D9: (WARN) :Current Process (pid) = 00000f20
Direct3D9: (WARN) :Memory Address: 00c75060 lAllocID=1 dwSize=000047f8, (pid=00000f20)
Direct3D9: (WARN) : Stack Back Trace
Direct3D9: (ERROR) : [0] : Address 00E4E4CB
Direct3D9: (ERROR) : [1] : Address 00E4E59B
Direct3D9: (ERROR) : [2] : Address 00E4E440
Direct3D9: (ERROR) : [3] : Address 00E42DB4
Direct3D9: (ERROR) : [4] : Address 4FDFAF2E
Direct3D9: (ERROR) : [5] : Address 00418D25
Direct3D9: (ERROR) : [6] : Address 0041761E
Direct3D9: (ERROR) : [7] : Address 0042D028
Direct3D9: (ERROR) : [8] : Address 0042CD8F
Direct3D9: (ERROR) : [9] : Address 7C816D4F
Direct3D9: (ERROR) : [10] : Address 00000000
Direct3D9: (ERROR) : [11] : Address 00000000
Direct3D9: (ERROR) : [12] : Address 00000000
Direct3D9: (ERROR) : [13] : Address 00000000
Direct3D9: (ERROR) : [14] : Address 00000000
Direct3D9: (ERROR) : [15] : Address 00000000
Direct3D9: (WARN) :Memory Address: 00c7bc50 lAllocID=10 dwSize=000013d4, (pid=00000f20)
Direct3D9: (WARN) : Stack Back Trace
Direct3D9: (ERROR) : [0] : Address 00E450D4
Direct3D9: (ERROR) : [1] : Address 00E45EBF
Direct3D9: (ERROR) : [2] : Address 00E465F8
Direct3D9: (ERROR) : [3] : Address 00E42DD5
Direct3D9: (ERROR) : [4] : Address 4FDFAF2E
Direct3D9: (ERROR) : [5] : Address 00418D25
Direct3D9: (ERROR) : [6] : Address 0041761E
Direct3D9: (ERROR) : [7] : Address 0042D028
Direct3D9: (ERROR) : [8] : Address 0042CD8F
Direct3D9: (ERROR) : [9] : Address 7C816D4F
Direct3D9: (ERROR) : [10] : Address 00000000
Direct3D9: (ERROR) : [11] : Address 00000000
Direct3D9: (ERROR) : [12] : Address 00000000
Direct3D9: (ERROR) : [13] : Address 00000000
Direct3D9: (ERROR) : [14] : Address 00000000
Direct3D9: (ERROR) : [15] : Address 00000000
Direct3D9: (WARN) :Memory Address: 00c7bae0 lAllocID=11 dwSize=00000014, (pid=00000f20)
Direct3D9: (WARN) : Stack Back Trace
...


[Edited by - Sync Views on February 4, 2008 4:06:01 PM]

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!