Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

andyb716

VertexBuffers and Textures

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

Im trying to create a vertex buffer class and a texture class. I first create a structure to hold my vertices. typedef struct{ FLOAT x, y, z; FLOAT u, v; } sVertex; Then I create the vertex buffer. if(FAILED(m_Graphics->GetDevice()->CreateVertexBuffer(m_VertexSize, 0, m_FVF, D3DPOOL_DEFAULT, &m_pVB))){ return FALSE; } then I pass in my vertex stuct BOOL cVertexBuffer::Set(void *Vertex){ if(Lock() == FALSE){ return FALSE; } memcpy(m_Ptr, Vertex, sizeof(Vertex)); if(Unlock() == FALSE){ return FALSE; } } then I go to render it and nothing shows up. BOOL cVertexBuffer::Render(cTexture *Texture, DWORD Type){ m_Graphics->GetDevice()->SetStreamSource(0, m_pVB, sizeof(sVertex)); m_Graphics->GetDevice()->SetVertexShader(m_FVF); m_Graphics->GetDevice()->SetTexture(0, Texture->GetTexture()); D3DXMatrixIdentity(&m_matTexture); m_Graphics->GetDevice()->SetTransform(D3DTS_WORLD, &m_matTexture); m_Graphics->GetDevice()->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2); m_Graphics->GetDevice()->SetTexture(0, NULL); } is there a way to know if I create the vertex buffer right, or can I know if if copy the vertex info right? If i just use it globally it works fine but when I put it into a class it doesn''t show up. I wonder if the data isn''t bieng passed right. I''m new to all this, so thanks to any one who helps me.

Share this post


Link to post
Share on other sites
Advertisement
You''re creating a vertexbuffer to hold 1 vertex..
The 1st paramter should be m_NumVertices * m_VertexSize.

Beware of the fact that you CANNOT sizeof() a dynamically allocated array, so the memcpy might not work as you expect it to, IF you''re using new to create the vertex-array.


This is DirectX specific, please post questions related to DirectX in the DirectX forum. Thank you.

--
You''re Welcome,
Rick Wong
- Google | Google for GameDev.net | GameDev.net''s DirectX FAQ. (not as cool as the Graphics and Theory FAQ)

Share this post


Link to post
Share on other sites
I have created an array of verts.

sVertex Verts[4] = {
{ -10000.0f, -100.0f, 10000.0f, 0.0f, 0.0f},
{ 10000.0f, -100.0f, 10000.0f, 50.0f, 0.0f},
{ -10000.0f, -100.0f, -10000.0f, 0.0f, 50.0f},
{ 10000.0f, -100.0f, -10000.0f, 50.0f, 50.0f}
};

And I changed my create buffer, and it still doesn''t show up.

if(FAILED(m_Graphics->GetDevice()->CreateVertexBuffer(m_NumVertices * m_VertexSize, 0, m_FVF, D3DPOOL_DEFAULT, &m_pVB))){

I thought this was a begginer question thats why I posted it here, because last time I posted I was told to post in here. I guess I''m a retard or something. thanks for the help.

Share this post


Link to post
Share on other sites
The problem is with the memcpy. sizeof(Vertex) will simply compile down to whatever the size of a void * is on your platform. So you need to modify your function to take the size of the buffer passed in as well as the pointer.

Edit: In fact it seems that your using sVertex everywhere else so you should be passing in a sVertex pointer and not a void pointer if this is the case.

James

[edited by - jamessharpe on June 1, 2004 12:15:09 PM]

Share this post


Link to post
Share on other sites
thanks for all the help, it seems I did need to pass in the size to my function. now it shows up thanks

Share this post


Link to post
Share on other sites

  • 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!