Jump to content
  • Advertisement
Sign in to follow this  
Anddos

cant render a rectange in rhw space

This topic is 2484 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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);

Share this post


Link to post
Share on other sites
Advertisement
You want to render a triangle list, not a triangle strip. Change D3DPT_TRIANGLESTRIP to D3DPT_TRIANGLELIST

Share this post


Link to post
Share on other sites
Maybe a problem is the order of vertices.
Please, swap vertices in your invlisble triangle.
(a, b, c) => (a, c, b)

Share this post


Link to post
Share on other sites
@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

Share this post


Link to post
Share on other sites

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


that was it , thanks

Share this post


Link to post
Share on other sites
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)...

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!