   [DX10] Why does my cube looks like *this*?
  Please, see this picture, and tell me why:I'm working on a small testing application today, and I've seen that my models are all just gibberish. So I just copied some code from a DX-Tutorial from the SDK, to draw that test cube. And there it happens, too! Never had this before (Not when the indices are right), what can it be? Here is how I create my cube:    V_RETURN( D3DX10CreateEffectFromFile( str, NULL, NULL, "fx_4_0", dwShaderFlags, 0, pd3dDevice, NULL, NULL, &g_pEffect10, NULL, NULL ) );    // Get effects variables    g_pmWorldViewProj = g_pEffect10->GetVariableByName( "g_mWorldViewProjection" )->AsMatrix();    g_pmWorld = g_pEffect10->GetVariableByName( "g_mWorld" )->AsMatrix();    g_pfTime = g_pEffect10->GetVariableByName( "g_fTime" )->AsScalar(); // Create our vertex input layout    const D3D10_INPUT_ELEMENT_DESC layout[] =    {   { "POSITION",  0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0,  D3D10_INPUT_PER_VERTEX_DATA, 0 },   { "NORMAL",    0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 12, D3D10_INPUT_PER_VERTEX_DATA, 0 },   { "TEXCOORD",  0, DXGI_FORMAT_R32G32_FLOAT,    0, 24, D3D10_INPUT_PER_VERTEX_DATA, 0 },    };    D3D10_PASS_DESC PassDesc;V_RETURN( g_pEffect10->GetTechniqueByIndex(0)->GetPassByIndex( 0 )->GetDesc( &PassDesc ) );    V_RETURN( pd3dDevice->CreateInputLayout( layout, 3, PassDesc.pIAInputSignature,PassDesc.IAInputSignatureSize, &g_pVertexLayout ) ); // Create vertex buffer    VertexStruct vertices[] =    {   { D3DXVECTOR3( -1.0f, 1.0f, -1.0f ), D3DXVECTOR2( 0.0f, 0.0f ), D3DXVECTOR2( 0.0f, 0.0f ) },   { D3DXVECTOR3( 1.0f, 1.0f, -1.0f ), D3DXVECTOR2( 1.0f, 0.0f ), D3DXVECTOR2( 0.0f, 0.0f ) },   { D3DXVECTOR3( 1.0f, 1.0f, 1.0f ), D3DXVECTOR2( 1.0f, 1.0f ), D3DXVECTOR2( 0.0f, 0.0f ) },   { D3DXVECTOR3( -1.0f, 1.0f, 1.0f ), D3DXVECTOR2( 0.0f, 1.0f ), D3DXVECTOR2( 0.0f, 0.0f ) },   { D3DXVECTOR3( -1.0f, -1.0f, -1.0f ), D3DXVECTOR2( 0.0f, 0.0f ), D3DXVECTOR2( 0.0f, 0.0f ) },   { D3DXVECTOR3( 1.0f, -1.0f, -1.0f ), D3DXVECTOR2( 1.0f, 0.0f ), D3DXVECTOR2( 0.0f, 0.0f ) },   { D3DXVECTOR3( 1.0f, -1.0f, 1.0f ), D3DXVECTOR2( 1.0f, 1.0f ), D3DXVECTOR2( 0.0f, 0.0f ) },   { D3DXVECTOR3( -1.0f, -1.0f, 1.0f ), D3DXVECTOR2( 0.0f, 1.0f ), D3DXVECTOR2( 0.0f, 0.0f ) },   { D3DXVECTOR3( -1.0f, -1.0f, 1.0f ), D3DXVECTOR2( 0.0f, 0.0f ), D3DXVECTOR2( 0.0f, 0.0f ) },   { D3DXVECTOR3( -1.0f, -1.0f, -1.0f ), D3DXVECTOR2( 1.0f, 0.0f ), D3DXVECTOR2( 0.0f, 0.0f ) },   { D3DXVECTOR3( -1.0f, 1.0f, -1.0f ), D3DXVECTOR2( 1.0f, 1.0f ), D3DXVECTOR2( 0.0f, 0.0f ) },   { D3DXVECTOR3( -1.0f, 1.0f, 1.0f ), D3DXVECTOR2( 0.0f, 1.0f ), D3DXVECTOR2( 0.0f, 0.0f ) },   { D3DXVECTOR3( 1.0f, -1.0f, 1.0f ), D3DXVECTOR2( 0.0f, 0.0f ), D3DXVECTOR2( 0.0f, 0.0f ) },   { D3DXVECTOR3( 1.0f, -1.0f, -1.0f ), D3DXVECTOR2( 1.0f, 0.0f ), D3DXVECTOR2( 0.0f, 0.0f ) },   { D3DXVECTOR3( 1.0f, 1.0f, -1.0f ), D3DXVECTOR2( 1.0f, 1.0f ), D3DXVECTOR2( 0.0f, 0.0f ) },   { D3DXVECTOR3( 1.0f, 1.0f, 1.0f ), D3DXVECTOR2( 0.0f, 1.0f ), D3DXVECTOR2( 0.0f, 0.0f ) },   { D3DXVECTOR3( -1.0f, -1.0f, -1.0f ), D3DXVECTOR2( 0.0f, 0.0f ), D3DXVECTOR2( 0.0f, 0.0f ) },   { D3DXVECTOR3( 1.0f, -1.0f, -1.0f ), D3DXVECTOR2( 1.0f, 0.0f ), D3DXVECTOR2( 0.0f, 0.0f ) },   { D3DXVECTOR3( 1.0f, 1.0f, -1.0f ), D3DXVECTOR2( 1.0f, 1.0f ), D3DXVECTOR2( 0.0f, 0.0f ) },   { D3DXVECTOR3( -1.0f, 1.0f, -1.0f ), D3DXVECTOR2( 0.0f, 1.0f ), D3DXVECTOR2( 0.0f, 0.0f ) },   { D3DXVECTOR3( -1.0f, -1.0f, 1.0f ), D3DXVECTOR2( 0.0f, 0.0f ), D3DXVECTOR2( 0.0f, 0.0f ) },   { D3DXVECTOR3( 1.0f, -1.0f, 1.0f ), D3DXVECTOR2( 1.0f, 0.0f ), D3DXVECTOR2( 0.0f, 0.0f ) },   { D3DXVECTOR3( 1.0f, 1.0f, 1.0f ), D3DXVECTOR2( 1.0f, 1.0f ), D3DXVECTOR2( 0.0f, 0.0f ) },   { D3DXVECTOR3( -1.0f, 1.0f, 1.0f ), D3DXVECTOR2( 0.0f, 1.0f ), D3DXVECTOR2( 0.0f, 0.0f ) },    };g_NumMeshVerts=24;    D3D10_BUFFER_DESC bd;    bd.Usage = D3D10_USAGE_DEFAULT;    bd.ByteWidth = sizeof( VertexStruct ) * 24;    bd.BindFlags = D3D10_BIND_VERTEX_BUFFER;    bd.CPUAccessFlags = 0;    bd.MiscFlags = 0;    D3D10_SUBRESOURCE_DATA InitData;    InitData.pSysMem = vertices;    V_RETURN( pd3dDevice->CreateBuffer( &bd, &InitData, &g_VertexBuffer ) );    // Set vertex buffer    UINT stride = sizeof( VertexStruct );    UINT offset = 0;    pd3dDevice->IASetVertexBuffers( 0, 1, &g_VertexBuffer, &stride, &offset );    // Create index buffer    // Create vertex buffer    DWORD indices[] =    {   3,1,0,   2,1,3,   6,4,5,   7,4,6,   11,9,8,   10,9,11,   14,12,13,   15,12,14,   19,17,16,   18,17,19,   22,20,21,   23,20,22    };    bd.Usage = D3D10_USAGE_DEFAULT;    bd.ByteWidth = sizeof( DWORD ) * 36;    bd.BindFlags = D3D10_BIND_INDEX_BUFFER;    bd.CPUAccessFlags = 0;    bd.MiscFlags = 0;    InitData.pSysMem = indices;    V_RETURN( pd3dDevice->CreateBuffer( &bd, &InitData, &g_IndexBuffer ) );    Sorry, I really don't know what code to show. I just don't where to look :(   
  When initializing the vertices array, you are initializing the normal with a 2D vector? Shouldn't it be a 3D vector? (That's how you specify it in the layout.)What does VertexStruct look like?Also, you can try using fewer indices to see which triangles are messed up. For example, comment-out all index triples and then start adding each triple to see if the triangle looks correct.BTW, using hard-coded constants (24, 36) for these things is very error prone (especially if you start doing the modifications above). You can set the array size like this:int numVertices = sizeof(vertices) / sizeof(vertices[0]);   ;  Thanks for your reply!This was sample code, but now I fixed that with the normals. I hardcoded those values, because the cube is just a simple test for my sample (To find out why everything looks like that).The VertexStruct looks like this:struct VertexStruct{D3DXVECTOR3 Pos;D3DXVECTOR3 Nrm;D3DXVECTOR2 UV;};And it also seems to be, that even the very first triangle is wrong. hm.   ;  Maybe the problem is in the drawing code. Are you drawing the cube as a triangle list?BTW, looking at the image, it looks like the first triangle is drawn correctly, but not the second one. That's why I thought it might be the drawing code.   ;  Here you go://--------------------------------------------------------------------------------------// Render the scene using the D3D10 device//--------------------------------------------------------------------------------------void CALLBACK OnD3D10FrameRender( ID3D10Device* pd3dDevice, double fTime, float fElapsedTime, void* pUserContext ){    D3DXMATRIX mWorldViewProjection;    D3DXMATRIX mWorld;    D3DXMATRIX mView;    D3DXMATRIX mProj;    float ClearColor[4] = { 0.176f, 0.196f, 0.667f, 0.0f };    ID3D10RenderTargetView* pRTV = DXUTGetD3D10RenderTargetView();    pd3dDevice->ClearRenderTargetView( pRTV, ClearColor );    // Clear the depth stencil    ID3D10DepthStencilView* pDSV = DXUTGetD3D10DepthStencilView();    pd3dDevice->ClearDepthStencilView( pDSV, D3D10_CLEAR_DEPTH, 1.0, 0 );    // If the settings dialog is being shown, then render it instead of rendering the app's scene    if( g_SettingsDlg.IsActive() )    {   g_SettingsDlg.OnRender( fElapsedTime );   return;    }    // Get the projection & view matrix from the camera class    mWorld = *g_Camera.GetWorldMatrix();    mProj = *g_Camera.GetProjMatrix();    mView = *g_Camera.GetViewMatrix();    mWorldViewProjection = mWorld * mView * mProj;    // Update the effect's variables.  Instead of using strings, it would// be more efficient to cache a handle to the parameter by calling// ID3DXEffect::GetParameterByName    g_pmWorldViewProj->SetMatrix( ( float* )&mWorldViewProjection );    g_pmWorld->SetMatrix( ( float* )&mWorld );    g_pfTime->SetFloat( ( float )fTime );   UINT stride = sizeof( VertexStruct);UINT offset = 0;DXUTGetD3D10Device()->IASetVertexBuffers( 0, 1, &g_VertexBuffer, &stride, &offset );DXUTGetD3D10Device()->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST);g_pEffect10->GetTechniqueByIndex(0)->GetPassByIndex(0)->Apply(0); // Set vertex Layout    pd3dDevice->IASetInputLayout( g_pVertexLayout );DXUTGetD3D10Device()->Draw(g_NumMeshVerts,0);    DXUT_BeginPerfEvent( DXUT_PERFEVENTCOLOR, L"HUD / Stats" );    RenderText();    g_HUD.OnRender( fElapsedTime );    g_SampleUI.OnRender( fElapsedTime );    DXUT_EndPerfEvent();}The most is just from that SimpleSample from the SDK.EDIT: I found out: When using Triangle Strips, each side of the cube as one right triangle. Does this help?EDIT2: Fixed it! I was using ->Draw instead of ->DrawIndexed! Stupid typo :([Edited by - mind in a box on June 2, 2010 2:22:29 PM];  I'm taking a lil bit of a guess here but I'm betting your problem is the winding order of your triangles causing every other triangle to get back face culled.Triangle strips when rendered end up reversing the winding on every other triangle because of how they work.The back face culling process, however, takes this into account so it isn't something you have to worry about.If you are manually trying to compensate for the winding reversal, that would cause problems like this.Not sure if this is your problem but it looks pretty suspect (:   ;  I've fixed it already. :) Just read the EDIT2 of my last posting.   