Projecting 3D coordinates to 2D for text drawing

Started by
1 comment, last by simonloach 16 years, 9 months ago
I'm trying to draw text on screen using ID3DXFont but this only takes 2D coordinates. So far I've got:
	D3DXMATRIX n = viewmatrix * projectionmatrix;

	D3DXMATRIX textposition3d;
	D3DXMatrixIdentity(&textposition3d);
	D3DXMatrixTranslation(&textposition3d, 6.0f, 0.0f, 0.0f);

	D3DXMATRIX textposition2d = textposition3d * n;

	r->rendertext(L"text on screen", <x coordinate>, <y coordinate>);
I'm not sure whether this is the correct way to go about it and I also have no idea how to extract the coordinates from the textposition2d matrix. Any help would be appreciated :)
Advertisement
You can use the handy D3DXVec3Project() function to project a vector from object space to screen space.
Thanks works perfectly :)

This topic is closed to new replies.

Advertisement