# Problems displaying triangles properly

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

## Recommended Posts

Basically, I am drawing 3 triangles on the screen. As I understand it, the vertices are transformed already, so they should be in a "stuck" place in the 3d world. When I move the camera, however, the triangles actually move position. I can't figure out why this is happening. Thanks for any help! edit: ok, I see that the vertices being transformed means that they are in 2d screen space. How do I get them to be in 3d? I'm a little confused ;) Here's the code i'm using:
	CUSTOMVERTEX vertices[] =
{
{ 5.0f,  20.0f, 0.5f,0xffff0000, }, // x, y, z, rhw, color
{ 10.0f,  20.0f, -5.0f, 0xffff0000, },
{ 5.0f,  20.0f, -5.0f, 0xffff0000, },

{  5.0f, 5.0f, 0.5f,   0xff00ff00, }, // x, y, z, rhw, color
{ 10.0f, 50.0f, 0.5f,  0xff00ff00, },
{  10.0f, 10.0f, 0.5f, 0xff00ff00, },

{ 25.0f, 25.0f, 0.5f,  0xff00ffff, },
{ 5.0f,  25.0f, 0.5f,  0xff00ffff, },
{ 5.0f,  5.0f, 0.5f,   0xff00ffff, }, // x, y, z, rhw, color

};

if( FAILED( d3ddevice->CreateVertexBuffer( sizeof(vertices),
D3DUSAGE_WRITEONLY, D3DFVF_CUSTOMVERTEX, D3DPOOL_DEFAULT, &batch, NULL ) ) )
return 0;

VOID* pVertices;
if( FAILED( batch->Lock( 0, sizeof(vertices), (void**)&pVertices, 0 ) ) )
return E_FAIL;
memcpy( pVertices, vertices, sizeof(vertices) );
batch->Unlock();

d3ddevice->SetRenderState(D3DRS_LIGHTING,
FALSE);

d3ddevice->SetStreamSource( 0, batch, 0,sizeof(CUSTOMVERTEX) );
d3ddevice->SetFVF( D3DFVF_CUSTOMVERTEX );
d3ddevice->DrawPrimitive( D3DPT_TRIANGLELIST, 0, 3);


[Edited by - ktuluorion on October 8, 2006 3:36:35 PM]

##### Share on other sites
Your comments suggest you're using transformed and lit (which are specified in screen-space/2D) but your code suggests regular 3D.

e.g:

{ 5.0f, 20.0f, 0.5f,0xffff0000, }, // x, y, z, rhw, color

Your comment lists 5 fields, but your code is only providing 4 [smile]

What is D3DFVF_CUSTOMVERTEX defined as? Does it use D3DFVF_XYZRHW or D3DFVF_XYZ?

Cheers,
Jack

##### Share on other sites
How come each vertex only take four parameters? If they're supposed to be transformed, where's RHW?

Edit: Blasted "high speed" internet.

##### Share on other sites
I took out RHW. It's an old comment. I think i might have figured out the probem.. i needed to call the transform function to set where in space it is.

1. 1
2. 2
Rutin
16
3. 3
4. 4
5. 5

• 26
• 11
• 9
• 9
• 11
• ### Forum Statistics

• Total Topics
633702
• Total Posts
3013450
×