I have a graphics engine that i writing in Directx11 and I changed the way objects are drawn, and the way assets for the game are loaded. Everything in my draw call is set correct and I thought that it might be that the way the Buffers for the Vertices and the Indices are set but they seem to have the data set, same with my texture it is also loading so i have no idea why it is not drawing anything when the camera in pointed at where the object is set to be, and I have no translations set for the object.

//Clearing the Back Buffer
devcon->ClearRenderTargetView(backbuffer, Blue);
//Clearing the Depth Buffer 
devcon->ClearDepthStencilView(zbuffer, D3D11_CLEAR_DEPTH, 1.0f, 0);
//Projection Matrix
D3DXMATRIX matProjection;
//View Matrix
//Setting it to the only Viewport that i have set, it is a array because of an idea i have for later
devcon->RSSetViewports(1, &viewport[0]);

//Setting my projection Matrix
D3DXMatrixPerspectiveFovLH(&matProjection, (FLOAT)D3DXToRadian(45), (FLOAT)(SCREEN_WIDTH) / (FLOAT)SCREEN_HEIGHT,

//Setting my View Matrix
    &D3DXVECTOR3(0, 10, 0),    // the camera position
    &D3DXVECTOR3(0, 0, 0),    // the look-at position
    &D3DXVECTOR3(0.0f, 1.0f, 0.0f));

//VERTEX is custom struct that holds position as three floats, the surface normal as a custom VECTOR3 Struct, and two floats for the UV map
UINT stride = sizeof(VERTEX);
UINT offset = 0;
//Constant buffer for the Vertex Shader it holds the light, and direction of the main light, the ambient color, and also the rotation and final matrix for the object
//the light vector 
cb.LightVector = D3DXVECTOR4(0.0f, 1.0f, 0.0f, 0.0f);
//A medium color for it
cb.LightColor = D3DXCOLOR(0.7f, 0.7f, 0.7f, 1.0f);
//A lower level for the ambient
cb.AmbientColor = D3DXCOLOR(0.2f, 0.2f, 0.2f, 1.0f);

//setting my primative topology as a triangle list, which is what is always use and has always worked
//allThingsToDraw is a vector which holds a stuct that all things that want to be drawn have and give to my main directx class to use to draw 
for (int i = 0; i < allThingsToDraw.size(); i++)
    //Creating the Translation matrix, the position is set to 0,0,0
    D3DXMatrixTranslation(&matTraslate, allThingsToDraw[i].position.X, allThingsToDraw[i].position.Y, allThingsToDraw[i].position.Z);
    //The scale is set to 1,1,1 so that it is just a regular size
    D3DXMatrixScaling(&matScale, allThingsToDraw[i].scale.X, allThingsToDraw[i].scale.Y, allThingsToDraw[i].scale.Z);
    //All of the rotation at set to zero so that it has not moved in any way 
    D3DXMatrixRotationX(&matRotateX, allThingsToDraw[i].roation.X);
    D3DXMatrixRotationY(&matRotateY, allThingsToDraw[i].roation.Y);
    D3DXMatrixRotationZ(&matRotateZ, allThingsToDraw[i].roation.Z);
    //Creating my world Matrix
    matWorld = matRotateX * matRotateY * matRotateZ * matScale * matTraslate;
    //My final matrix
    matFinal = matWorld * matView * matProjection;
    //The final matrix being placed into my Constant buffer
    cb.Final = matFinal;
    //The rotation matrix being placed into the constant buffer
    cb.Rotation = matRotateX * matRotateY * matRotateZ;
    //My Vertices buffer, this is loaded and then held in a ModelLoader class, and the model class grabs that pointer and that is what is used to drawn, i think that this might be where the problem comes in
    devcon->IASetVertexBuffers(0, 1, &allThingsToDraw[i].modelData->Direxctx11VerticesBuffer, &stride, &offset);
    //My indices buffer this is also held inside the modelloader class paired with the Vertices that it is going to be with
    devcon->IASetIndexBuffer(allThingsToDraw[i].modelData->Direxctx11IndicesBuffer, DXGI_FORMAT_R32_UINT, 0);
    //Sending my Shader my Constant Buffer
    devcon->UpdateSubresource(pCBuffer, 0, 0, &cb, 0, 0);
    //Loading my texture this uses a similar way to my model, and is loaded on the model after i load the model so that differnet textures can be loaded onto to different models
    devcon->PSSetShaderResources(0, 1, &allThingsToDraw[i].modelData->Texture);
    //I have this hardcoded to 36 because i am stil testing if this way works and i only have the one object that i am drawing
    devcon->DrawIndexed(36, 0, 0);

//After this function the swapchain->Present(0,0); is called 
  • 2
    \$\begingroup\$ Try enabling DirectX debug messages and see if there's anything in the Output window; msdn.microsoft.com/en-us/library/windows/desktop/… \$\endgroup\$ – chad.mellor Jan 1 '14 at 1:56
  • 1
    \$\begingroup\$ Also, have you set an InputLayout and does it match what you shader is expecting? \$\endgroup\$ – chad.mellor Jan 1 '14 at 1:57
  • \$\begingroup\$ I do have a InputLayout set up and it does match what the shader in expecting \$\endgroup\$ – Tucker Morgan Jan 1 '14 at 3:13
  • \$\begingroup\$ just a side note, you are using D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST and D3DXMATRIX, but you tagged your question directx11? \$\endgroup\$ – user13213 Jan 1 '14 at 7:02
  • 1
    \$\begingroup\$ There is like zillion things that can be wrong. It can be uninitialized variable or missing context call. If you implement any changes to your rendering system do it step by step and every time check if it works as you expect. Draw some simple object at point 0.0 without any transformation. \$\endgroup\$ – Lufi Jan 1 '14 at 20:06

You need to scale before rotating. Otherwise the model is skewed, possibly the point of not being visible.


Matrix Multiplication is not commutative as it represents functions compositions (for example, sqrt of x² is the same as (sqrt x)². Okay is example is not really good because it's not from linear algebra).

A rule to remember when doing 3D is the "SRT" rule, as an order of application. That means you must Scale first, then rotate, then translate.

In matrix multiplication, the order is reversed, and it makes T * R * S as the final matrix, where T is the Matrix of translation, R of rotation, S of scale.

matWorld = matRotateX * matRotateY * matRotateZ * matScale * matTraslate;

I Believe that line is wrong, because you apply the scale and the rotation to your translation.

  • \$\begingroup\$ Would (SRT).Inverse be the same? Because I only do that for my view matrix, I always do world transform like this (SRT) I also have row_major matrix packing set for shader compilation. If I recall its openGL that uses TRS for the world transform but I could be wrong as I don't use openGL. \$\endgroup\$ – Justin William Stanley Bryant Feb 6 '17 at 23:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.