Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


bjornp

Member Since 10 Mar 2013
Offline Last Active Mar 21 2015 04:56 AM

#5208143 [Solved]Garbage data in Vertexbuffer

Posted by bjornp on 02 February 2015 - 01:07 AM

Hello, when loading data from my application into the Vertexbuffer, it seems that random data is loaded instead of my vertices. See picture:

 

vb.jpg

 

However, my vertices are defiened as follows (there are 24 in total, model is a cube):

 

vertices.jpg

 

 

I create my buffer like this:

D3D11_BUFFER_DESC vertexBufferDesc;
ZeroMemory(&vertexBufferDesc, sizeof(vertexBufferDesc));
vertexBufferDesc.Usage = D3D11_USAGE_DEFAULT;
vertexBufferDesc.ByteWidth = sizeof(SimpleVertex2) * _vertexes.size();
vertexBufferDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
vertexBufferDesc.CPUAccessFlags = 0;
vertexBufferDesc.MiscFlags = 0;
D3D11_SUBRESOURCE_DATA InitialVertexData;
ZeroMemory(&InitialVertexData, sizeof(InitialVertexData));
InitialVertexData.pSysMem = &_vertexes;
InitialVertexData.SysMemPitch = 0;
InitialVertexData.SysMemSlicePitch = 0;
_gfx->GetDevice()->CreateBuffer(&vertexBufferDesc, &InitialVertexData, &_vertexbuffer);

I set my vertexbuffer before rendering:

unsigned int _stride = sizeof(SimpleVertex2);
unsigned int _offset = 0;
_gfx->GetContext()->IASetVertexBuffers(0, 1, &_vertexbuffer, &_stride, &_offset);

My vertexformat:

struct SimpleVertex2
{
XMFLOAT4 Pos;
XMFLOAT3 Normal;
};

I am having trouble locating the source of the error. Hoping you can help my once again with my problems smile.png.

 

 

 

Edit: The problem was on this line:

 

InitialVertexData.pSysMem = &_vertexes;

 

When using vectors to initialize VBs you need to use:

 

InitialVertexData.pSysMem = &_vertexes[0];



#5158931 [Solved] Depth not working

Posted by bjornp on 07 June 2014 - 12:01 PM

Ok i found the problem. I was using the DirectX Toolkit to render text which disables the depthbuffer to do so, I just had to enable it again :)

 

D3DDeviceContext->OMSetDepthStencilState(pDSState, 1);



PARTNERS