Sign in to follow this  

Ortho Projection gone wrong.

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

I'm not sure why this isn't displaying, I still can't really get these to work properly so I hope someone else could help me out with it. Problem is simple, the quad doesn't show up.
struct _quad
{
	struct _vertex
	{
		float x, y, z;
		DWORD diffuse;
		float tu, tv;
	} v[4];

};


		LPDIRECT3DDEVICE9 d3dd = g_graphicsEngine.GetDevice();

		d3dd->SetFVF(D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1);

		d3dd->SetRenderState(D3DRS_LIGHTING, FALSE );
		d3dd->SetRenderState(D3DRS_ALPHABLENDENABLE,true);
		d3dd->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCCOLOR);
		d3dd->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCCOLOR);

		d3dd->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
		d3dd->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
		d3dd->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
		d3dd->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_DIFFUSE);

void SpriteModel::Update(void)
{

	float windowX;
	float windowY;

	D3DXMATRIX view;
	D3DXMATRIX projection;

	if(m_isfileopen == true){
		windowX = (float)m_window->Width;
		windowY = (float)m_window->Height;
		float textureX = 0;
		float textureY = 0;
		D3DXMatrixIdentity(&projection);
		D3DXMatrixOrthoOffCenterLH(&view, 0.0f, windowX, 0.0f, windowY, 0.0f, 1.0f);
//		D3DXMatrixOrthoLH(&view, windowX, windowY, 0.0f, 1.0f);
//		D3DXMatrixOrthoRH(&view, windowX, windowY, 0.0f, 1.0f);
		g_graphicsEngine.GetDevice()->SetTransform(D3DTS_VIEW, &view);
		g_graphicsEngine.GetDevice()->SetTransform(D3DTS_PROJECTION, &projection);

		if(g_graphicsEngine.SceneBegin(true) == true){
			if(g_textureManager.Contains("background") == true){
				LPDIRECT3DDEVICE9 d3dd = g_graphicsEngine.GetDevice();

				cTexture* texBack = (cTexture*)g_textureManager.Retrieve("background");
				textureX = (float)texBack->GetWidth();
				textureY = (float)texBack->GetHeight();

				_quad backQuad;

				backQuad.v[0].diffuse = backQuad.v[1].diffuse = backQuad.v[2].diffuse = backQuad.v[3].diffuse = 0xFF0000FF;

				backQuad.v[1].x = 0; 
				backQuad.v[1].y = 0;
				backQuad.v[3].x = windowX; 
				backQuad.v[3].y = 0;
				backQuad.v[2].x = windowX;
				backQuad.v[2].y = windowY;
				backQuad.v[0].x = 0;
				backQuad.v[0].y = windowY;

				for(int i = 0; i < 4; i++)
					backQuad.v[3].z = 1.0f;

				backQuad.v[1].tu = 0; 
				backQuad.v[1].tv = 0;
				backQuad.v[3].tu = windowX / textureX;
				backQuad.v[3].tv = 0;
				backQuad.v[2].tu = windowX / textureX;
				backQuad.v[2].tv = windowY / textureY;
				backQuad.v[0].tu = 0;
				backQuad.v[0].tv = windowY / textureY;

				d3dd->SetTexture(0, texBack->GetTexture());
				d3dd->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, &backQuad, sizeof(_quad::_vertex));
			
			}

			// if(texture){
			// drawFrame
			// }

			g_graphicsEngine.SceneEnd();
			g_graphicsEngine.ScenePresent();
		}else{
			// reset graphics
		}
	}
}

Thanks

Share this post


Link to post
Share on other sites
Instead of using the view matrix to project the coords to screen-space you could use FVF.Transformed and then work in screen pixel coords. It's simpler and more efficient too.

Theres a Sprite interface too in DX (ID3DXSprite from memory).

It could help to set the RenderState.FillMode to wireframe. If you can't see anything then you're coords are incorrect (or at least the ones the pipeline receives are.. could be that your FVF is wrong or similar).

You could also try using the VertexDeclaration object rather than rely on the FVF.

Hope that get's you going.
Greg

Share this post


Link to post
Share on other sites
Nah, sorry. Both of those don't seem to work.

Let me try and explain what I'm trying to do with setting up the vertices.

windowX, and windowY are a panel I draw to and they are the dimentions for it.

So then I set the view to (I) and the projection matrix to a matrix making the screen (0, 0), (windowX, windowY) making the pixel to screen ratio 1:1

Then I fill up the quad with vertices for each corner in the screen going in the pattern

1---3
| \ |
0---2

then I set the z values to 1.0f (I made a mistake in the first post, I corrected it but it still doesn't work)

then I do something similar with the textures except I divide them by the texturewidth and height. So I can effectivly have the same texture (16x16) tile across the whole window.

Share this post


Link to post
Share on other sites

This topic is 4302 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.

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