Jump to content
  • Advertisement
Sign in to follow this  

problem with 2d quad tutorial

This topic is 4232 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've worked through the article http://www.gamedev.net/reference/articles/article1972.asp and assumed that for my game I don't need batching. I use the orthogonal projection matrix as explained in the tutorial but there's one problem. The position of the quad is correct but the size of the quad seems not. I tried a checker texture (check pattern with a size of one pixel) and it's blurred. I used point filtering but that doesn't seem to help. Do I have to use pretransformed vertex positions (xyzrhw) or could it be that I implemented something wrong?
    // render quad
    D3DXMatrixScaling (&matScale, (float)screenwidth, (float)screenheight, 1.0f);
    D3DXMatrixTranslation (&matTranslation, -float(screenwidth/2+posx),float(screenheight/2-posy), 0.0f);
    matTransform = matScale * matTranslation;

	m_pDevice->SetTransform (D3DTS_WORLD, &matTransform);
	m_pDevice->SetTransform (D3DTS_PROJECTION, &matOrtho);
	m_pDevice->SetTransform (D3DTS_VIEW, &matIdentity); 

    m_pDevice->DrawPrimitive(D3DPT_TRIANGLEFAN, 0, 2);

    // orthogonal projection matrix is initialized in the init method like this:
    D3DXMatrixOrthoLH (&matOrtho, (float)screenwidth, (float)screenheight, 1.0f, 10.0f);
screenwidth/height equals backbuffer size Thanks in advance

Share this post

Link to post
Share on other sites
If you're going to create a 2D game, you should use pre-transformed vertex. It makes more sense either.

Share this post

Link to post
Share on other sites
Actually it is only for the GUI. The reason I didn't use them was because the article said it's faster to use matrix transformation than locking/unlocking the vertexbuffer.

I'll use pretransformed vertices now. Thank you.

Share this post

Link to post
Share on other sites
Alright, I've tried to use pretransformed vertices but the problem's still the same. Looks like it's filtered or blurred or something.
left = original image, right = application

I use the following code:
HRESULT CRender::RenderQuad(int iTexID, float posx, float posy) {
m_pDevice->SetRenderState(D3DRS_ZWRITEENABLE, false);
m_pDevice->SetRenderState(D3DRS_ZFUNC, D3DCMP_ALWAYS);
m_pDevice->SetRenderState(D3DRS_LIGHTING, FALSE);
m_pDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
m_pDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE);

m_pDevice->SetSamplerState(0, D3DSAMP_MIPFILTER, D3DTEXF_NONE);
m_pDevice->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_NONE);
m_pDevice->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_NONE);

//fill vertex buffer
SVertex2D* vertices = NULL;
m_pVB_Quad->Lock(0, 4 * sizeof(SVertex2D), (VOID**)&vertices, 0);
vertices[0].vPosition = CVector(posx -.5f +0.0f, posy -.5f +0.0f, 1.0f);
vertices[0].rhw = 1;
vertices[0].u = 0.0f;
vertices[0].v = 0.0f;

vertices[1].vPosition = CVector(posx -.5f +256.0f, posy -.5f +0.0f, 1.0f);
vertices[1].rhw = 1;
vertices[1].u = 1.0f;
vertices[1].v = 0.0f;

vertices[2].vPosition = CVector(posx -.5f +256.0f, posy -.5f +256.0f, 1.0f);
vertices[2].rhw = 1;
vertices[2].u = 1.0f;
vertices[2].v = 1.0f;

vertices[3].vPosition = CVector(posx -.5f +0.0f, posy -.5f +256.0f, 1.0f);
vertices[3].rhw = 1;
vertices[3].u = 0.0f;
vertices[3].v = 1.0f;

m_pDevice->SetTexture(0, ITextureManager.GetTextureByID(iTexID));
m_pDevice->SetStreamSource(0, m_pVB_Quad, 0, sizeof(SVertex2D));

m_pDevice->DrawPrimitive(D3DPT_TRIANGLEFAN, 0, 2);

return S_OK;

Any idea?

[Edited by - mk1x86 on May 16, 2007 1:07:56 PM]

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!