Jump to content

  • Log In with Google      Sign In   
  • Create Account


cant render a rectange in rhw space


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
11 replies to this topic

#1 Anddos   Members   -  Reputation: 485

Like
0Likes
Like

Posted 29 February 2012 - 09:24 AM

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

Attached Thumbnails

  • rectange-render-lines.jpg
  • rectange-render-triangles.jpg

:)

Sponsor:

#2 turch   Members   -  Reputation: 590

Like
1Likes
Like

Posted 29 February 2012 - 09:44 AM

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

#3 kubera   Members   -  Reputation: 903

Like
0Likes
Like

Posted 29 February 2012 - 10:00 AM

Maybe a problem is the order of vertices.
Please, swap vertices in your invlisble triangle.
(a, b, c) => (a, c, b)

#4 Burnt_Fyr   Members   -  Reputation: 1230

Like
0Likes
Like

Posted 29 February 2012 - 10:12 AM

@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

#5 Anddos   Members   -  Reputation: 485

Like
0Likes
Like

Posted 29 February 2012 - 10:50 AM

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


that was it , thanks
:)

#6 Anddos   Members   -  Reputation: 485

Like
0Likes
Like

Posted 29 February 2012 - 10:50 AM

Would it be possible to set a texture now for this rectange?
:)

#7 Evil Steve   Members   -  Reputation: 1959

Like
0Likes
Like

Posted 29 February 2012 - 11:36 AM

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

Steve Macpherson
Senior programmer, Firebrand Games


#8 Anddos   Members   -  Reputation: 485

Like
0Likes
Like

Posted 29 February 2012 - 11:51 AM

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

#9 turch   Members   -  Reputation: 590

Like
0Likes
Like

Posted 29 February 2012 - 12:34 PM

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.

#10 Anddos   Members   -  Reputation: 485

Like
0Likes
Like

Posted 29 February 2012 - 12:44 PM

ok you have to remove the D3DFVF_DIFFUSE then it works :)
:)

#11 turch   Members   -  Reputation: 590

Like
0Likes
Like

Posted 29 February 2012 - 12:55 PM

This guide should help you.

#12 Anddos   Members   -  Reputation: 485

Like
0Likes
Like

Posted 29 February 2012 - 01:05 PM

Thanks for that guide, that is exactly what i was looking for
:)




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS