Jump to content
  • Advertisement
Sign in to follow this  

Ortho Projection gone wrong.

This topic is 4665 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->SetRenderState(D3DRS_LIGHTING, FALSE );

		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 projection;

	if(m_isfileopen == true){
		windowX = (float)m_window->Width;
		windowY = (float)m_window->Height;
		float textureX = 0;
		float textureY = 0;
		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
			// }

			// reset graphics


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.

Share this post

Link to post
Share on other sites
I don't have time to go through your code, but 2 things to try:
1) Disable alphablending
2) Disable culling

Then see if you can see anything.

There's nothing wrong with using Ortho, it can be quite handy.

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

| \ |

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
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!