Drawing Shape on top of Sprites

Started by
30 comments, last by nlraley 13 years, 5 months ago
Thanks, I should be able to get something like that working pretty easy. I technically already have the points and everything indexed, b/c each object I will be using drawprimitive for is an object that I have its coordinates for. It's just a matter of dynamically using the buffer now.

I still don't have my blending working the way I want it however. What do I have to do to have the rectangle be solid red with a transparency? Right now it has a transparency but its the equivalent of having a gradient. I am just wanting solid color with partial transparency to the background. Do I have one of the options set wrong?
Advertisement
Quote:Original post by nlraley
I still don't have my blending working the way I want it however. What do I have to do to have the rectangle be solid red with a transparency? Right now it has a transparency but its the equivalent of having a gradient. I am just wanting solid color with partial transparency to the background. Do I have one of the options set wrong?
Your current setup will blend the texture and diffuse alpha - do you have a texture set? Does it make any difference if you call device->SetTexture(NULL); before rendering your rectangles?
Ah, that could be it. I wasn't wanting to load a texture into the quad. I wanted the quad to be a solid color and diffuse it with the sprites loaded into the background.

Will setting the texture to null mess up the sprites?
It looks like the parts of your Vertex struct are in the wrong order. If you specified

D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1

as your vertex shader, then the data in the vertex buffer needs to be in this order:

float x
float y
float z
float rhw
D3DCOLOR diffuse
float u
float v

I think you've got your UV values before your diffuse values, so it's reading the wrong numbers for the wrong properties.

The good news is that, because you're seeing the gradient, you've got alpha blending set up properly.
Jon Hellebuyck - Mode13.com
Ah, that could be it and would explain why it appeared to be fading into black. I had my structure defined in a different order than that which is the reason I had them in a different order. I should have caught that one. Let me give it a try.

*edit*
Changing the order results in no rectangle being drawn at all.

*edit*
Never mind, I forgot that while messing around with various settings I had changed my vector format. Now I have a solid blue rectangle.

*final edit*
I forgot that I had disabled the call to the device settings, therefore my rendering wasn't being set up. Its all up and running now. Thanks guys.

The solution was to set the device settings as follows:
if (FAILED(hr = d3d9Device->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE)))                  return hr;        if (FAILED(hr = d3d9Device->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA)))             return hr;        if (FAILED(hr = d3d9Device->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA)))         return hr;        if (FAILED(hr = d3d9Device->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE)))      return hr;


Followed by defining my Vector in this order, yes order does matter:
typedef struct{    FLOAT x, y, z, rhw; // The transformed position for the vertex    DWORD color;        // The vertex color    FLOAT tu, ty;} Vertex;


And finally creating the rectangle as follows:
Vertex vertices[] =        {            {Data->Zones.i->dxPosition[0].X, Data->Zones.i->dxPosition[0].Y, 0.0f, 0.0f, 0x7f0000ff, 0, 0},            {Data->Zones.i->dxPosition[1].X, Data->Zones.i->dxPosition[1].Y, 0.0f, 0.0f, 0x7f0000ff, 1, 0 },            {Data->Zones.i->dxPosition[2].X, Data->Zones.i->dxPosition[2].Y, 0.0f, 0.0f, 0x7f0000ff, 0, 1 },            {Data->Zones.i->dxPosition[3].X, Data->Zones.i->dxPosition[3].Y, 0.0f, 0.0f, 0x7f0000ff, 1, 1 }        };if( FAILED( d3d9Device->CreateVertexBuffer(            4 * sizeof( Vertex ),		//  Length            0,							//  Usage -            D3DFVF_TLVERTEX,			//  Specifies Vertex Format            D3DPOOL_MANAGED,			//  D3DPool            &d3d9VertexBuffer,  		//  Pointer to the Direct3D Vertex Buffer            NULL						//  HANDLE        ) ) )        {            //-------------------            return E_FAIL;            //-------------------        }        //-------------------        if( FAILED( d3d9VertexBuffer->Lock( 0, sizeof( vertices ), ( void** )&pVertices, 0 ) ) )            return E_FAIL;        memcpy( pVertices, vertices, sizeof( vertices ) );        d3d9VertexBuffer->Unlock();        //-------------------        d3d9Device->SetStreamSource( 0, d3d9VertexBuffer, 0, sizeof( Vertex ) );        d3d9Device->SetFVF( D3DFVF_TLVERTEX );        //-------------------        if (FAILED( hr = d3d9Device->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 2 ) ) )        {            const char* szError = DXGetErrorDescription9(hr);            MessageBox (MainForm->Handle, szError, "Error", MB_OK );            return E_FAIL;        }        //-------------------


[Edited by - nlraley on October 26, 2010 3:57:56 PM]
Can we see your vertex struct and FVF?

Quote:Original post by nlraley
Will setting the texture to null mess up the sprites?
Nope - null means "no texture", so nothing to blend with, and ID3DXSprite will call SetTexture internally as required for any sprites you draw with it.

EDIT: Or just set D3DTSS_ALPHAOP to D3DTOP_SELECTARG2 to select the default 2nd argument (D3DTA_CURRENT) instead of modulating it with the texture.

EDIT #2:
Quote:Original post by nlraley
*edit*
Never mind, I forgot that while messing around with various settings I had changed my vector format. Now I have a solid blue rectangle.
What do you have for your current diffuse colour? 0xff0000ff? The first 2 hex digits is the alpha value. Try D3DCOLOR_ARGB(128, 0, 0, 255) instead (Equivalent to 0x800000ff).
Yea, I posted the changed values.

What was wrong was I defined my structure for the vertices in a different order, not putting the connection that the parameters I was passing were telling it the order in which it was expecting the values.

I had my structure defining x,y,z,rwh,tu,ty,color. I was passing the vertex parameters in this order, but defining my D3DFVF_TLVERTEX it was taking (D3DFVF_XYZRHW|D3DFVF_DIFFUSE|D3DFVF_TEX1), hence expecting it as x,y,z,rhw,color,tu,ty, which was not the order I was sending it in.

I had previously set the alpha to ff to see if I could get a solid rectangle, which once I turned on the device settings to allow the alpha, ff wasn't even creating a solid rectangle.

Thankfully Jon was able to catch the order situation and once I re-enabled everything correctly, I set my alpha to something like 7f, and everything worked just fine.

One final question, when resetting the device for the map pan, I'm getting an invalid call once again after implementing these primitives. I'm assuming it is b/c I need to release the vertex buffer? How do you go about resetting that?

And the vertex structure working correctly is as follows:
typedef struct{    FLOAT x, y, z, rhw; // The transformed position for the vertex    DWORD color;        // The vertex color    FLOAT tu, ty;} Vertex;


[Edited by - nlraley on October 26, 2010 3:39:16 PM]
Quote:Original post by Evil Steve
Quote:Original post by nlraley
Creating the indexed triangle list.


Untested:
*** Source Snippet Removed ***
And at shutdown time, remember to Release() pIndexBuffer.


I am slightly understanding this concept, but I am stuck on one part of this. We define our indices, but where/how do you set the points for these vertices? I was trying to find an example of this, but haven't been able to see where/how they actually define the vertices. Do you still use the vertex buffer, because I don't see where they reference it at all, they only reference the index buffer; however, I never see where they define the vertices for the index buffer, just the indices?

*edit
Is this done with setting the stream source?

*edit*
I think I am starting to understand it. You create the index buffer before hand alotting enough space for as much needed for 1024 rectangles. Then you have your vertex buffer the same size. You assign the Vertices to the vertex buffer as before. Set the vertex buffer as the stream source. Then render the Index buffer which runs through it all at one pass?

[Edited by - nlraley on October 26, 2010 3:23:18 PM]
Okay, been working around with this indexed buffer concept and haven't gotten it to work just yet.

Here is where I initialize my buffers:
HRESULT _Direct3D::InitBuffers(){    //-------------------    WORD* pIndices;    //-------------------    // Create the Index Buffer. Here we are allocating enough memory    // (from the managed pool) to hold up to 1024 Rectangles.  Each    // rectangle is composed of 2 triangles, each with 3 vertices.    //-------------------    if (FAILED(hr = d3d9Device->CreateIndexBuffer(        sizeof(WORD)*MAX_RECTS*6,           //  Length        D3DUSAGE_WRITEONLY,                 //  Usage        D3DFMT_INDEX16,			            //  Specifies Format        D3DPOOL_MANAGED,                    //  D3D Pool        &d3d9IndexBuffer,                   //  IDirect3DIndexBuffer9        NULL                                //  Handle    ) ) )    {        const char* szError = DXGetErrorDescription9(hr);        MessageBox (MainForm->Handle, szError, "Error", MB_OK );        return E_FAIL;    }    //-------------------  Lock the Index Buffer    if ( FAILED( hr = d3d9IndexBuffer->Lock(0, 0, (void**)&pIndices, 0) ) )        return hr;    //-------------------  Fill the Indices    for ( int i = 0; i < MAX_RECTS; ++i )    {       //-------------------  First triangle (top left, top right, bottom left)       *pIndices++ = i*4;       *pIndices++ = i*4 + 1;       *pIndices++ = i*4 + 2;       //-------------------  Second triangle (top right, bottom right, bottom left)       *pIndices++ = i*4 + 1;       *pIndices++ = i*4 + 3;       *pIndices++ = i*4 + 2;    }    //-------------------  Unlock the Index Buffer    d3d9IndexBuffer->Unlock();    //-------------------    // Create the vertex buffer. Here we are allocating enough memory    // (from the default pool) to hold all our 3 custom vertices. We also    // specify the FVF, so the vertex buffer knows what data it contains.    //-------------------    if( FAILED( d3d9Device->CreateVertexBuffer(        sizeof(WORD)*MAX_RECTS*6,		    //  Length        0,							        //  Usage        D3DFVF_TLVERTEX,			        //  Specifies Vertex Format        D3DPOOL_MANAGED,			        //  D3DPool        &d3d9VertexBuffer,  		        //  Pointer to the Direct3D Vertex Buffer        NULL					        	//  HANDLE    ) ) )    {        //-------------------        return hr;        //-------------------    }    return hr;    //-------------------}//-------------------


Then on my render call I call this function to draw my rectangles:
HRESULT _Direct3D::DrawZones(){    //-------------------    bool first = false;    WORD* pIndices;    int num_rectangles = 0;    int i = 0;    //-------------------    Direct3DDeviceSettings(true);    //-------------------  Iterate through the Zones    Data->Zones.whileFirst();    while ( Data->Zones.whileNext() && !first )    {        //-------------------  First triangle top left        vertices.x = Data-&gt;Zones.i-&gt;dxPosition[<span class="cpp-number">1</span>].X;<br>        vertices.y = Data-&gt;Zones.i-&gt;dxPosition[<span class="cpp-number">1</span>].Y;<br>        vertices.z = <span class="cpp-number">0</span>.0f;<br>        vertices.rhw = <span class="cpp-number">0</span>.0f;<br>        vertices.color = D3DCOLOR_ARGB(<span class="cpp-number">127</span>, <span class="cpp-number">0</span>, <span class="cpp-number">0</span>, <span class="cpp-number">255</span>);<br>        vertices.tu = <span class="cpp-number">1</span>;<br>        vertices.ty = <span class="cpp-number">0</span>;<br>        <span class="cpp-comment">//——————-  First triangle top right</span><br>        vertices.x = Data-&gt;Zones.i-&gt;dxPosition[<span class="cpp-number">3</span>].X;<br>        vertices.y = Data-&gt;Zones.i-&gt;dxPosition[<span class="cpp-number">3</span>].Y;<br>        vertices.z = <span class="cpp-number">0</span>.0f;<br>        vertices.rhw = <span class="cpp-number">0</span>.0f;<br>        vertices.color = D3DCOLOR_ARGB(<span class="cpp-number">127</span>, <span class="cpp-number">0</span>, <span class="cpp-number">0</span>, <span class="cpp-number">255</span>);<br>        vertices.tu = <span class="cpp-number">1</span>;<br>        vertices.ty = <span class="cpp-number">1</span>;<br>        <span class="cpp-comment">//——————-  First triangle bottom left</span><br>        vertices.x = Data-&gt;Zones.i-&gt;dxPosition[<span class="cpp-number">0</span>].X;<br>        vertices.y = Data-&gt;Zones.i-&gt;dxPosition[<span class="cpp-number">0</span>].Y;<br>        vertices.z = <span class="cpp-number">0</span>.0f;<br>        vertices.rhw = <span class="cpp-number">0</span>.0f;<br>        vertices.color = D3DCOLOR_ARGB(<span class="cpp-number">127</span>, <span class="cpp-number">0</span>, <span class="cpp-number">0</span>, <span class="cpp-number">255</span>);<br>        vertices.tu = <span class="cpp-number">0</span>;<br>        vertices.ty = <span class="cpp-number">0</span>;<br>        <span class="cpp-comment">//——————-  Second triangle top right</span><br>        vertices.x = Data-&gt;Zones.i-&gt;dxPosition[<span class="cpp-number">3</span>].X;<br>        vertices.y = Data-&gt;Zones.i-&gt;dxPosition[<span class="cpp-number">3</span>].Y;<br>        vertices.z = <span class="cpp-number">0</span>.0f;<br>        vertices.rhw = <span class="cpp-number">0</span>.0f;<br>        vertices.color = D3DCOLOR_ARGB(<span class="cpp-number">127</span>, <span class="cpp-number">0</span>, <span class="cpp-number">0</span>, <span class="cpp-number">255</span>);<br>        vertices.tu = <span class="cpp-number">1</span>;<br>        vertices.ty = <span class="cpp-number">1</span>;<br>        <span class="cpp-comment">//——————-  Second triangle bottom right</span><br>        vertices.x = Data-&gt;Zones.i-&gt;dxPosition[<span class="cpp-number">2</span>].X;<br>        vertices.y = Data-&gt;Zones.i-&gt;dxPosition[<span class="cpp-number">2</span>].Y;<br>        vertices.z = <span class="cpp-number">0</span>.0f;<br>        vertices.rhw = <span class="cpp-number">0</span>.0f;<br>        vertices.color = D3DCOLOR_ARGB(<span class="cpp-number">127</span>, <span class="cpp-number">0</span>, <span class="cpp-number">0</span>, <span class="cpp-number">255</span>);<br>        vertices.tu = <span class="cpp-number">0</span>;<br>        vertices.ty = <span class="cpp-number">1</span>;<br>        <span class="cpp-comment">//——————-  Second triangle bottom left</span><br>        vertices.x = Data-&gt;Zones.i-&gt;dxPosition[<span class="cpp-number">0</span>].X;<br>        vertices.y = Data-&gt;Zones.i-&gt;dxPosition[<span class="cpp-number">0</span>].Y;<br>        vertices.z = <span class="cpp-number">0</span>.0f;<br>        vertices.rhw = <span class="cpp-number">0</span>.0f;<br>        vertices.color = D3DCOLOR_ARGB(<span class="cpp-number">127</span>, <span class="cpp-number">0</span>, <span class="cpp-number">0</span>, <span class="cpp-number">255</span>);<br>        vertices.tu = <span class="cpp-number">0</span>;<br>        vertices.ty = <span class="cpp-number">0</span>;<br>        <span class="cpp-comment">//——————-</span><br>        num_rectangles++;<br>        first = <span class="cpp-keyword">true</span>;<br>        <span class="cpp-comment">//——————-</span><br>    }<br>    <span class="cpp-comment">//——————-</span><br>    <span class="cpp-keyword">if</span>( FAILED( d3d9VertexBuffer-&gt;Lock( <span class="cpp-number">0</span>, <span class="cpp-keyword">sizeof</span>( vertices ), ( <span class="cpp-keyword">void</span>** )&amp;pIndices, <span class="cpp-number">0</span> ) ) )<br>        <span class="cpp-keyword">return</span> E_FAIL;<br>    <span class="cpp-comment">//memcpy( pVertices, vertices, sizeof( vertices ) );</span><br>    d3d9VertexBuffer-&gt;Unlock();<br>    <span class="cpp-comment">//——————-</span><br>    d3d9Device-&gt;SetStreamSource( <span class="cpp-number">0</span>, d3d9VertexBuffer, <span class="cpp-number">0</span>, <span class="cpp-keyword">sizeof</span>( Vertex ) );<br>    d3d9Device-&gt;SetFVF( D3DFVF_TLVERTEX );<br>    <span class="cpp-comment">//——————-</span><br>    d3d9Device-&gt;SetIndices(d3d9IndexBuffer);<br>    <span class="cpp-comment">//——————-</span><br>    <span class="cpp-keyword">if</span> (FAILED(hr = d3d9Device-&gt;DrawIndexedPrimitive(<br>        D3DPT_TRIANGLELIST,<br>        <span class="cpp-number">0</span>,<br>        <span class="cpp-number">0</span>,<br>        num_rectangles*<span class="cpp-number">4</span>,<br>        <span class="cpp-number">0</span>,<br>        num_rectangles*<span class="cpp-number">2</span><br>    ) ) )<br>        <span class="cpp-keyword">return</span> hr;<br>hr = Direct3DDeviceSettings(<span class="cpp-keyword">false</span>);<br>    <span class="cpp-comment">//——————-</span><br>    <span class="cpp-keyword">return</span> hr;<br>    <span class="cpp-comment">//——————-</span><br></pre></div><!–ENDSCRIPT–><br><br>Any ideas what I'm doing wrong?  I modified the coordinates to use the list instead and have the coordinates top left, top right, bottom left and top right, bottom right, bottom left.
Okay, I've gotten a little further with this, but now I am only getting the left triangle ( bottom left, top left, bottom right ) being drawn. Any ideas?

My buffers initted
//-------------------HRESULT _Direct3D::InitBuffers(){    //-------------------    WORD* pIndices;    //-------------------    // Create the Index Buffer. Here we are allocating enough memory    // (from the managed pool) to hold up to 1024 Rectangles.  Each    // rectangle is composed of 2 triangles, each with 3 vertices.    //-------------------    if (FAILED(hr = d3d9Device->CreateIndexBuffer(        sizeof(WORD)*MAX_RECTS*6,           //  Length        D3DUSAGE_WRITEONLY,                 //  Usage        D3DFMT_INDEX16,			            //  Specifies Format        D3DPOOL_MANAGED,                    //  D3D Pool        &d3d9IndexBuffer,                   //  IDirect3DIndexBuffer9        NULL                                //  Handle    ) ) )    {        const char* szError = DXGetErrorDescription9(hr);        MessageBox (MainForm->Handle, szError, "Error", MB_OK );        return E_FAIL;    }    //-------------------  Lock the Index Buffer    if ( FAILED( hr = d3d9IndexBuffer->Lock(0, 0, (void**)&pIndices, 0) ) )        return hr;    //-------------------  Fill the Indices    for ( int i = 0; i < MAX_RECTS; ++i )    {       //-------------------  First triangle (top left, top right, bottom left)       *pIndices++ = i*4;       *pIndices++ = i*4 + 1;       *pIndices++ = i*4 + 2;       //-------------------  Second triangle (top right, bottom right, bottom left)       *pIndices++ = i*4 + 1;       *pIndices++ = i*4 + 3;       *pIndices++ = i*4 + 2;    }    //-------------------  Unlock the Index Buffer    d3d9IndexBuffer->Unlock();    //-------------------    // Create the vertex buffer. Here we are allocating enough memory    // (from the default pool) to hold all our 3 custom vertices. We also    // specify the FVF, so the vertex buffer knows what data it contains.    //-------------------    if( FAILED( d3d9Device->CreateVertexBuffer(        sizeof(WORD)*MAX_RECTS*6,		    //  Length        0,							        //  Usage        D3DFVF_TLVERTEX,			        //  Specifies Vertex Format        D3DPOOL_MANAGED,			        //  D3DPool        &d3d9VertexBuffer,  		        //  Pointer to the Direct3D Vertex Buffer        NULL					        	//  HANDLE    ) ) )    {        //-------------------        return hr;        //-------------------    }    return hr;    //-------------------}//-------------------


And call during render:
HRESULT _Direct3D::DrawZones(){    //-------------------    bool first = false;    WORD* pIndices;    Vertex* pVertices;    int num_rectangles = 0;    int i = 0;    //-------------------    Direct3DDeviceSettings(true);    //-------------------    if( FAILED( d3d9VertexBuffer->Lock( 0, 0, ( void** )&pVertices, 0 ) ) )        return E_FAIL;    //-------------------  Iterate through the Zones    Data->Zones.whileFirst();    while ( Data->Zones.whileNext() && !first )    {        //-------------------  First triangle top left        //pVertices.x = Data-&gt;Zones.i-&gt;dxPosition[1].X;</span><br>        <span class="cpp-comment">//pVertices.y = Data-&gt;Zones.i-&gt;dxPosition[1].Y;</span><br>        pVertices.x = <span class="cpp-number">256</span>.0f;<br>        pVertices.y = <span class="cpp-number">256</span>.0f;<br>        pVertices.z = <span class="cpp-number">0</span>.0f;<br>        pVertices.rhw = <span class="cpp-number">0</span>.0f;<br>        pVertices.color = D3DCOLOR_ARGB(<span class="cpp-number">127</span>, <span class="cpp-number">0</span>, <span class="cpp-number">0</span>, <span class="cpp-number">255</span>);<br>        <span class="cpp-comment">//pVertices.tu = 1;</span><br>        <span class="cpp-comment">//pVertices.ty = 0;</span><br>        pVertices.tu = <span class="cpp-number">0</span>;<br>        pVertices.ty = <span class="cpp-number">0</span>;<br>        <span class="cpp-comment">//——————-  First triangle top right</span><br>        <span class="cpp-comment">//pVertices.x = Data-&gt;Zones.i-&gt;dxPosition[3].X;</span><br>        <span class="cpp-comment">//pVertices.y = Data-&gt;Zones.i-&gt;dxPosition[3].Y;</span><br>        pVertices.x = <span class="cpp-number">512</span>.0f;<br>        pVertices.y = <span class="cpp-number">256</span>.0f;<br>        pVertices.z = <span class="cpp-number">0</span>.0f;<br>        pVertices.rhw = <span class="cpp-number">0</span>.0f;<br>        pVertices.color = D3DCOLOR_ARGB(<span class="cpp-number">127</span>, <span class="cpp-number">0</span>, <span class="cpp-number">0</span>, <span class="cpp-number">255</span>);<br>        <span class="cpp-comment">//pVertices.tu = 1;</span><br>        <span class="cpp-comment">//pVertices.ty = 1;</span><br>        pVertices.tu = <span class="cpp-number">1</span>;<br>        pVertices.ty = <span class="cpp-number">0</span>;<br>        <span class="cpp-comment">//——————-  First triangle bottom left</span><br>        <span class="cpp-comment">//pVertices.x = Data-&gt;Zones.i-&gt;dxPosition[0].X;</span><br>        <span class="cpp-comment">//pVertices.y = Data-&gt;Zones.i-&gt;dxPosition[0].Y;</span><br>        pVertices.x = <span class="cpp-number">256</span>.0f;<br>        pVertices.y = <span class="cpp-number">512</span>.0f;<br>        pVertices.z = <span class="cpp-number">0</span>.0f;<br>        pVertices.rhw = <span class="cpp-number">0</span>.0f;<br>        pVertices.color = D3DCOLOR_ARGB(<span class="cpp-number">127</span>, <span class="cpp-number">0</span>, <span class="cpp-number">0</span>, <span class="cpp-number">255</span>);<br>        <span class="cpp-comment">//pVertices.tu = 0;</span><br>        <span class="cpp-comment">//pVertices.ty = 0;</span><br>        pVertices.tu = <span class="cpp-number">0</span>;<br>        pVertices.ty = <span class="cpp-number">1</span>;<br>        <span class="cpp-comment">//——————-  Second triangle top right</span><br>        <span class="cpp-comment">//pVertices.x = Data-&gt;Zones.i-&gt;dxPosition[3].X;</span><br>        <span class="cpp-comment">//pVertices.y = Data-&gt;Zones.i-&gt;dxPosition[3].Y;</span><br>        pVertices.x = <span class="cpp-number">512</span>.0f;<br>        pVertices.y = <span class="cpp-number">256</span>.0f;<br>        pVertices.z = <span class="cpp-number">0</span>.0f;<br>        pVertices.rhw = <span class="cpp-number">0</span>.0f;<br>        pVertices.color = D3DCOLOR_ARGB(<span class="cpp-number">127</span>, <span class="cpp-number">0</span>, <span class="cpp-number">0</span>, <span class="cpp-number">255</span>);<br>        <span class="cpp-comment">//pVertices.tu = 1;</span><br>        <span class="cpp-comment">//pVertices.ty = 1;</span><br>        pVertices.tu = <span class="cpp-number">1</span>;<br>        pVertices.ty = <span class="cpp-number">0</span>;<br>        <span class="cpp-comment">//——————-  Second triangle bottom right</span><br>        <span class="cpp-comment">//pVertices.x = Data-&gt;Zones.i-&gt;dxPosition[2].X;</span><br>        <span class="cpp-comment">//pVertices.y = Data-&gt;Zones.i-&gt;dxPosition[2].Y;</span><br>        pVertices.x = <span class="cpp-number">512</span>.0f;<br>        pVertices.y = <span class="cpp-number">512</span>.0f;<br>        pVertices.z = <span class="cpp-number">0</span>.0f;<br>        pVertices.rhw = <span class="cpp-number">0</span>.0f;<br>        pVertices.color = D3DCOLOR_ARGB(<span class="cpp-number">127</span>, <span class="cpp-number">0</span>, <span class="cpp-number">0</span>, <span class="cpp-number">255</span>);<br>        <span class="cpp-comment">//pVertices.tu = 0;</span><br>        <span class="cpp-comment">//pVertices.ty = 1;</span><br>        pVertices.tu = <span class="cpp-number">1</span>;<br>        pVertices.ty = <span class="cpp-number">1</span>;<br>        <span class="cpp-comment">//——————-  Second triangle bottom left</span><br>        <span class="cpp-comment">//pVertices.x = Data-&gt;Zones.i-&gt;dxPosition[0].X;</span><br>        <span class="cpp-comment">//pVertices.y = Data-&gt;Zones.i-&gt;dxPosition[0].Y;</span><br>        pVertices.x = <span class="cpp-number">256</span>.0f;<br>        pVertices.y = <span class="cpp-number">512</span>.0f;<br>        pVertices.z = <span class="cpp-number">0</span>.0f;<br>        pVertices.rhw = <span class="cpp-number">0</span>.0f;<br>        pVertices.color = D3DCOLOR_ARGB(<span class="cpp-number">127</span>, <span class="cpp-number">0</span>, <span class="cpp-number">0</span>, <span class="cpp-number">255</span>);<br>        <span class="cpp-comment">//pVertices.tu = 0;</span><br>        <span class="cpp-comment">//pVertices.ty = 0;</span><br>        pVertices.tu = <span class="cpp-number">0</span>;<br>        pVertices.ty = <span class="cpp-number">1</span>;<br>        <span class="cpp-comment">//——————-</span><br>        num_rectangles++;<br>        first = <span class="cpp-keyword">true</span>;<br>        <span class="cpp-comment">//——————-</span><br>    }<br>    <span class="cpp-comment">//——————-</span><br>    <span class="cpp-comment">//memcpy( pIndices, vertices, sizeof( vertices ) );</span><br>    d3d9VertexBuffer-&gt;Unlock();<br>    <span class="cpp-comment">//——————-</span><br>    d3d9Device-&gt;SetTexture( <span class="cpp-number">0</span>, NULL );<br>    d3d9Device-&gt;SetStreamSource( <span class="cpp-number">0</span>, d3d9VertexBuffer, <span class="cpp-number">0</span>, <span class="cpp-keyword">sizeof</span>( Vertex ) );<br>    d3d9Device-&gt;SetFVF( D3DFVF_TLVERTEX );<br>    <span class="cpp-comment">//——————-</span><br>    d3d9Device-&gt;SetIndices(d3d9IndexBuffer);<br>    <span class="cpp-comment">//——————-</span><br>    <span class="cpp-keyword">if</span> (FAILED(hr = d3d9Device-&gt;DrawIndexedPrimitive(<br>        D3DPT_TRIANGLELIST,<br>        <span class="cpp-number">0</span>,<br>        <span class="cpp-number">0</span>,<br>        num_rectangles*<span class="cpp-number">4</span>,<br>        <span class="cpp-number">0</span>,<br>        num_rectangles*<span class="cpp-number">2</span><br>    ) ) )<br>        <span class="cpp-keyword">return</span> hr;<br>    hr = Direct3DDeviceSettings(<span class="cpp-keyword">false</span>);<br>    <span class="cpp-comment">//——————-</span><br>    <span class="cpp-keyword">return</span> hr;<br><br><br></pre></div><!–ENDSCRIPT–><br><br>*edit<br>Is this because when declaring the vertices I &#111;nly need to define 4. Then the index buffer connects the vertices accordingly?<br><br><!–EDIT–><span class=editedby><!–/EDIT–>[Edited by - nlraley on October 26, 2010 5:31:57 PM]<!–EDIT–></span><!–/EDIT–>

This topic is closed to new replies.

Advertisement