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);
}
DrawPrimitive problem
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 :(
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):
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)
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)
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 :(
[Edited by - Sync Views on February 4, 2008 4:06:01 PM]
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: :DoneExclusiveModeDirect3D9: :====> ENTER: DLLMAIN(00e4e6e0): Process Detach 00000f20, tid=00000df4Direct3D9: (INFO) :MemFini!Direct3D9: (WARN) :Memory still allocated! Alloc count = 108Direct3D9: (WARN) :Current Process (pid) = 00000f20Direct3D9: (WARN) :Memory Address: 00c75060 lAllocID=1 dwSize=000047f8, (pid=00000f20)Direct3D9: (WARN) : Stack Back TraceDirect3D9: (ERROR) : [0] : Address 00E4E4CBDirect3D9: (ERROR) : [1] : Address 00E4E59BDirect3D9: (ERROR) : [2] : Address 00E4E440Direct3D9: (ERROR) : [3] : Address 00E42DB4Direct3D9: (ERROR) : [4] : Address 4FDFAF2EDirect3D9: (ERROR) : [5] : Address 00418D25Direct3D9: (ERROR) : [6] : Address 0041761EDirect3D9: (ERROR) : [7] : Address 0042D028Direct3D9: (ERROR) : [8] : Address 0042CD8FDirect3D9: (ERROR) : [9] : Address 7C816D4FDirect3D9: (ERROR) : [10] : Address 00000000Direct3D9: (ERROR) : [11] : Address 00000000Direct3D9: (ERROR) : [12] : Address 00000000Direct3D9: (ERROR) : [13] : Address 00000000Direct3D9: (ERROR) : [14] : Address 00000000Direct3D9: (ERROR) : [15] : Address 00000000Direct3D9: (WARN) :Memory Address: 00c7bc50 lAllocID=10 dwSize=000013d4, (pid=00000f20)Direct3D9: (WARN) : Stack Back TraceDirect3D9: (ERROR) : [0] : Address 00E450D4Direct3D9: (ERROR) : [1] : Address 00E45EBFDirect3D9: (ERROR) : [2] : Address 00E465F8Direct3D9: (ERROR) : [3] : Address 00E42DD5Direct3D9: (ERROR) : [4] : Address 4FDFAF2EDirect3D9: (ERROR) : [5] : Address 00418D25Direct3D9: (ERROR) : [6] : Address 0041761EDirect3D9: (ERROR) : [7] : Address 0042D028Direct3D9: (ERROR) : [8] : Address 0042CD8FDirect3D9: (ERROR) : [9] : Address 7C816D4FDirect3D9: (ERROR) : [10] : Address 00000000Direct3D9: (ERROR) : [11] : Address 00000000Direct3D9: (ERROR) : [12] : Address 00000000Direct3D9: (ERROR) : [13] : Address 00000000Direct3D9: (ERROR) : [14] : Address 00000000Direct3D9: (ERROR) : [15] : Address 00000000Direct3D9: (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]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement