• Advertisement
Sign in to follow this  

texture alignment RHW coords?

This topic is 4476 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 loaded a font - CreateFont() - ran through a list of characters i care about and dropped them in a DX texture. I've stashed away all the texture locations ( u/v 's ) for the characters. If I render the generated font texture out to screen ( size:256 u/v:0-1 ) it renders flawlessly. All verts are RHW. When I render any characters to screen, using the stashed u/v coords, I get a tear in the letter. Looking at the letter 'T' there is a single pixel cut where the two triangles edges meet that makes up the full quad. Why is this happening?

Share this post


Link to post
Share on other sites
Advertisement
You're likely using UVs that are on the threshold between one texel and the next. It's a common problem.

In D3D a UV of 0,0 isn't the texel at the top left of your texture, or more precisely, it's not the center of that texel, but it's corner. A UV of 0,0 is in fact exactly mid-way between all four corners of your texture (assuming wrap addressing). In order to point at the center of a texel you must add an offset equal to 1/2 a texel to both U and V.

For example, assuming a 4x8 texture, each texel is 1/4 x 1/8 big. To use this correctly you'd want to add 0.5/4 and 0.5/8 to your U and V, or in general terms vertex.u += 0.5f/texwidth; vertex.v += 0.5f/texheight;

Share this post


Link to post
Share on other sites


Here is the effect that I am getting.
As a description of what your seeing:

The vert positions have been scaled by a factor of ~15.

I lowered the font size to 8pt to produce very blocky fonts to exaggerate the problem induced by one piece or another.

The font texture (at its actual size) is that 'other' part of the picture.

By looking at the T or H you can see the jump right along the horizontal where the tris meet. = Bizarre, seeing as how I am using the same positions for all verts for each letter quad.

I do appreciate your feedback namenobodyelsetook. In giving that a werr, the next pixel rendered becomes that black area that surrounds all the letters in the font texture, then exaggerated by the scaling.

Unsure if the following helps but here it is again with a different diffuse color per tri.


[Edited by - skillfreak on January 20, 2006 12:07:56 AM]

Share this post


Link to post
Share on other sites
U/V:

SIZE extent;
for(char cChar = 32; cChar < 127; cChar++)
{
GetTextExtentPoint32( hDC, (LPCTSTR)&cChar, 1, &extent);
if( curx + extent.cx + 1 > textureSize )
{
curx = 0;
cury += fontSize + 1;
}
ExtTextOut( hDC, curx, cury, ETO_OPAQUE, NULL, (LPCTSTR) &cChar, 1, NULL );
dex = cChar - 32;

texCoords[dex][X_MIN] = (float)curx / (float)textureSize;
texCoords[dex][Y_MIN] = (float)cury / (float)textureSize;
texCoords[dex][X_MAX] = (float)(curx+ extent.cx) / (float)textureSize;
texCoords[dex][Y_MAX] = (float)(cury+ extent.cy) / (float)textureSize;
curx += extent.cx + 5;
}




render():

for( int i = 0; i < strSize; i++ )
{
c = txt - 32;
width = (texCoords[c][X_MAX] - texCoords[c][X_MIN]) * (float)textureSize;
height = (texCoords[c][Y_MAX] - texCoords[c][Y_MIN]) * (float)textureSize;

width *= 20;
height *= 20;

// |¯/
// |/
vd[dex].x = curX;
vd[dex].y = height + y;
vd[dex].tu = texCoords[c][X_MIN];
vd[dex].tv = texCoords[c][Y_MAX];
vd[dex].diffuse = D3DCOLOR_XRGB( 255, 0, 0 );
vd[dex].rhw = 1.0f; vd[dex].z = 0.0f;

dex++;
vd[dex].x = curX;
vd[dex].y = y;
vd[dex].tu = texCoords[c][X_MIN];
vd[dex].tv = texCoords[c][Y_MIN];
vd[dex].diffuse = D3DCOLOR_XRGB( 255, 0, 0 );
vd[dex].rhw = 1.0f; vd[dex].z = 0.0f;

dex++;
vd[dex].x = width + curX;
vd[dex].y = y;
vd[dex].tu = texCoords[c][X_MAX];
vd[dex].tv = texCoords[c][Y_MIN];
vd[dex].diffuse = D3DCOLOR_XRGB( 255, 0, 0 );
vd[dex].rhw = 1.0f; vd[dex].z = 0.0f;

// /|
// /_|
dex++;
vd[dex].x = width + curX;
vd[dex].y = y;
vd[dex].tu = texCoords[c][X_MAX];
vd[dex].tv = texCoords[c][Y_MIN];
vd[dex].diffuse = D3DCOLOR_XRGB( 255, 255, 0 );
vd[dex].rhw = 1.0f; vd[dex].z = 0.0f;

dex++;
vd[dex].x = width + curX;
vd[dex].y = height + y;
vd[dex].tu = texCoords[c][X_MAX];
vd[dex].tv = texCoords[c][Y_MAX];
vd[dex].diffuse = D3DCOLOR_XRGB( 255, 255, 0 );
vd[dex].rhw = 1.0f; vd[dex].z = 0.0f;

dex++;
vd[dex].x = curX;
vd[dex].y = height + y;
vd[dex].tu = texCoords[c][X_MIN];
vd[dex].tv = texCoords[c][Y_MAX];
vd[dex].diffuse = D3DCOLOR_XRGB( 255, 255, 0 );
vd[dex].rhw = 1.0f; vd[dex].z = 0.0f;


dex++;
curX += width;
}

dev->SetFVF( Vertex::FVF /*D3DFVF_XYZRHW|D3DFVF_DIFFUSE|D3DFVF_TEX1*/ );
dev->SetStreamSource( 0, vertBuf, 0, sizeof( Vertex ) );
dev->SetTexture( 0, fontTexture );
dev->DrawPrimitive( D3DPT_TRIANGLELIST, 0, strSize*2 );




is all she wrote.

Share this post


Link to post
Share on other sites
um...
uh
wow.

I switch compilers; going from 2005 to 2003 and the problem just went away...

Thanks for your ongoing assistance ntnet. ++ rating

[edit]
how much time i spent just staring through my computer screen... haha =) all for not.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement