Sign in to follow this  
Unliterate

Cant figure out why vertices stopped appearing on the screen. (DirectX)

Recommended Posts

All I do is switch my FVF from (D3DFVF_XYZRHW|D3DFVF_DIFFUSE) to (D3DFVF_XYZ|D3DFVF_DIFFUSE) and I dont see any vertices any more. I'm not doing any SetTransforms, because I'm assuming I dont have to if the default view is at 0,0,0 looking off as z increases with y+ going up, but maybe I need some (to be applied to the object vertices?)? When I do use camera and world transformations I notice no difference. here is the code:
	for(vertex_index=0;vertex_index<4000;vertex_index++)
	{
		vertices[vertex_index].x=(rand()%2000-1000)/(float)100;
		vertices[vertex_index].y=(rand()%2000-1000)/(float)100;
		vertices[vertex_index].z=(rand()%2000-1000)/(float)100;
		colors[vertex_index]=D3DCOLOR_ARGB(rand()%255,rand()%255,rand()%255,rand()%255);
	}


	Game->Display.LoadVertexData(vertices,colors,4000);




void DISPLAY::LoadVertexData(D3DXVECTOR3 *coordinates,D3DCOLOR *colors,int number_of_vertices)
{
	VOID* pVertices;
	if(FAILED(D3DVertexBuffer->Lock(0,0,(void**) &pVertices,D3DLOCK_DISCARD/*entire buffer is overwritten*/)))
	{
		MessageBox(window,"Failed to lock the vertex buffer!","Damn!",MB_ICONEXCLAMATION | MB_OK);
		return;
	}

	int index=0;
	while(index<number_of_vertices)//dont ask why im using a while() instead of a for() here, i dont know :|
	{
		screen_vertices[index].x=coordinates[index].x;
		screen_vertices[index].y=coordinates[index].y;
		screen_vertices[index].z=coordinates[index].z;
		screen_vertices[index].color=colors[index];
		index++;
	}

	memcpy(pVertices,screen_vertices,sizeof(screen_vertices));

	if(FAILED(D3DVertexBuffer->Unlock()))
		MessageBox(window,"Failed to unlock the vertex buffer!","Damn!",MB_ICONEXCLAMATION | MB_OK);
}




inline void Refresh()
{

	Game->Display.BeginRendering();


	int primitive_count[2];
	int starts[2];
//	Game->Display.SetTexture(1);
	starts[0]=0;
	primitive_count[0]=1000;
	starts[1]=1999;
	primitive_count[1]=1000;
	Game->Display.RenderVertices(starts,primitive_count,2);

	Game->Display.BeginSpriteRendering();

	if(Game->fps_display)
	{
		Game->Text.D3DDrawText("FPS",D3DXVECTOR2(0,0),&D3DXVECTOR2(.5,.8));
		Game->Text.D3DDrawText(1/Time.TimeMultiple,D3DXVECTOR2(40,0),NULL);
	}
//	Game->Display.DrawSpriteToBuffer(1,&D3DXVECTOR2(200,200),NULL,NULL,NULL,NULL);

	Game->Display.EndSpriteRendering();
	
	Game->Display.EndRendering();
}



void DISPLAY::RenderVertices(int *vertice_starts,int *number_of_primitives,int number_of_unique_primitive_sets)
{
	D3DRenderDevice->SetStreamSource(0,D3DVertexBuffer,0,sizeof(CUSTOM_VERTEX));
	D3DRenderDevice->SetFVF(CustomFVF);

	for(int index=0;index<number_of_unique_primitive_sets;index++)
		D3DRenderDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP,vertice_starts[index],number_of_primitives[index]);
}




the ONLY change I made was to the FVF, everything worked when i was using pretransformed vertices. That being the case I have a feeling there is something obvious I forgot or didn't know I needed to do. [Edited by - Unliterate on September 2, 2004 9:06:15 PM]

Share this post


Link to post
Share on other sites
Yes, sory the topic had a little typo, ill fix it. sprites appear correctly, the only thing that doesnt apear are the vertices. (I'm assuming are you asking if it failed to present).

DrawPrimitve isnt failing either.

[Edited by - Unliterate on September 2, 2004 9:05:30 PM]

Share this post


Link to post
Share on other sites
Quote:

(D3DFVF_XYZRHW|D3DFVF_DIFFUSE) to (D3DFVF_XYZ|D3DFVF_DIFFUSE)


Transformed vs. untransformed.


You need view, projection, and world matrices now.

EDIT:

Did you make (in the creation of your vertex buffer} the sizeof parm fit to your vertices?

struct Vertex
{
Vector3 pos;
DWORD color;
};

CreateVertexBuffer(numberOfVerts*sizeof(Vertex) ....

That could be part of it too.

Share this post


Link to post
Share on other sites
Yea I have the correct size in there. As for the matrices I know I will need them for the transformations but I didnt know I would need them just to see something. Like I said, I've tried to use some transformations but I guess I wasn't using them correctly, I'll give it another shot.

Share this post


Link to post
Share on other sites
this still results in no vertices. I labeled all the things with what i think their purpose is, can anyone see anything wrong here:


void DISPLAY::RenderVertices(int *vertice_starts,int *number_of_primitives,int number_of_unique_primitive_sets)
{
D3DRenderDevice->SetStreamSource(0,D3DVertexBuffer,0,sizeof(CUSTOM_VERTEX));
D3DRenderDevice->SetFVF(CustomFVF);

D3DXMATRIX World,View,Perspective;

D3DXMatrixIdentity(&World);
D3DRenderDevice->SetTransform(D3DTS_WORLD,&World);

D3DXMatrixPerspectiveFovLH(&Perspective,
D3DX_PI/4,//verticle FOV, (90º)
1024/768,//viewing aspect ratio
0,//minimum distance clip
100//maximum distance clip
);
D3DRenderDevice->SetTransform(D3DTS_PROJECTION,&Perspective);

D3DXMatrixLookAtLH(&View,
&D3DXVECTOR3(0,0,-1),//camera vector (x,y,z)?
&D3DXVECTOR3(0,0,0), //camera target
&D3DXVECTOR3(0,1,0));//up
D3DRenderDevice->SetTransform(D3DTS_VIEW,&View);

for(int index=0;index<number_of_unique_primitive_sets;index++)
D3DRenderDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP,vertice_starts[index],number_of_primitives[index]);
}







I'm rendering 4 vertices at (-10,10,1),(10,10,1),(-10,-10,1), and (10,-10,1). can anyone tell me where about on the screen these should be appearing?

[Edited by - Unliterate on September 3, 2004 4:24:04 PM]

Share this post


Link to post
Share on other sites
If you are using RHW vertices, then no transformations are applied. Make sure your XY coordinates matches screen coordinates. Z is used for z buffer and may be any value from 0 to 0.9999999999

Also, you have to provide the W value by hand.

Luck!

Guimo

Share this post


Link to post
Share on other sites
I'm not using RHW so I'm assuming z can be anything. I set the minimum clip to 1 and all the z values of the coordinates to 2 but I still see nothing.

Can someone explain exaclty how the clipping will work? if I have the camera at z=-1, and the clipping planes at 1,50. vertices will only appear if their z coordinate is between 0 and 49 (after rotations and whatnot) correct?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this