Question

Trying to de-engineer some code I received to figure out how DirectX works. I have a triangle up, and I have figured out how to do everything (change color, size, position..etc) except adding another triangle. i have read extensively on DirectXTutorial.com and I think it has something to do with Vertices, which awesome good, makes sense, however I can't get it to work for me!

To the code below I tried to add more float2's with no luck...

float2 triangleVertices[] =
{
    float2(-0.5f, 0.5f),
    float2(0.0f, 3.5f),
    float2(0.5f, -3.5f), 
    float2(-2.5f, 1.5f),
    float2(2.0f, -3.5f),
    float2(0.5f, 3.5f), 

};

and then I tried this (saw it on a 3D tutorial)

    float2 triangleVertices[] =
    {
        { float2(-0.5f, 0.5f), float2(0.0f, 3.5f), float2(0.5f, -3.5f),}
        { float2(0.5f, -3.5f), float2(0.5f, -3.5f), float2(0.5f, -3.5f),`} 
    };

none of which worked. Any help is appreciated, but I am really looking to see what I am doing wrong, and how to create another triangle. I'll post rest of code below:

        // Create vertex and index buffers that define a simple triangle.

        float2 triangleVertices[] =
        {
            float2(-0.5f, 0.5f),
            float2(0.0f, 3.5f),
            float2(0.5f, -3.5f), 

        };



        unsigned short triangleIndices[] =
        {
            4, 1, 2, 

        };
Was it helpful?

Solution

You need to add both vertex and index, try below code.

float2 triangleVertices[] =
{
    float2(-0.5f, 0.5f),
    float2(0.0f, 3.5f),
    float2(0.5f, -3.5f), 
    float2(-2.5f, 1.5f),
    float2(2.0f, -3.5f),
    float2(0.5f, 3.5f), 
};


unsigned short triangleIndices[] =
{
    0, 1, 2, 
    3, 5, 4
};
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top