Sign in to follow this  

DrawPrimitiveUP and data from a vector

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

Hi everyone, I'm currently loading model files. I read out the vertex and face data and saved them each in a vector. Now I wanted to draw the faces onto screen using dx9 and DrawPrimitiveUP. But I need a 'user memory pointer to the vertex data'. But how can I convert from 'std::vector' to 'const void*'??? thx for help! cu

Share this post


Link to post
Share on other sites
No, that doesn't work, but maybe it's my fault:

Maybe there is some sizeof mistake in the following code

// MODEL LOADING CODE
...
SModelMesh *pMesh = new SModelMesh;

pMesh->Position = D3DXVECTOR3(0.0f, 0.0f, 0.0f);
pMesh->Color = D3DCOLOR_XRGB(255, 0, 0);

Model.Mesh.push_back(*pMesh);

pMesh->Position = D3DXVECTOR3(0.0f, 0.0f, 1.0f);
pMesh->Color = D3DCOLOR_XRGB(255, 0, 0);

Model.Mesh.push_back(*pMesh);

pMesh->Position = D3DXVECTOR3(1.0f, 0.0f, 1.0f);
pMesh->Color = D3DCOLOR_XRGB(255, 0, 0);

Model.Mesh.push_back(*pMesh);

delete pMesh;

if(FAILED(Engine.Window.m_pD3DDevice->CreateVertexBuffer(3*sizeof(SModelMesh),
0,
D3DFVF_XYZ | D3DFVF_DIFFUSE,
D3DPOOL_DEFAULT,
&Model.VBuffer,
NULL)))
{
// Error --> Exit!
Engine.Exit();
}

VOID* pVertices;
if(FAILED(Model.VBuffer->Lock(0,
3*sizeof(SModelMesh),
(void**)&pVertices,
0)))
{
// Error --> Exit!
Engine.Exit();
}

memcpy(pVertices,
&Model.Mesh,
3*sizeof(SModelMesh));

Model.VBuffer->Unlock();

...
// END OF MODEL LOADING CODE

// RENDERING CODE
...
for(int index = 0; index < Models.m_NumModels; index++)
{
Engine.Window.m_pD3DDevice->SetStreamSource(0,
Models.GetModelVB(index),
0,
sizeof(SModelMesh));
Engine.Window.m_pD3DDevice->SetFVF(D3DFVF_XYZ | D3DFVF_DIFFUSE);
Engine.Window.m_pD3DDevice->DrawPrimitiveUP(D3DPT_TRIANGLELIST,
1,
Models.GetModelMesh(index),
sizeof(SModelMesh));
}
...
// END OF RENDERING CODE

btw the '3' is just for testing, so this will be changed into Model.Mesh.size()!

[Edited by - stefan5000 on July 19, 2005 3:45:30 PM]

Share this post


Link to post
Share on other sites
Change this:
memcpy(pVertices, &Model.Mesh, 3*sizeof(SModelMesh));

To:
memcpy(pVertices, &Model.Mesh[0], 3 * sizeof(SModelMesh));


Also, what does "Models.GetModelMesh(index) do? You're passing whatever it returns to DrawPrimitiveUP, so it could be doing something wrong.

Share this post


Link to post
Share on other sites
I'm not sure why it won't work for you, this works for me:
//D3DCUSTOMVERTEX - Vertex shader for non-textured primitives
//'pflag' and 'primitives' are determined elsewhere
D3DCUSTOMVERTEX *vData;
//For vectors ( vector<D3DCUSTOMVERTEX> example )
vData=&example[0];
lpD3DDevice->DrawPrimitiveUP(pflag,primitives,vData,sizeof(D3DCUSTOMVERTEX));

But then again, I am using DirectX 8...

Share this post


Link to post
Share on other sites
Well, that '[0]'-thing seems to work now at this line:

memcpy(pVertices, &Model.Mesh[0], 3 * sizeof(SModelMesh));

But the DrawPrimitiveUP-function still results in an error when writing that '[0]'-thing!

I changed that void *GetModelMesh(int index) thing to

SModelMesh *CModel::GetModelMesh(int index)
{
SModelMesh *pMesh;
pMesh = &m_ModelList[index].Mesh[0];

return pMesh;
}

Has anyone an idea?!

Share this post


Link to post
Share on other sites

This topic is 4530 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.

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