Jump to content
  • Advertisement
Sign in to follow this  

3D DX8 - Texel to pixel mapping

Recommended Posts

Blast from the past: While checking my different renderers I've come upon a problem in a Direct3d8 renderer, which I'm pretty sure worked fine already a while ago.

Basically I'm drawing a 2d quad with pretransformed vertices, but the first triangle's texture coordinates seem off. I'm offsetting the coordinates by -0.5,-0.5 as per spec and there's not much more to it. The same part with D3D11 using shaders works fine (well, duh). Anyhow, I'm still curious, as the DX8 renderer is still my final fallback and it currently is supported quite well.

Anybody see any glaring mistake?

The code in question is this, the texture is a 16x16 pixel sized cut out from a 256x256 texture, these values are used. FWIW I'm running on Windows 10 with some AMD Radeon 5450.


iX = 22
iY = 222
Texture rect from the full texture are is (144,0 with 16x16 size)
The drawn box is drawn scaled up to a size of 40x40 pixels
m_DirectTexelMapping.offset is a 2d vector with values -0.5, -0.5

I've set min-, mag- and mip-mapping filter to nearest.

  D3DXVECTOR3   position; // The position
  float         fRHW;
  D3DCOLOR      color;    // The color
  float         fTU,
  CUSTOMVERTEX          vertData[4];	  
  float   fRHW = 1.0f;	  
  GR::tVector   ptPos( (float)iX, (float)iY, fZ );
  GR::tVector   ptSize( (float)iWidth, (float)iHeight, 0.0f );	  
  m_pd3dDevice->SetVertexShader( D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1 );	  
  vertData[0].position.= ptPos.x + m_DirectTexelMappingOffset.x;
  vertData[0].position.= ptPos.y + m_DirectTexelMappingOffset.y;
  vertData[0].position.= (float)ptPos.z;
  vertData[0].fRHW        = fRHW;
  vertData[0].color       = dwColor1;
  vertData[0].fTU         = fTU1;
  vertData[0].fTV         = fTV1;	  
  vertData[1].position.= ptPos.x + ptSize.x + m_DirectTexelMappingOffset.x;
  vertData[1].position.= ptPos.y            + m_DirectTexelMappingOffset.y;
  vertData[1].position.= (float)ptPos.z;
  vertData[1].fRHW        = fRHW;
  vertData[1].color       = dwColor2;
  vertData[1].fTU         = fTU2;
  vertData[1].fTV         = fTV2;	  
  vertData[2].position.= ptPos.x            + m_DirectTexelMappingOffset.x;
  vertData[2].position.= ptPos.y + ptSize.y + m_DirectTexelMappingOffset.y;
  vertData[2].position.= (float)ptPos.z;
  vertData[2].fRHW        = fRHW;
  vertData[2].color       = dwColor3;
  vertData[2].fTU         = fTU3;
  vertData[2].fTV         = fTV3;	  
  vertData[3].position.= ptPos.x + ptSize.x + m_DirectTexelMappingOffset.x;
  vertData[3].position.= ptPos.y + ptSize.y + m_DirectTexelMappingOffset.y;
  vertData[3].position.= (float)ptPos.z;
  vertData[3].fRHW        = fRHW;
  vertData[3].color       = dwColor4;
  vertData[3].fTU         = fTU4;
  vertData[3].fTV         = fTV4;	  
                  sizeof( vertData[0] ) );


God, I hate this borked message editor, it's so not user friendly. This POS message editor really loves to f*ck up code formatting.

Share this post

Link to post
Share on other sites

D3D9 was released Jan, 2003... I don't see anything standing out to me in your code snippet mind you.  But honestly you need to drop support for this, it's not worth the time of day to maintain.  If you release anything to the public you will have a maintenance nightmare on your hands.  Mostly in the form of infected out of date OS support calls/complaints.  And if you claim to support their OS they will ridicule your software on public forums and leaving negative reviews.

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  

  • Advertisement

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!