views:

114

answers:

1

I finally managed to get a texture onto a cube sadly, but it is appearing incorrectly. as the below picture identifies.

alt text

Anyways, I am not sure what it could be. My first guess is it could be my uv mapping or my vertex positioning is off. If someone could check and make sure thats good. The first element is the vertex position, second is the color, and third is the uv texture.

struct VertexPos
{
    D3DXVECTOR3 pos;
    D3DXVECTOR4 color;
    D3DXVECTOR3 normal;
    D3DXVECTOR2 texCoord;
};

 // Create vertex buffer
     VertexPos vertices[] =
    {
        // BACK SIDES
        { D3DXVECTOR3(-5.0f,  5.0f, 5.0f), D3DXVECTOR4(1.0f,0.0f,0.0f,0.0f),D3DXVECTOR3(0.0f,0.0f,0.0f) ,D3DXVECTOR2(0.0,0.0)},
        { D3DXVECTOR3(-5.0f, -5.0f, 5.0f), D3DXVECTOR4(1.0f,0.0f,0.0f,0.0f),D3DXVECTOR3(0.0f,0.0f,0.0f) ,D3DXVECTOR2(1.0,1.0)},
        { D3DXVECTOR3(5.0f,  5.0f, 5.0f), D3DXVECTOR4(1.0f,0.0f,0.0f,0.0f),D3DXVECTOR3(0.0f,0.0f,0.0f)  ,D3DXVECTOR2(0.0,1.0)},

        { D3DXVECTOR3(5.0f,  5.0f, 5.0f), D3DXVECTOR4(1.0f,0.0f,0.0f,0.0f),D3DXVECTOR3(0.0f,0.0f,0.0f) ,D3DXVECTOR2(0.0,1.0)},
        { D3DXVECTOR3(-5.0f, -5.0f, 5.0f), D3DXVECTOR4(1.0f,0.0f,0.0f,0.0f),D3DXVECTOR3(0.0f,0.0f,0.0f) ,D3DXVECTOR2(1.0,1.0)},
        { D3DXVECTOR3(5.0f,  -5.0f, 5.0f), D3DXVECTOR4(1.0f,0.0f,0.0f,0.0f),D3DXVECTOR3(0.0f,0.0f,0.0f) ,D3DXVECTOR2(1.0,1.0)},

        // 2 FRONT SIDE
        { D3DXVECTOR3(-5.0f,  5.0f, -5.0f), D3DXVECTOR4(0.0f,1.0f,0.0f,0.0f),D3DXVECTOR3(0.0f,0.0f,0.0f) ,D3DXVECTOR2(0.0,0.0)},
        { D3DXVECTOR3(5.0f,  5.0f, -5.0f), D3DXVECTOR4(0.0f,1.0f,0.0f,0.0f),D3DXVECTOR3(0.0f,0.0f,0.0f)  ,D3DXVECTOR2(1.0,0.0)},
        { D3DXVECTOR3(-5.0f, -5.0f, -5.0f), D3DXVECTOR4(0.0f,1.0f,0.0f,0.0f),D3DXVECTOR3(0.0f,0.0f,0.0f) ,D3DXVECTOR2(0.0,1.0)},

        { D3DXVECTOR3(-5.0f, -5.0f, -5.0f), D3DXVECTOR4(0.0f,1.0f,0.0f,0.0f),D3DXVECTOR3(0.0f,0.0f,0.0f) ,D3DXVECTOR2(0.0,1.0)},
        { D3DXVECTOR3(5.0f,  5.0f, -5.0f), D3DXVECTOR4(0.0f,1.0f,0.0f,0.0f) ,D3DXVECTOR3(0.0f,0.0f,0.0f) ,D3DXVECTOR2(1.0,0.0)},
        { D3DXVECTOR3(5.0f,  -5.0f, -5.0f), D3DXVECTOR4(0.0f,1.0f,0.0f,0.0f),D3DXVECTOR3(0.0f,0.0f,0.0f) ,D3DXVECTOR2(1.0,1.0)},

        // 3
        { D3DXVECTOR3(-5.0f, 5.0f,  5.0f), D3DXVECTOR4(0.0f,0.0f,1.0f,0.0f),D3DXVECTOR3(0.0f,0.0f,0.0f) ,D3DXVECTOR2(0.0,0.0)},
        { D3DXVECTOR3(5.0f, 5.0f,  5.0f),  D3DXVECTOR4(0.0f,0.0f,1.0f,0.0f),D3DXVECTOR3(0.0f,0.0f,0.0f) ,D3DXVECTOR2(1.0,0.0)},
        { D3DXVECTOR3(-5.0f, 5.0f, -5.0f), D3DXVECTOR4(0.0f,0.0f,1.0f,0.0f),D3DXVECTOR3(0.0f,0.0f,0.0f) ,D3DXVECTOR2(0.0,1.0)},

        { D3DXVECTOR3(-5.0f, 5.0f, -5.0f), D3DXVECTOR4(0.0f,0.0f,1.0f,0.0f),D3DXVECTOR3(0.0f,0.0f,0.0f) ,D3DXVECTOR2(0.0,1.0)},
        { D3DXVECTOR3(5.0f, 5.0f, 5.0f), D3DXVECTOR4(0.0f,0.0f,1.0f,0.0f),D3DXVECTOR3(0.0f,0.0f,0.0f) ,D3DXVECTOR2(1.0,0.0)},
        { D3DXVECTOR3(5.0f, 5.0f, -5.0f),  D3DXVECTOR4(0.0f,0.0f,1.0f,0.0f),D3DXVECTOR3(0.0f,0.0f,0.0f) ,D3DXVECTOR2(0.0,1.0)},

        // 4
        { D3DXVECTOR3(-5.0f, -5.0f,  5.0f), D3DXVECTOR4(1.0f,0.5f,0.0f,0.0f),D3DXVECTOR3(0.0f,0.0f,0.0f) ,D3DXVECTOR2(0.0,0.0)},
        { D3DXVECTOR3(-5.0f, -5.0f, -5.0f), D3DXVECTOR4(1.0f,0.5f,0.0f,0.0f),D3DXVECTOR3(0.0f,0.0f,0.0f) ,D3DXVECTOR2(1.0,0.0)},
        { D3DXVECTOR3(5.0f, -5.0f,  5.0f),  D3DXVECTOR4(1.0f,0.5f,0.0f,0.0f),D3DXVECTOR3(0.0f,0.0f,0.0f) ,D3DXVECTOR2(0.0,1.0)},

        { D3DXVECTOR3(5.0f, -5.0f,  5.0f),  D3DXVECTOR4(1.0f,0.5f,0.0f,0.0f),D3DXVECTOR3(0.0f,0.0f,0.0f) ,D3DXVECTOR2(0.0,1.0)},
        { D3DXVECTOR3(-5.0f, -5.0f, -5.0f), D3DXVECTOR4(1.0f,0.5f,0.0f,0.0f),D3DXVECTOR3(0.0f,0.0f,0.0f) ,D3DXVECTOR2(1.0,0.0)},
        { D3DXVECTOR3(5.0f, -5.0f, -5.0f),  D3DXVECTOR4(1.0f,0.5f,0.0f,0.0f),D3DXVECTOR3(0.0f,0.0f,0.0f) ,D3DXVECTOR2(0.0,1.0)},

        // 5
        { D3DXVECTOR3(5.0f,  5.0f, -5.0f), D3DXVECTOR4(0.0f,1.0f,0.5f,0.0f),D3DXVECTOR3(0.0f,0.0f,0.0f) ,D3DXVECTOR2(0.0,0.0)},
        { D3DXVECTOR3(5.0f,  5.0f,  5.0f), D3DXVECTOR4(0.0f,1.0f,0.5f,0.0f),D3DXVECTOR3(0.0f,0.0f,0.0f) ,D3DXVECTOR2(1.0,0.0)},
        { D3DXVECTOR3(5.0f, -5.0f, -5.0f), D3DXVECTOR4(0.0f,1.0f,0.5f,0.0f),D3DXVECTOR3(0.0f,0.0f,0.0f) ,D3DXVECTOR2(0.0,1.0)},

        { D3DXVECTOR3(5.0f, -5.0f, -5.0f), D3DXVECTOR4(0.0f,1.0f,0.5f,0.0f),D3DXVECTOR3(0.0f,0.0f,0.0f) ,D3DXVECTOR2(0.0,1.0)},
        { D3DXVECTOR3(5.0f,  5.0f,  5.0f), D3DXVECTOR4(0.0f,1.0f,0.5f,0.0f),D3DXVECTOR3(0.0f,0.0f,0.0f) ,D3DXVECTOR2(1.0,0.0)},
        { D3DXVECTOR3(5.0f, -5.0f,  5.0f), D3DXVECTOR4(0.0f,1.0f,0.5f,0.0f),D3DXVECTOR3(0.0f,0.0f,0.0f) ,D3DXVECTOR2(0.0,1.0)},

        // 6
        {D3DXVECTOR3(-5.0f,  5.0f, -5.0f), D3DXVECTOR4(0.5f,0.0f,1.0f,0.0f),D3DXVECTOR3(0.0f,0.0f,0.0f) ,D3DXVECTOR2(0.0,0.0)},
        {D3DXVECTOR3(-5.0f, -5.0f, -5.0f), D3DXVECTOR4(0.5f,0.0f,1.0f,0.0f),D3DXVECTOR3(0.0f,0.0f,0.0f) ,D3DXVECTOR2(1.0,0.0)},
        {D3DXVECTOR3(-5.0f,  5.0f,  5.0f), D3DXVECTOR4(0.5f,0.0f,1.0f,0.0f),D3DXVECTOR3(0.0f,0.0f,0.0f) ,D3DXVECTOR2(0.0,1.0)},

        {D3DXVECTOR3(-5.0f,  5.0f,  5.0f), D3DXVECTOR4(0.5f,0.0f,1.0f,0.0f),D3DXVECTOR3(0.0f,0.0f,0.0f) ,D3DXVECTOR2(0.0,1.0)},
        {D3DXVECTOR3(-5.0f, -5.0f, -5.0f), D3DXVECTOR4(0.5f,0.0f,1.0f,0.0f),D3DXVECTOR3(0.0f,0.0f,0.0f) ,D3DXVECTOR2(1.0,0.0)},
        {D3DXVECTOR3(-5.0f, -5.0f,  5.0f), D3DXVECTOR4(0.5f,0.0f,1.0f,0.0f),D3DXVECTOR3(0.0f,0.0f,0.0f) ,D3DXVECTOR2(0.0,1.0)},
    };

My second guess could be an error that I am receiving as I run the program. But I don't know where to begin with that. The following is the description of the error .

D3D10: WARNING: ID3D10Device::Draw: Vertex Buffer at the input vertex slot 0 is not big enough for what the Draw*() call expects to traverse. This is OK, as reading off the end of the Buffer is defined to return 0. However the developer probably did not intend to make use of this behavior.  [ EXECUTION WARNING #356: DEVICE_DRAW_VERTEX_BUFFER_TOO_SMALL ]

Not sure what it could be. but here is my vertex layout description

//Create Layout
D3D10_INPUT_ELEMENT_DESC layout[] = {
    {"POSITION",0,DXGI_FORMAT_R32G32B32_FLOAT, 0 , 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
    {"COLOR",0,DXGI_FORMAT_R32G32B32A32_FLOAT, 0 , 12, D3D10_INPUT_PER_VERTEX_DATA, 0},
    {"NORMAL",0,DXGI_FORMAT_R32G32B32A32_FLOAT, 0 , 28, D3D10_INPUT_PER_VERTEX_DATA, 0},
    {"TEXCOORD",0, DXGI_FORMAT_R32G32_FLOAT, 0 , 44, D3D10_INPUT_PER_VERTEX_DATA, 0}
};

UINT numElements = (sizeof(layout)/sizeof(layout[0]));
modelObject.numVertices = sizeof(vertices)/sizeof(VertexPos);

for(int i = 0; i < modelObject.numVertices; i += 3)
{
    D3DXVECTOR3 out;

    D3DXVECTOR3 v1 = vertices[0 + i].pos;
    D3DXVECTOR3 v2 = vertices[1 + i].pos;
    D3DXVECTOR3 v3 = vertices[2 + i].pos;

    D3DXVECTOR3 u = v2 - v1;
    D3DXVECTOR3 v = v3 - v1;

    D3DXVec3Cross(&out, &u, &v);
    D3DXVec3Normalize(&out, &out);

    vertices[0 + i].normal = out;
    vertices[1 + i].normal = out;
    vertices[2 + i].normal = out;
}

//Create buffer desc
D3D10_BUFFER_DESC bufferDesc;
bufferDesc.Usage = D3D10_USAGE_DEFAULT;
bufferDesc.ByteWidth = sizeof(VertexPos) * modelObject.numVertices;
bufferDesc.BindFlags = D3D10_BIND_VERTEX_BUFFER;
bufferDesc.CPUAccessFlags = 0;
bufferDesc.MiscFlags = 0;

D3D10_SUBRESOURCE_DATA initData;
initData.pSysMem = vertices;
//Create the buffer

HRESULT hr = mpD3DDevice->CreateBuffer(&bufferDesc, &initData, &modelObject.pVertexBuffer);
if(FAILED(hr))
    return false;
+1  A: 

fixed the issue. The problem was in my input layout description still.

D3D10_INPUT_ELEMENT_DESC layout[] = {
    {"POSITION",0,DXGI_FORMAT_R32G32B32_FLOAT, 0 , 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
    {"COLOR",0,DXGI_FORMAT_R32G32B32A32_FLOAT, 0 , 12, D3D10_INPUT_PER_VERTEX_DATA, 0},
    {"NORMAL",0,DXGI_FORMAT_R32G32B32A32_FLOAT, 0 , 28, D3D10_INPUT_PER_VERTEX_DATA, 0},
    {"TEXCOORD",0, DXGI_FORMAT_R32G32_FLOAT, 0 , 44, D3D10_INPUT_PER_VERTEX_DATA, 0}
};

my vertex normal was set to rgba, when it is defined in my vertex struct as a rgb, or xyz. making it in accurate. My offset was wrong too

numerical25