Rendering .obj Model in DirectX 11

Started by
29 comments, last by eee 9 years, 3 months ago

Hello,

I'm trying to render a box model (.obj file) but I don't see anything, I have attached the project file.

Advertisement
Have you tried turning it on and off again?

@fastcall22: What do you mean?

What is it you think is going to happen here? Do you think someone is going to download your project, set it up on their system, investigate and fix the issue then send back the fixed project, all from the goodness of their hearts?

What have you tried? What isn't working? Specific questions will get answers.

@Aardvajk: The problem is: I don't see the model on the screen even I'm loading the vertices and setting up the vertex and index buffer

So, the best thing here is to post the code that I'm using.

FYI: This is just a simple project and it won't take 5 minutes to look it up.

Do you think someone is going to download your project, set it up on their system, investigate and fix the issue then send back the fixed project, all from the goodness of their hearts?

Yes, I'm expecting people here will help.

If you would like someone to help you need to list what you've tried already, and what you think the problem might be. Narrow down the code shared to just the part where you think the problem is, and maybe try isolating problem parts in a stand alone test case.

Finally, voting down people for stating the brutally honest truth is a bit low, i wouldn't do it if I were you because the mods can see it...

@braindigitalis: What If I don't know where the problem is?

The only thing I see is that dev->CreateBuffer() is returning false when creating vertex or index buffer even both buffers was created successfully.

However, I'm not sure if the box is drawn or not (I see nothing on the screening)


int indexCount = vertexCount;
// Create vertex buffer
D3D11_BUFFER_DESC bd;
ZeroMemory(&bd, sizeof(D3D11_BUFFER_DESC));
bd.Usage = D3D11_USAGE_DYNAMIC;
bd.BindFlags = D3D11_BIND_VERTEX_BUFFER;
bd.ByteWidth = vertexCount * sizeof(VertexType);
bd.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
bool r = dev->CreateBuffer(&bd, NULL, &pVertexBuffer);

D3D11_MAPPED_SUBRESOURCE ms;
devcon->Map(pVertexBuffer, NULL, D3D11_MAP_WRITE_DISCARD, 0, &ms);
memcpy(ms.pData, &vertices, sizeof(vertices));
devcon->Unmap(pVertexBuffer, NULL);

// Create index buffer
D3D11_BUFFER_DESC indexBufferDESC;
//ZeroMemory(&indexBufferDESC, sizeof(indexBufferDESC));
indexBufferDESC.Usage = D3D11_USAGE_DEFAULT;
indexBufferDESC.ByteWidth = sizeof(unsigned long) * indexCount;
indexBufferDESC.BindFlags = D3D11_BIND_INDEX_BUFFER;
indexBufferDESC.CPUAccessFlags = 0;
indexBufferDESC.MiscFlags = 0;
indexBufferDESC.StructureByteStride = 0;


D3D11_SUBRESOURCE_DATA indexData;
indexData.pSysMem = indices;
indexData.SysMemPitch = 0;
indexData.SysMemSlicePitch = 0;

// Create the index buffer
result = dev->CreateBuffer(&indexBufferDESC, &indexData, &pIndexBuffer);

Thanks, any idea why the zeromemory call is commented out? There are other fields in the index buffer you aren't filling that should all be zeroed. Does uncommenting that help at all?

@braindigitalis: The 6 structure properties are filled, I even tried to uncomment the ZeroMemory() call but still nothing happens.

You removed most of temp files from your project, I'll give you that. Usually people are unable to do even that.

I am unable to compile your project because I don't have D3DX, but there is something I have noticed:

  1. you aren't doing any transformations in your vertex shader, meaning it's not being transformed into the screen;
  2. your box is relatively far from (0, 0, 0) point, it won't be visible with 'default' camera transform.

This topic is closed to new replies.

Advertisement