Skip to main content
gamedev.net
🔒 Locked

DG question

Started by Hamster Patrick Jun 2, 2002 at 3:01 AM 1 replies 250+ views
Original Post
Hamster Patrick
Hamster Patrick
Hi, I have an problem with my blitting routine! I have made this screenshots, the first is a screenshot from my programm and the second is the BitmapFile who I try to blit. http://cpp.ufosnetwork.com/Image1.gif http://cpp.ufosnetwork.com/Image2.gif my routine:
  
bool CGraphic::drawAdvance (float x, float y, float rotation, D3DCOLOR color, CVideo &PrimaryVideoClass)
{
	VERTEX v1,v2,v3,v4;
	VERTEX Vertex_Array[4];

	D3DXMATRIX matRot, matTrans, matTrans2, matWorld;

	float Breite = (float)m_ImageInfo.Width;
	float Hoehe  = (float)m_ImageInfo.Height;

	v1.x		= x;
	v1.y		= y;
	v1.z		= 0.5f;
	v1.u		= 0.0f;
	v1.v		= 0.0f;
	v1.color	= color;

	v2.x		= Breite + x;
	v2.y		= y;
	v2.z		= 0.5f;
	v2.u		= 1.0f;
	v2.v		= 0.0f;
	v2.color	= color;

	v3.x		= x;
	v3.y		= Hoehe + y;
	v3.z		= 0.5f;
	v3.u		= 0.0f;
	v3.v		= 1.0f;
	v3.color	= color;

	v4.x		= Breite + x;
	v4.y		= Hoehe + y;
	v4.z		= 0.5f;
	v4.u		= 1.0f;
	v4.v		= 1.0f;
	v4.color	= color;

	Vertex_Array[0] = v2;
	Vertex_Array[1] = v1;
	Vertex_Array[2] = v4;
	Vertex_Array[3] = v3;

	D3DXMatrixRotationZ(&matRot, PI * rotation / 180);
	PrimaryVideoClass.getDevice()->SetTransform(D3DTS_WORLD, &matRot);

	D3DXMatrixTranslation(&matTrans,-x-(Breite/2),-y-(Hoehe/2), 0.0f);
	 
	D3DXMatrixTranslation(&matTrans2,x+(Breite/2),y+(Hoehe/2), 0.0f); 
	  
	D3DXMatrixMultiply(&matWorld, &matTrans, &matRot);

	D3DXMatrixMultiply(&matWorld, &matWorld, &matTrans2);

	PrimaryVideoClass.getDevice()->SetTransform(D3DTS_WORLD, &matWorld);
	PrimaryVideoClass.getDevice()->SetTexture(0, m_Texture);	

	PrimaryVideoClass.getDevice()->SetTextureStageState(0, D3DTSS_MINFILTER, D3DTEXF_LINEAR);
	PrimaryVideoClass.getDevice()->SetTextureStageState(0, D3DTSS_MAGFILTER, D3DTEXF_LINEAR);


	PrimaryVideoClass.getDevice()->SetTransform(D3DTS_PROJECTION, &PrimaryVideoClass.matProj);

	PrimaryVideoClass.getDevice()->SetVertexShader(VERTEXCAPS);
	PrimaryVideoClass.getDevice()->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP,2,&Vertex_Array[0],sizeof(VERTEX));

	D3DXMatrixMultiply(&matWorld, &matWorld, &matTrans2); 
	D3DXMatrixRotationZ  (&matWorld, 0);
	PrimaryVideoClass.getDevice()->SetTransform(D3DTS_WORLD, &matWorld);

	return (true);

}      
  
please help me! --------------------------------------- Coden ist das Schönste auf der Welt! [edited by - Hamster Patrick on June 2, 2002 4:03:00 AM] [edited by - Hamster Patrick on June 2, 2002 4:03:58 AM] [edited by - jim adams on June 2, 2002 2:21:35 PM]
---------------------------------------Coden ist das Schönste auf der Welt! :)
xyzzy00
xyzzy00
My guess is that you are asking about fill rules.

If you want to guarantee that a pixel on the screen will be drawn, you need to make sure that it is completely inside your primitive. If you drawing a screenspace rect (x,y,w,h), you should offset the coordinates to be (x-0.5,y-0.5,w,h). This will guarantee that (x,y) and (x+w-1,y+w-1) are both explicitly included. If your vertices are already in screenspace, this is easy to do manually by just subtracting 0.5 from each coordinate. If your vertices are not in screenspace, this is also easy enough to do in your projection matrix.

Offsetting the position by (-0.5,-0.5) has another benefit: If you are moving through texturespace at the same rate as you are moving through screenspace, when you draw the pixel (x,y) you will already be (0.5,0.5) into the texture. When using bilinear filtering, this should select only the top-left pixel of your texture. Whereas (0.0,0.0) would represent some average of all four corner pixels of your texture.

You might want to take a look at using ID3DXSprite, which I believe already takes this all into account.

xyzzy

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.