basically i wanted people to be able to specify the position of each vertex and let D3D figure out the points then render the primitive count accordingly, but as you can see, that's not happening...So could someone tell me what to do to get it to work? (i'm making a D3D9/10/11 engine (also gonna throw in OpenGL), anyways, any thoughts?
You can't use rich text/HTML inside a code block. You can try copying your code into notepad first to strip it of all formatting, and then pasting it into here.
You can't use rich text/HTML inside a code block. You can try copying your code into notepad first to strip it of all formatting, and then pasting it into here.
This is an array of pointers. You can't upload an array of pointers to DirectX -- it wants an array of values. Also, by using new here, you're leaking memory.std::vector<VertexPos*> verts;
verts.push_back(new VertexPos(X,Y,Z)); You want:std::vector<VertexPos> verts;
verts.push_back(VertexPos(X,Y,Z));
Here, "[font="Lucida Console"]&size[/font]" is the address of a local variable -- you're copying random local variable data from the stack into your vertex buffer!
Also, "[font="Lucida Console"]sizeof(verts)[/font]" tells you the size of a std::vector, which is always going to return ~12 IIRC, no matter how many items are in the vector!
What is this memcpy supposed to be doing -- you've only just created the buffer, and don't have any data to copy into it yet?DWORD size = (DWORD)verts.size();
memcpy(pDat,&size,sizeof(verts));
Again, here "sizeof(verts.size())" is telling you the size of an unsigned integer variable, which will always return 4, no matter how many items are in the vector... You did the correct calculation up in CreateVertexBuffer with "[font="Lucida Console"]primitiveCount*sizeof(VertexPos)[/font]" ID3D9Renderer::getDev9()->SetStreamSource(0,pVertexBuffer,0,sizeof(verts.size()));
[hr]The logic of your class doesn't make much sense to me either.
You initialize primitiveCount to 0, then you use that number (0) to create the vertex buffer (with 0 size), then you copy some random data into the vertex buffer. Then with each call to setPosition, you copy data into a vector (which is never copied into the vertex buffer).
I would guess that the logic should look like this - the size of the vertex buffer isn't known until after all the setPosition calls, which means you've got to create the vertex buffer in the call to endRenderable. void IPolygon::beginRenderable()
{
assert( pVertexBuffer == NULL );
}
void IPolygon::setPosition(float X, float Y, float Z)
{
verts.push_back(VertexPos(X,Y,Z)); // don't need primitiveCount - verts.size() is the same thing
}
void IPolygon::endRenderable()
{
assert( !verts.empty() );
DWORD sizeInBytes = verts.size() *sizeof(VertexPos);//how many items * size of each item
HR(ID3D9Renderer::getDev9()->CreateVertexBuffer(sizeInBytes,0,D3DFVF_XYZ,
D3DPOOL_DEFAULT,
&pVertexBuffer,
NULL));
void* pDat;
HR(pVertexBuffer->Lock(0,0,&pDat,0));
memcpy(pDat,&verts[0],sizeInBytes);//copy from the vector into the buffer
HR(pVertexBuffer->Unlock());
}
Ok, thanks, i got it to work thanks to you, now to do the same with generating indices and texture coordnates based on how many triangles in the vector (also make it shader based rendering so that way D3D9/10/11 are in sync)
Ok, i'm having a little problem.... when i try to add just one triangle it adds like 10 or what ever, I'm trying to use the class to create a screen quad
and i get this output:
ScreenQuad::ScreenQuad()
{
screen_Object = new DynamicObject9();
}
What is the type of [font="CourierNew, monospace"]verts[/font]? You're putting [color="#1C2837"][font="CourierNew, monospace"][color="#660066"]VertexPosColor[/font]s into it, but are computing it's size in bytes as if it contains [color="#660066"][font="CourierNew, monospace"]VertexData[/font]s.
Again, [color="#1C2837"][font="CourierNew, monospace"][color="#000088"]sizeof[color="#666600"]([color="#000000"]verts[color="#666600"].[color="#000000"]size[color="#666600"]())[/font] will always return 4 (the size of the of an [font="Courier New"]unsigned int[/font] -- the type that's returned by [font="Courier New"]size()[/font]).
Also, [color="#660066"][font="CourierNew, monospace"]DrawPrimitive[/font] wants you to pass in the number of primitives, but you're passing in the number of vertices. Inside the switch statement, you need to add logic for each primitive type that calculates the number of primitives based on the number of vertices (e.g. for a tri-list, it's [font="Courier New"]numVerts/3[/font], for a tri-strip it's [font="Courier New"]numVerts-2[/font], etc...)
this is still not getting me anywhere, I'll just have to create a new vertex buffer for the screen quad and just fill it that way with the 6 vertices to make the quad..."sigh* i'll have to study this problem more carefully to better understand it, as it stands it only draws one triangle half way the screen thanks for your help