cant render a rectange in rhw space

Started by
10 comments, last by Anddos 12 years, 2 months ago
struct CUSTOMVERTEX {FLOAT X, Y, Z, RHW; DWORD COLOR;};
#define CUSTOMFVF (D3DFVF_XYZRHW | D3DFVF_DIFFUSE )


I an trying to render a rectangle like this, it renders in linelist mode so i can see if the cordinates are correct, so what i want todo now is change it to 2 tranges to make a solid rectangle, but i can only seem to make 1 trangle render , not sure why?


CUSTOMVERTEX vertices[] =
{
//x //y
/*450 */{ 150.0f, 62.5f, 0.5f, 1.0f, D3DCOLOR_XRGB(0, 0, 255), }, //top left
{ 325.0f, 500.0f, 0.5f, 1.0f, D3DCOLOR_XRGB(0, 255, 0), }, //bottom right
{ 150.0f, 500.0f, 0.5f, 1.0f, D3DCOLOR_XRGB(255, 0, 0), }, //bottom left

{150.0f, 62.5f, 0.5f, 1.0f, D3DCOLOR_XRGB(0, 0, 255), }, //top left
{ 325.0f, 62.5f, 0.5f, 1.0f, D3DCOLOR_XRGB(0, 0, 255), }, //top right
{ 325.0f, 500.0f, 0.5f, 1.0f, D3DCOLOR_XRGB(0, 0, 255), }, //bottom right
};

// create a vertex buffer interface called v_buffer
d3ddev->CreateVertexBuffer(6*sizeof(CUSTOMVERTEX),
0,
CUSTOMFVF,
D3DPOOL_MANAGED,
&v_buffer,
NULL);

VOID* pVoid; // a void pointer

// lock v_buffer and load the vertices into it
v_buffer->Lock(0, 0, (void**)&pVoid, 0);
memcpy(pVoid, vertices, sizeof(vertices));
v_buffer->Unlock();


in the rendering function


// select which vertex format we are using
d3ddev->SetFVF(CUSTOMFVF);

// select the vertex buffer to display
d3ddev->SetStreamSource(0, v_buffer, 0, sizeof(CUSTOMVERTEX));

// copy the vertex buffer to the back buffer
// d3ddev->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0,2);

d3ddev->DrawPrimitive(D3DPT_LINESTRIP, 0,5);
:)
Advertisement
You want to render a triangle list, not a triangle strip. Change D3DPT_TRIANGLESTRIP to D3DPT_TRIANGLELIST
Maybe a problem is the order of vertices.
Please, swap vertices in your invlisble triangle.
(a, b, c) => (a, c, b)
@OP: Turch is correct, I looked earlier and didn't spot it.

@kubera: that was my first instinct to, but both triangles are clearly wound the same based on vertex position

You want to render a triangle list, not a triangle strip. Change D3DPT_TRIANGLESTRIP to D3DPT_TRIANGLELIST


that was it , thanks
:)
Would it be possible to set a texture now for this rectange?
:)
Yes, if you add a set of UV coordinates to your vertex struct and FVF:
struct CUSTOMVERTEX {FLOAT X, Y, Z, RHW; FLOAT U, V; DWORD COLOR;};
#define CUSTOMFVF (D3DFVF_XYZRHW | D3DFVF_TEX1 | D3DFVF_DIFFUSE )

I'm not sure if UV should come after the diffuse component - it's been years since I used FVF codes (And this is one of the many reasons not to use them)...
but what about the texture cordinates? , ive got a feeling i need to lock the vertexbuffers and add the 1.0 and 0.0 offsets but ive only seen this done for a 3d cube in worldspace , not screenspace
:)
uv coordinates are their own space, it doesn't matter if you're drawing in screen or world space, the uv's don't get affected by any of the transformations.
ok you have to remove the D3DFVF_DIFFUSE then it works :)
:)

This topic is closed to new replies.

Advertisement