Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Triangle Fans Won't Draw

This topic is 5673 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

Hi, I'm writing my basic engine bit by bit, right now I'm getting it to draw basic geometric shapes. To get it to draw a circle (or multi-sided polygon) I decided to use a triangle fan, as I can just specify the center and the edge points. No-matter how I try, however, I can't get it to draw - It doesn't throw any errors up, just doesn't do anything. Can anyone see my problem?
// Pointer to device called m_pD3DDevice

BOOL cFixedGeometry::DrawPolygon ( float x, float y, float radius, int points, float phase, DWORD color)
	// Generate the Vertex Points

	vertex *Vertices;
	Vertices = new vertex[points+2];

	Vertices[0].x = x; Vertices[0].y = y; Vertices[0].z = 0.0f; Vertices[0].rhw = 1.0f; Vertices[0].color = color; 

	for (int i = 0; i <= points; i++)
		Vertices[i+1].x = x + (float)(radius * sin(((2.0*PI)/points)*i));
		Vertices[i+1].y = y - (float)(radius * cos(((2.0*PI)/points)*i));
		Vertices[i+1].z = 0.0f; Vertices[i+1].rhw = 1.0f; Vertices[i+1].color = color;

	IDirect3DVertexBuffer9	*vbuffer;
	if(FAILED(((IDirect3DDevice9*)m_pD3DDevice)->CreateVertexBuffer((points+2)*sizeof(vertex), 0, P2DVERTEX, D3DPOOL_DEFAULT, &vbuffer, NULL)))
		return FALSE;

	//Now fill the vertex buffer

	VOID *pVertices;
	if (FAILED( vbuffer->Lock(0, sizeof(Vertices), (void**)&pVertices, 0)))
		return FALSE;
	memcpy(pVertices, Vertices, sizeof(Vertices));

	//Now Draw it

		return FALSE;
	if(((IDirect3DDevice9*)m_pD3DDevice)->SetStreamSource(0, vbuffer, 0, sizeof(vertex)) != D3D_OK)
		return FALSE;
	if(((IDirect3DDevice9*)m_pD3DDevice)->DrawPrimitive(D3DPT_TRIANGLEFAN, 0, points) != D3D_OK)
		return FALSE;

	//RElease the Vertex Buffer now. this is Messy, but since the size can change each

	//call it's easier than keeping track of everything.

	delete Vertices;

	return TRUE;
oh yeah, the FvF Format is just Pre-transformed with colour (x, y, z, rhw, color) and thats the contents of the vertex struct. other than that and the d3d pointer, this function should be pretty stand alone - so the problem should be here. [edited by - Xgkkp on June 2, 2003 7:11:28 PM]

Share this post

Link to post
Share on other sites
1) Set the colour you specify in your Clear() call to something like "hideous pink" (255,0,255). That''ll show you if the polygons are being rasterised at all. If they appear, but they''re black, then there is a problem with your pixel processing set up.

2) What scales are you passing for your radius, and what position coordinates are you passing? - remember that transformed vertices are in screen coordinates.

3) Try setting the cull mode (D3DRS_CULLMODE) to D3DCULL_NONE. If you see the polygons with that, then you''re specifying the vertices in the wrong order (i.e. clockwise vs anticlockwise). Reverse the order that your points are being created. Also see #2 - the origin is at the top left hand corner and Y goes down the screen not up like it does in 3D space.

4) Make sure you clear your Z buffer (D3DCLEAR_ZBUFFER). Also as a test, make sure that nothing else is obscuring your primitive (i.e. isolate so that only the function you''ve posted is being called).

5) Do you have any other states set to unusual values such as D3DRS_ZFUNC set to D3DCMP_NEVER or indeed anything else at all set up.

6) Do you have a valid projection matrix set up? (yes, even if you''re using rhw vertices).

7) Although not a problem at the moment. I''d STRONGLY advise against creating and later destroying a new vertex buffer for every call. Peformance wise, that''s absolutely hideous, and about the slowest way you could achieve that .

a. A simpler and much faster way would be to use DrawPrimitiveUP(). That''s bad for performance in itself, but D3D does provide some internal logic to ensure that buffers aren''t created when they aren''t needed so should still be faster than creating and destroying a new buffer.

b. Your highest average vertex count per shape probably isn''t too high - why not just create a shape vertex buffer when your app starts with the "usual" maximum number of vertices as its size. For all shapes which fit in that buffer (i.e. the majority), use that buffer, and then special case the ones that don''t.

c. Your VB should be dynamic if you''re generating the points that go in it dynamically. And the lock flags you use should be appropriate (they also let you efficiently render complex shapes in multiple batches with a smaller buffer size)

d. There''s no need to dynamiclaly allocate memory, then memcpy the vertices - just generate the vertices straight into the locked buffer.

Simon O''Connor
Creative Asylum Ltd

Share this post

Link to post
Share on other sites
1) I'm rendering onto a (0,0,197)ish blue, not black background, so Thats not the problem.

2) I'm passing (x=300, y=300, rad=20, point=3, phase=0, color=0xFFFFFFFF) - so not that

3) I've been messing around with this stuff, and it hasn't seemed to make a difference

4) My clear automatically clears zbuffer, and I'm only drawing 2 things anyway - this and a single line elsewhere on the screen

5) uhhh... I don't think so - I've only been building up from the basics, no experimenting, I use seperate, test projects for that

6) I am pretty sure i do - i think it's part of the initialisation of the graphics

7) I know, I know, It was just a quick hack-test thing. - I like those suggestions though, I hadn't thought of it in that way. what do you mean by "Your VB should be dynamic if you're generating the points that go in it dynamically." - Dynamic Vertex buffers? I'll have to look it up when I can get access to the sdk next.

Thanks a lot for all the suggestions!!!

[edited by - xgkkp on June 2, 2003 8:05:09 PM]

Share this post

Link to post
Share on other sites

  • 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!