XNA Creators Club Online
Page 1 of 1 (6 items)
Sort Posts: Previous Next

UVs problem - Convert from RH system to LH system?

Last post 08-30-2008 6:35 AM by Christopher Pisz. 5 replies.
  • 08-29-2008 5:54 PM

    UVs problem - Convert from RH system to LH system?

    Edit - To Mods: (I cannot get either hyperlinks or images to work in this silly forum editor!!! I even went into HTML and typed the <img src="my url"/> tag myself, and when i go and look at the post and view source, the forum engine totally removed the src attribute. The same with hyperlinks. I tryed using the "hyperlink manager" and typing it manually. Either way, the forum engine took out the href attribute when I view source)

    -------------------------------------------------------

    I am trying to render a textured cube.

    I tryed manually copying the data from my Maya Exporter I wrote as some test data in my engine. I figured out that the data was originally using a right handed coordinate system. I manually altered the vertex positions and normals, according to what I found in MSDN. It said to flip the Zs for vertex positions, normals, and to change (v0, v1, v2) to (v0, v2, v1). However, when rendering my UVs are obviously out of whack. It was perfectly textured in Maya, but the texture is not correct when rendering from my engine.

    Is there something you have to do when converting from right handed to left handed coordinate systems with the UVs? I thought they would be the same, but now I wonder.

    Here is what it looks like in Maya:

    Maya image

    ftp://christopherpisz.is-a-geek.com/pub/images/texturebug/maya.jpg

    Here is what it looks like rendered by my engine:

    Engine image

    ftp://christopherpisz.is-a-geek.com/pub/images/texturebug/engine.jpg

    Here is my data I am using in the engine to render a textured cube:

    EDIT: I don't know if you can see it that well, but the dice dots only appear on the front and back. The sides have a streak of a white stripe, and the top and bottom only appear green.

    // Define vertices of a test shape  
       //  
       // Textured Cube made in Maya  
       //  
       // Created our Vertices by:  
       // 1) Take the face indices that make up a polygon set (in this case there was only 1 polygon set)  
       // 2) Replace those face indices with the face data provided (vertex position index, vertesx normal index,  
       //    uv index from 1 uv Set)   
       // 3) Replace the vertex position index with the actual vertex position  
       // 4) Replace the vertex normal index with the actual vertex normal  
       // 5) Replace the UV index with the actual UV from the specified UV Set  
       //   
       // Maya used a right handed coordinate system  
       // Changed to left handed by:  
       // 1) Inversing the Z axis for vertices and normals  
       // 2) Making vertices appear in clockwise order, instead of counter clockwise  
       //    By taking v0, v1, v2 appear as v0, v2, v1  
       //  
       // Note - Maya uses duplicate vertices for triangles that share an edge  
       //        I am not sure if this can be algorithmically eliminated at this point until more models are  
       //        examined.  
       //   
       // Format is: Vertex Position, Vertex Normal, UV Coordinate  
     
       Vertex_PosNorTex vertices[ =  
       {  
          // Front  
          { D3DXVECTOR3(-0.5f, -0.5f, -0.5f), D3DXVECTOR3( 0.0f,  0.0f, -1.0f), D3DXVECTOR2(0.665054000f, 0.998491000f) },  
          { D3DXVECTOR3(-0.5f,  0.5f, -0.5f), D3DXVECTOR3( 0.0f,  0.0f, -1.0f), D3DXVECTOR2(0.664636000f, 0.748652000f) },  
          { D3DXVECTOR3( 0.5f, -0.5f, -0.5f), D3DXVECTOR3( 0.0f,  0.0f, -1.0f), D3DXVECTOR2(0.332801000f, 0.998073000f) },  
     
          { D3DXVECTOR3( 0.5f, -0.5f, -0.5f), D3DXVECTOR3( 0.0f,  0.0f, -1.0f), D3DXVECTOR2(0.332801000f, 0.998073000f) },  
          { D3DXVECTOR3(-0.5f,  0.5f, -0.5f), D3DXVECTOR3( 0.0f,  0.0f, -1.0f), D3DXVECTOR2(0.664636000f, 0.748652000f) },  
          { D3DXVECTOR3( 0.5f,  0.5f, -0.5f), D3DXVECTOR3( 0.0f,  0.0f, -1.0f), D3DXVECTOR2(0.332383000f, 0.748515000f) },  
     
          // Top  
          { D3DXVECTOR3(-0.5f,  0.5f, -0.5f), D3DXVECTOR3( 0.0f,  1.0f,  0.0f), D3DXVECTOR2(0.664636000f, 0.748652000f) },  
          { D3DXVECTOR3(-0.5f,  0.5f,  0.5f), D3DXVECTOR3( 0.0f,  1.0f,  0.0f), D3DXVECTOR2(0.664103000f, 0.500466000f) },  
          { D3DXVECTOR3( 0.5f,  0.5f, -0.5f), D3DXVECTOR3( 0.0f,  1.0f,  0.0f), D3DXVECTOR2(0.332383000f, 0.748515000f) },  
     
          { D3DXVECTOR3( 0.5f,  0.5f, -0.5f), D3DXVECTOR3( 0.0f,  1.0f,  0.0f), D3DXVECTOR2(0.332383000f, 0.748515000f) },  
          { D3DXVECTOR3(-0.5f,  0.5f,  0.5f), D3DXVECTOR3( 0.0f,  1.0f,  0.0f), D3DXVECTOR2(0.664103000f, 0.500466000f) },  
          { D3DXVECTOR3( 0.5f,  0.5f,  0.5f), D3DXVECTOR3( 0.0f,  1.0f,  0.0f), D3DXVECTOR2(0.331850000f, 0.500133000f) },  
     
          // Back  
          { D3DXVECTOR3(-0.5f,  0.5f,  0.5f), D3DXVECTOR3( 0.0f,  0.0f,  1.0f), D3DXVECTOR2(0.664103000f, 0.500466000f) },  
          { D3DXVECTOR3(-0.5f, -0.5f,  0.5f), D3DXVECTOR3( 0.0f,  0.0f,  1.0f), D3DXVECTOR2(0.663684000f, 0.249599000f) },  
          { D3DXVECTOR3( 0.5f,  0.5f,  0.5f), D3DXVECTOR3( 0.0f,  0.0f,  1.0f), D3DXVECTOR2(0.331850000f, 0.500133000f) },  
     
          { D3DXVECTOR3( 0.5f,  0.5f,  0.5f), D3DXVECTOR3( 0.0f,  0.0f,  1.0f), D3DXVECTOR2(0.331850000f, 0.500133000f) },  
          { D3DXVECTOR3(-0.5f, -0.5f,  0.5f), D3DXVECTOR3( 0.0f,  0.0f,  1.0f), D3DXVECTOR2(0.663684000f, 0.249599000f) },  
          { D3DXVECTOR3( 0.5f, -0.5f,  0.5f), D3DXVECTOR3( 0.0f,  0.0f,  1.0f), D3DXVECTOR2(0.331431000f, 0.250208000f) },  
     
          // Bottom  
          { D3DXVECTOR3(-0.5f, -0.5f,  0.5f), D3DXVECTOR3( 0.0f, -1.0f,  0.0f), D3DXVECTOR2(0.663684000f, 0.249599000f) },  
          { D3DXVECTOR3(-0.5f, -0.5f, -0.5f), D3DXVECTOR3( 0.0f, -1.0f,  0.0f), D3DXVECTOR2(0.663230000f, 0.001333000f) },  
          { D3DXVECTOR3( 0.5f, -0.5f,  0.5f), D3DXVECTOR3( 0.0f, -1.0f,  0.0f), D3DXVECTOR2(0.331431000f, 0.250208000f) },  
     
          { D3DXVECTOR3( 0.5f, -0.5f,  0.5f), D3DXVECTOR3( 0.0f, -1.0f,  0.0f), D3DXVECTOR2(0.331431000f, 0.250208000f) },  
          { D3DXVECTOR3(-0.5f, -0.5f, -0.5f), D3DXVECTOR3( 0.0f, -1.0f,  0.0f), D3DXVECTOR2(0.663230000f, 0.001333000f) },  
          { D3DXVECTOR3( 0.5f, -0.5f, -0.5f), D3DXVECTOR3( 0.0f, -1.0f,  0.0f), D3DXVECTOR2(0.330977000f, 0.001945500f) },  
     
          // Right Side  
          { D3DXVECTOR3( 0.5f, -0.5f, -0.5f), D3DXVECTOR3( 1.0f,  0.0f,  0.0f), D3DXVECTOR2(0.001384540f, 0.748372000f) },  
          { D3DXVECTOR3( 0.5f,  0.5f, -0.5f), D3DXVECTOR3( 1.0f,  0.0f,  0.0f), D3DXVECTOR2(0.332383000f, 0.748515000f) },  
          { D3DXVECTOR3( 0.5f, -0.5f,  0.5f), D3DXVECTOR3( 1.0f,  0.0f,  0.0f), D3DXVECTOR2(0.000774436f, 0.500205000f) },  
     
          { D3DXVECTOR3( 0.5f, -0.5f,  0.5f), D3DXVECTOR3( 1.0f,  0.0f,  0.0f), D3DXVECTOR2(0.000774436f, 0.500205000f) },  
          { D3DXVECTOR3( 0.5f,  0.5f, -0.5f), D3DXVECTOR3( 1.0f,  0.0f,  0.0f), D3DXVECTOR2(0.332383000f, 0.748515000f) },  
          { D3DXVECTOR3( 0.5f,  0.5f,  0.5f), D3DXVECTOR3( 1.0f,  0.0f,  0.0f), D3DXVECTOR2(0.331850000f, 0.500133000f) },  
     
          // Left Side  
          { D3DXVECTOR3(-0.5f, -0.5f,  0.5f), D3DXVECTOR3(-1.0f,  0.0f,  0.0f), D3DXVECTOR2(0.998518000f, 0.499788000f) },  
          { D3DXVECTOR3(-0.5f,  0.5f,  0.5f), D3DXVECTOR3(-1.0f,  0.0f,  0.0f), D3DXVECTOR2(0.664103000f, 0.500466000f) },  
          { D3DXVECTOR3(-0.5f, -0.5f, -0.5f), D3DXVECTOR3(-1.0f,  0.0f,  0.0f), D3DXVECTOR2(0.998102000f, 0.747899000f) },  
     
          { D3DXVECTOR3(-0.5f, -0.5f, -0.5f), D3DXVECTOR3(-1.0f,  0.0f,  0.0f), D3DXVECTOR2(0.998102000f, 0.747899000f) },  
          { D3DXVECTOR3(-0.5f,  0.5f,  0.5f), D3DXVECTOR3(-1.0f,  0.0f,  0.0f), D3DXVECTOR2(0.664103000f, 0.500466000f) },  
          { D3DXVECTOR3(-0.5f,  0.5f, -0.5f), D3DXVECTOR3(-1.0f,  0.0f,  0.0f), D3DXVECTOR2(0.664636000f, 0.748652000f) }  
       };  
     
       // Define indices of a test shape  
       //  
       // Because maya duplicated vertices with shared edges, the indices are simply in consecutive order  
       // from 0 to the number of vertices - 1  
       //   
       // Note - If it is possible to eliminate duplicate vertices algorithmically, the index buffer will be  
       //        altered to actually be useful.  
     
       unsigned int indices[ =  
       {  
          // Front  
           0,  1,  2,  
           3,  4,  5,  
             
          // Top  
           6,  7,  8,  
           9, 10, 11,  
            
          // Back  
          12, 13, 14,  
          15, 16, 17,  
     
          // Bottom  
          18, 19, 20,  
          21, 22, 23,  
     
          // Right  
          24, 25, 26,  
          27, 28, 29,  
     
          // Left  
          30, 31, 32,  
          33, 34, 35,  
       };  
     
       // Create the test shape  
       m_object3D = new SimpleObject3D(*m_d3dDevice);  
       m_object3D->SetGeometry(vertices, 36, indices, 36, "Textures//dice.png");  
       m_object3D->SetPosition(D3DXVECTOR3( 0.0f, 5.0f, 0.0f));  
     

    And here is the original data:

    1 ----------------------------------------  
    2 // Mesh Name  
    3 pCubeShape1  
    4  
    5 // Vertices  
    6 //   
    7 // Format:  
    8 // v[index] x y z  
    9 v[0] -0.5 -0.5 0.5  
    10 v[1] 0.5 -0.5 0.5  
    11 v[2] -0.5 0.5 0.5  
    12 v[3] 0.5 0.5 0.5  
    13 v[4] -0.5 0.5 -0.5  
    14 v[5] 0.5 0.5 -0.5  
    15 v[6] -0.5 -0.5 -0.5  
    16 v[7] 0.5 -0.5 -0.5  
    17  
    18 // Colors  
    19 //   
    20 // Format:  
    21 // c[index] r g b a  
    22 c[0] -1 -1 -1 -1  
    23 c[1] -1 -1 -1 -1  
    24 c[2] -1 -1 -1 -1  
    25 c[3] -1 -1 -1 -1  
    26 c[4] -1 -1 -1 -1  
    27 c[5] -1 -1 -1 -1  
    28 c[6] -1 -1 -1 -1  
    29 c[7] -1 -1 -1 -1  
    30 c[8] -1 -1 -1 -1  
    31 c[9] -1 -1 -1 -1  
    32 c[10] -1 -1 -1 -1  
    33 c[11] -1 -1 -1 -1  
    34 c[12] -1 -1 -1 -1  
    35 c[13] -1 -1 -1 -1  
    36 c[14] -1 -1 -1 -1  
    37 c[15] -1 -1 -1 -1  
    38 c[16] -1 -1 -1 -1  
    39 c[17] -1 -1 -1 -1  
    40 c[18] -1 -1 -1 -1  
    41 c[19] -1 -1 -1 -1  
    42 c[20] -1 -1 -1 -1  
    43 c[21] -1 -1 -1 -1  
    44 c[22] -1 -1 -1 -1  
    45 c[23] -1 -1 -1 -1  
    46 c[24] -1 -1 -1 -1  
    47 c[25] -1 -1 -1 -1  
    48 c[26] -1 -1 -1 -1  
    49 c[27] -1 -1 -1 -1  
    50 c[28] -1 -1 -1 -1  
    51 c[29] -1 -1 -1 -1  
    52 c[30] -1 -1 -1 -1  
    53 c[31] -1 -1 -1 -1  
    54 c[32] -1 -1 -1 -1  
    55 c[33] -1 -1 -1 -1  
    56 c[34] -1 -1 -1 -1  
    57 c[35] -1 -1 -1 -1  
    58  
    59 // Normals  
    60 //   
    61 // Format:  
    62 // n[index] x y z  
    63 n[0] 0 0 1  
    64 n[1] 0 0 1  
    65 n[2] 0 0 1  
    66 n[3] 0 0 1  
    67 n[4] 0 1 0  
    68 n[5] 0 1 0  
    69 n[6] 0 1 0  
    70 n[7] 0 1 0  
    71 n[8] 0 0 -1  
    72 n[9] 0 0 -1  
    73 n[10] 0 0 -1  
    74 n[11] 0 0 -1  
    75 n[12] 0 -1 0  
    76 n[13] 0 -1 0  
    77 n[14] 0 -1 0  
    78 n[15] 0 -1 0  
    79 n[16] 1 0 0  
    80 n[17] 1 0 0  
    81 n[18] 1 0 0  
    82 n[19] 1 0 0  
    83 n[20] -1 0 0  
    84 n[21] -1 0 0  
    85 n[22] -1 0 0  
    86 n[23] -1 0 0  
    87  
    88 // UV Set  
    89 //   
    90 // Format:  
    91 // Set Name  
    92 // uv[index] u v  
    93 map1  
    94 uv[0] 0.998102, 0.747899  
    95 uv[1] 0.332801, 0.998073  
    96 uv[2] 0.664636, 0.748652  
    97 uv[3] 0.332383, 0.748515  
    98 uv[4] 0.664103, 0.500466  
    99 uv[5] 0.33185, 0.500133  
    100 uv[6] 0.663684, 0.249599  
    101 uv[7] 0.331431, 0.250208  
    102 uv[8] 0.66323, 0.001333  
    103 uv[9] 0.330977, 0.0019455  
    104 uv[10] 0.000774436, 0.500205  
    105 uv[11] 0.00138454, 0.748372  
    106 uv[12] 0.998518, 0.499788  
    107 uv[13] 0.665054, 0.998491  
    108  
    109  
    110 // Polygon Set  
    111 //   
    112 // Format:  
    113 // Polygon Set Name  
    114 // Texture Filepath  
    115 // Faces Indices  
    116 blinn1SG  
    117 c:/Users/cpisz.HOMENETWORK/Documents/Visual Studio 2005/Projects/Maya_Import/dice.png  
    118 0 1 2 3 4 5 6 7 8 9 10 11   
    119  
    120  
    121 // Faces  
    122 //   
    123 // Format:  
    124 // 'Face Index' 'Vertex Index' 'Normal Index' 'Color Index' 'UV Index - map1'  
    125 0 0 0 0 13  
    126 0 1 1 1 1  
    127 0 2 2 2 2  
    128  
    129 1 1 1 3 1  
    130 1 3 3 4 3  
    131 1 2 2 5 2  
    132  
    133 2 2 4 6 2  
    134 2 3 5 7 3  
    135 2 4 6 8 4  
    136  
    137 3 3 5 9 3  
    138 3 5 7 10 5  
    139 3 4 6 11 4  
    140  
    141 4 4 8 12 4  
    142 4 5 9 13 5  
    143 4 6 10 14 6  
    144  
    145 5 5 9 15 5  
    146 5 7 11 16 7  
    147 5 6 10 17 6  
    148  
    149 6 6 12 18 6  
    150 6 7 13 19 7  
    151 6 0 14 20 8  
    152  
    153 7 7 13 21 7  
    154 7 1 15 22 9  
    155 7 0 14 23 8  
    156  
    157 8 1 16 24 11  
    158 8 7 17 25 10  
    159 8 3 18 26 3  
    160  
    161 9 7 17 27 10  
    162 9 5 19 28 5  
    163 9 3 18 29 3  
    164  
    165 10 6 20 30 12  
    166 10 0 21 31 0  
    167 10 4 22 32 4  
    168  
    169 11 0 21 33 0  
    170 11 2 23 34 2  
    171 11 4 22 35 4  
    172  
    173  

     

    I am just guessing that this is the problem. Could there be some other problem causing this?

    I am really at a loss as to how to figure this out.

     

    Could it be my shader code?

    //--------------------------------------------------------------------------------------  
    // File: default.fx  
    //  
    //--------------------------------------------------------------------------------------  
     
    Texture2D textureDiffuse;  
     
    SamplerState samplerLinear  
    {  
       Filter = MIN_MAG_MIP_LINEAR;  
       AddressU = Wrap;  
       AddressV = Wrap;  
    };  
     
    //--------------------------------------------------------------------------------------  
    // Constant Buffer Variables  
    matrix World;  
    matrix View;  
    matrix Projection;  
     
    float4 LightDirs[2];  
    float4 LightColors[2];  
     
    //--------------------------------------------------------------------------------------  
    struct VS_INPUT  
    {  
       float4 Pos : POSITION;  
       float3 Norm : NORMAL;  
       float2 UV : TEXCOORD;  
    };  
     
    struct PS_INPUT  
    {  
       float4 Pos : SV_POSITION;  
       float3 Norm : NORMAL;  
       float2 UV : TEXCOORD;  
    };  
     
    //--------------------------------------------------------------------------------------  
    // Vertex Shader  
    //--------------------------------------------------------------------------------------  
     
    //--------------------------------------------------------------------------------------  
    // Simply transforms positions and normals  
    //   
    PS_INPUT VS( VS_INPUT input )  
    {  
       PS_INPUT output = (PS_INPUT)0;  
       output.Pos   = mul( input.Pos, World );  
       output.Pos   = mul( output.Pos, View );  
       output.Pos   = mul( output.Pos, Projection);  
       output.Norm  = mul( input.Norm, World );   
       output.UV    = input.UV;  
         
       return output;  
    }  
     
     
    //--------------------------------------------------------------------------------------  
    // Pixel Shaders  
    //--------------------------------------------------------------------------------------  
     
    //--------------------------------------------------------------------------------------  
    // Shades an object using 2 colored directional lights  
    //  
    float4 PS( PS_INPUT input ) : SV_Target  
    {  
       float4 finalColor = 0;  
         
       // Do N dot L lighting for 2 lights  
       for(int i = 0; i < 2; i++)  
       {  
          finalColor += saturate( dot( (float3)LightDirs[i],input.Norm) * LightColors[i] );  
       }  
         
       finalColor *= textureDiffuse.Sample(samplerLinear, input.UV);  
       finalColor.a = 1;  
         
       return finalColor;  
    }  
     
    //--------------------------------------------------------------------------------------  
    // Techniques  
    //--------------------------------------------------------------------------------------  
     
    //--------------------------------------------------------------------------------------  
    // Renders an object using 2 directional lights  
    //  
    technique10 Render  
    {  
        pass P0  
        {  
            SetVertexShader( CompileShader( vs_4_0, VS() ) );  
            SetGeometryShader( NULL );  
            SetPixelShader( CompileShader( ps_4_0, PS() ) );  
        }  

     

    Could it be the vertex structure?

    //--------------------------------------------------------------------------------  
    class Vertex_PosNorTex  
    {  
    public:  
     
       /** 
       * Gets the input layout associated with this vertex format
       *
       * The input layout is used to tell DirectX how to read the input buffers
       * provided to it for rendering. The input layout must be set on a device
       * before an object is rendered.
       *
       * Release of the input layout object is left to the caller.
       */ 
       static ID3D10InputLayout * GetInputLayout(ID3D10Device & d3dDevice,  
                                                 ID3D10EffectTechnique & technique);  
       D3DXVECTOR3 m_pos;    // Position  
       D3DXVECTOR3 m_normal; // Normal  
       D3DXVECTOR2 m_uv;     // Texture Coordinate  
    }; 

     

    Could it be my input layout?

    //-----------------------------------------------------------------  
    ID3D10InputLayout * Vertex_PosNorTex::GetInputLayout(ID3D10Device & d3dDevice,  
                                                         ID3D10EffectTechnique & technique)  
    {  
       // Define the vertex input layout in GPU memory  
       D3D10_INPUT_ELEMENT_DESC vertexDesc[ =   
       {  
          {  
             "POSITION",                    // The HLSL Semantic associated with this element in the shader code  
             0,                             // Semantic Index for the element when there is more than one  
             DXGI_FORMAT_R32G32B32_FLOAT,   // Data type of the element  
             0,                             // Input Assembler Slot. Between 0 and 15  
             D3D10_APPEND_ALIGNED_ELEMENT,  // Optional, offset in bytes between each element  
             D3D10_INPUT_PER_VERTEX_DATA,   // Input data class for a single input slot. See D3D10_INPUT_CLASSIFICATION  
             0                              // Used when data class is D3D10_INPUT_PER_INSTANCE_DATA  
          },  
     
          {  
             "NORMAL",  
             0,  
             DXGI_FORMAT_R32G32B32_FLOAT,  
             0,  
             0,  
             D3D10_INPUT_PER_VERTEX_DATA,  
             0  
          },  
     
          {  
             "TEXCOORD",  
             0,  
             DXGI_FORMAT_R32G32_FLOAT,  
             0,  
             0,  
             D3D10_INPUT_PER_VERTEX_DATA,  
             0  
          }  
       };  
     
       UINT numVertexDescElements = sizeof(vertexDesc) / sizeof(vertexDesc[0]);  
     
       // Create the input layout  
       D3D10_PASS_DESC passDesc;  
       technique.GetPassByIndex(0)->GetDesc(&passDesc);  
         
       ID3D10InputLayout * inputLayout;  
     
       if( FAILED(d3dDevice.CreateInputLayout(vertexDesc,  
                                              numVertexDescElements,  
                                              passDesc.pIAInputSignature,  
                                              passDesc.IAInputSignatureSize,  
                                              &inputLayout)) )  
       {  
          throw BaseException("Failed to create input layout",   
                              "ID3D10InputLayout * Vertex_PosNorTex::GetInputLayout(ID3D10Device & d3dDevice, ID3D10EffectTechnique & technique)",  
                              "Vertices3D.cpp");  
       }  
     
       return inputLayout;  

     

    Could it be the setting of the vertex, index, and texture resource view?

     

    //-----------------------------------------------------------------  
    void SimpleObject3D::SetGeometry(const Vertex_PosNorTex * vertices, unsigned int num_vertices,  
                                     const unsigned int * indices, unsigned int num_indices,  
                                     const std::string & texturePath)  
    {  
       static const std::string method = "void SimpleObject3D::SetGeometry(const Vertex_PosNorTex * vertices, " 
          + std::string("unsigned int num_vertices, const unsigned int * indices, unsigned int num_indices, ")   
          + std::string("const std::string & texturePath)");  
     
       static const std::string file = "SimpleObject3D.cpp";  
     
     
       // Release any texture resource that may already exist  
       if( m_textureResourceView )  
       {  
          m_textureResourceView->Release();  
          m_textureResourceView = NULL;  
       }  
     
       // Release any vertex buffer that may already exist  
       if( m_vertexBuffer )  
       {  
          m_vertexBuffer->Release();  
          m_vertexBuffer = NULL;  
       }  
     
       // Release any index buffer that may already exist  
       if( m_indexBuffer )  
       {  
          m_indexBuffer->Release();  
          m_indexBuffer = NULL;  
          m_numIndices = 0;  
       }  
     
       // Describe the new vertex buffer to use  
       D3D10_BUFFER_DESC bd;  
       bd.Usage          = D3D10_USAGE_DEFAULT;  
       bd.ByteWidth      = sizeof(Vertex_PosNorTex) * num_vertices;  
       bd.BindFlags      = D3D10_BIND_VERTEX_BUFFER;  
       bd.CPUAccessFlags = 0;  
       bd.MiscFlags      = 0;  
         
       // Provide the vertices for the new vertex buffer  
       D3D10_SUBRESOURCE_DATA InitData;  
       InitData.pSysMem = vertices;  
         
       // Create the new vertex buffer with the provided vertices  
       if( FAILED(m_d3dDevice.CreateBuffer(&bd, &InitData, &m_vertexBuffer)) )  
       {  
          throw BaseException("Failed to create vertex buffer", method, file);  
       }  
     
       // Describe the new index buffer to use  
       bd.Usage          = D3D10_USAGE_DEFAULT;  
       bd.ByteWidth      = sizeof(unsigned int) * num_indices;  
       bd.BindFlags      = D3D10_BIND_INDEX_BUFFER;  
       bd.CPUAccessFlags = 0;  
       bd.MiscFlags      = 0;  
     
       // Provide the indices for the new index buffer  
       InitData.pSysMem = indices;  
       m_numIndices = num_indices;  
         
       // Create the new index buffer with the provided vertices  
       if( FAILED(m_d3dDevice.CreateBuffer(&bd, &InitData, &m_indexBuffer)) )  
       {  
          throw BaseException("Failed to create index buffer", method, file);  
       }  
     
       // Create the texture resource  
       if( FAILED(D3DX10CreateShaderResourceViewFromFile(&m_d3dDevice,  
                                                         texturePath.c_str(),  
                                                         NULL,  
                                                         NULL,  
                                                         &m_textureResourceView,  
                                                         NULL)) )  
       {  
          throw BaseException("Failed to create resource view", method, file);  
       }  
     
       // Define the vertex input layout in GPU memory  
       m_vertexLayout = Vertex_PosNorTex::GetInputLayout(m_d3dDevice, *m_technique);  
     
       if( !m_vertexLayout )  
       {  
          throw BaseException("Failed to create input layout", method, file);  
       }  
     
       // Update the texture variable in the shader  
       m_effectVariable_textureDiffuse->SetResource(m_textureResourceView);  

     

    Could it be my rendering, particularly stride and offset?

    //-----------------------------------------------------------------  
    void SimpleObject3D::Render(BaseCamera * camera,  
                                D3DXVECTOR4 lightDirs[2],  
                                D3DXVECTOR4 lightColors[2])  
    {  
       if( m_needUpdated )  
       {  
          Update();