Sign in to follow this  

Strange problem with uv texture coords

Recommended Posts

Halaster    122
I have this really strange problem when I texture a quad. Basically the bottom line of pixels will wrap around to the top. So when I make my bitmaps I have to set the bottom row of pixels to the alpha colorkey so they are removed. I setup my vertices as follows: // Top left vVertices[0].m_vPosition = D3DXVECTOR3(-0.5f, 0.5f, 0.0f); vVertices[0].m_dwColor = 0xffffffff; vVertices[0].m_tu = 0.0f; vVertices[0].m_tv = 0.0f; // Top right vVertices[1].m_vPosition = D3DXVECTOR3(0.5f, 0.5f, 0.0f); vVertices[1].m_dwColor = 0xffffffff; vVertices[1].m_tu = 1.0f; vVertices[1].m_tv = 0.0f; // Bottom right vVertices[2].m_vPosition = D3DXVECTOR3(0.5f, -0.5f, 0.0f); vVertices[2].m_dwColor = 0xffffffff; vVertices[2].m_tu = 1.0f; vVertices[2].m_tv = 1.0f; // Bottom left vVertices[3].m_vPosition = D3DXVECTOR3(-0.5f, -0.5f, 0.0f); vVertices[3].m_dwColor = 0xffffffff; vVertices[3].m_tu = 0.0f; vVertices[3].m_tv = 1.0f; As you can see here there is nothing wrong with the way I setup my uv's. So I dont know if this is a problem with DirectX rendering pipeline or something I'm doing, or maybe some setting on my video card. I render the vertices using the following flags: // Enable alpha blending pd3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, true ); pd3dDevice->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_SRCALPHA ); pd3dDevice->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA ); g_pQuad->OnRender( pd3dDevice ); // Reset device states pd3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, false ); pd3dDevice->SetTexture( 0, NULL ); If anyone has ever encountered this problem before or has any idea of what might be causing it I would really like to know. Thanks.

Share this post

Link to post
Share on other sites
Change your texture addressing mode to clamp

(not a cut n paste, could be slightly off, sorry)

The reason is that in Direct3D, up to version 9, (0,0) is the corner of the top left pixel, not the center of the pixel. When you have wrapping and bilinear filtering you'll get a 50% with the top and bottom, and with the left and right. Adding half a texel to your UVs will compensate for this (ie: if source image is 64x512, then u += 0.5/64; v += 0.5/512;)

OpenGL uses 0,0 as the center of the pixel.

Share this post

Link to post
Share on other sites

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