RHW Quad Missing in Action

Started by
5 comments, last by Cuculain 19 years, 10 months ago
I''ve implemented a simple experimental Quad-system for 2D rendering based on the article on gamedev about this. It works just fine until I try to render even a single mesh (using the ID3DXMesh::DrawSubset method), which makes the quad simply disappear. Everything works fine in isolation - but it does not combine. I have RHW in my FVF and it is set to 1.0f. I also restore states before each pass. If anyone have ideas why this occurs I would be grateful.

//----------------------------------------  

// Draw a textured quad on the back-buffer

//----------------------------------------

void CQuad::Render(RECT* rDest)
{
    // Setup vertex format

    m_pDevice->SetVertexShader(NULL);
    m_pDevice->SetFVF(FVF_QUADVERTEX);

    // Set render states

    m_pDevice->SetRenderState(D3DRS_LIGHTING, FALSE);
    m_pDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
    m_pDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
    m_pDevice->SetRenderState(D3DRS_DESTBLEND,   
         D3DBLEND_INVSRCALPHA);
    m_pDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, 
         D3DTOP_MODULATE);

    QUADVERTEX* vertices;

    // Lock the vertex buffer

    vertexBuffer->Lock(0, 0, (void**)&vertices, NULL);

    // Setup vertices

    vertices[0].colour = 0xFFFFFFFF;
    vertices[0].x = (float) rDest->left - 0.5f;
    vertices[0].y = (float) rDest->top - 0.5f;
    vertices[0].z = 0.0f;
    vertices[0].rhw = 1.0f;
    vertices[0].u = 0.0f;
    vertices[0].v = 0.0f;

    vertices[1].colour = 0xFFFFFFFF;
    vertices[1].x = (float) rDest->right - 0.5f;
    vertices[1].y = (float) rDest->top - 0.5f;
    vertices[1].z = 0.0f;
    vertices[1].rhw = 1.0f;
    vertices[1].u = 1.0f;
    vertices[1].v = 0.0f;

    vertices[2].colour = 0xFFFFFFFF;
    vertices[2].x = (float) rDest->right - 0.5f;
    vertices[2].y = (float) rDest->bottom - 0.5f;
    vertices[2].z = 0.0f;
    vertices[2].rhw = 1.0f;
    vertices[2].u = 1.0f;
    vertices[2].v = 1.0f;

    vertices[3].colour = 0xFFFFFFFF;
    vertices[3].x = (float) rDest->left - 0.5f;
    vertices[3].y = (float) rDest->bottom - 0.5f;
    vertices[3].z = 0.0f;
    vertices[3].rhw = 1.0f;
    vertices[3].u = 0.0f;
    vertices[3].v = 1.0f;

    // Unlock the vertex buffer

    vertexBuffer->Unlock();

    // Set texture

    m_pDevice->SetTexture (0, m_pTexture);

    // Draw image

    m_pDevice->DrawPrimitive (D3DPT_TRIANGLEFAN, 0, 2);
}
Advertisement
So you had something that draw a textured quad, and it worked right?

Then you added code to generate a "mesh" and the quad and the quad is not visible?

Is the texture visiible?
Have your checked our Camera/World/Project matrices to make sure you haven''t transformed the quad off the screen, compared to your mesh?

Are you resetting those for each "object" being drawn?

Do you have z-buffer enabled? Also what is your Near/Far Clip compared to your camera location.

What are your "clear" settings etc.

Turn off culling:
m_pDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
m_pDevice->SetStreamSource(0, vertexBuffer, 0, sizeof(QUADVERTEX));

[edited by - Randy187 on June 10, 2004 3:43:51 AM]
Wow, I thought I was in for some matrix-transformational hell but resetting the stream source solved the problem. Thx Randy187 and others.
Just as a side note, RHW = 1.0f means that it''s already transformed, thus bypassing any matrix transformations.

---------------------------------------

Let''s struggle for our dream of Game!

http://andrewporritt.4t.com
quote:Original post by f8k8
Just as a side note, RHW = 1.0f means that it''s already transformed, thus bypassing any matrix transformations.

Not quite. Having the RHW as part of your vertex definition means it is transformed, the value has no impact on that.


Stay Casual,

Ken
Drunken Hyena
Stay Casual,KenDrunken Hyena

This topic is closed to new replies.

Advertisement