mirror of
https://github.com/SFML/SFML.git
synced 2024-11-25 04:41:05 +08:00
FS#121 - Improve accuracy of rendering
git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/trunk@1157 4e206d99-4929-0410-ac5d-dfc041789085
This commit is contained in:
parent
e2ddadb395
commit
06525907c1
@ -253,12 +253,11 @@ public :
|
||||
/// texture coordinates
|
||||
///
|
||||
/// \param Rect : Sub-rectangle of image to convert
|
||||
/// \param Adjust : Pass true to apply the half-texel adjustment
|
||||
///
|
||||
/// \return Texture coordinates corresponding to the sub-rectangle
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
FloatRect GetTexCoords(const IntRect& Rect, bool Adjust = true) const;
|
||||
FloatRect GetTexCoords(const IntRect& Rect) const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get a valid texture size according to hardware support
|
||||
|
@ -213,10 +213,6 @@ FT_Error FontLoader::CreateBitmapFont(FT_Face FontFace, unsigned int CharSize, c
|
||||
FT_Glyph_To_Bitmap(&Glyph, FT_RENDER_MODE_NORMAL, 0, 1);
|
||||
FT_BitmapGlyph BitmapGlyph = (FT_BitmapGlyph)Glyph;
|
||||
|
||||
// Should we handle other pixel modes ?
|
||||
if (BitmapGlyph->bitmap.pixel_mode != FT_PIXEL_MODE_GRAY)
|
||||
return FT_Err_Cannot_Render_Glyph;
|
||||
|
||||
// Add it to the sorted table of glyphs
|
||||
Glyphs.insert(std::make_pair(BitmapGlyph, Charset[i]));
|
||||
}
|
||||
@ -293,7 +289,7 @@ FT_Error FontLoader::CreateBitmapFont(FT_Face FontFace, unsigned int CharSize, c
|
||||
for (std::size_t i = 0; i < Charset.size(); ++i)
|
||||
{
|
||||
Uint32 CurChar = Charset[i];
|
||||
LoadedFont.myGlyphs[CurChar].TexCoords = LoadedFont.myTexture.GetTexCoords(Coords[CurChar], false);
|
||||
LoadedFont.myGlyphs[CurChar].TexCoords = LoadedFont.myTexture.GetTexCoords(Coords[CurChar]);
|
||||
}
|
||||
|
||||
// Update the character size (it may have been changed by the function)
|
||||
|
@ -542,26 +542,16 @@ bool Image::IsSmooth() const
|
||||
/// Convert a subrect expressed in pixels, into float
|
||||
/// texture coordinates
|
||||
////////////////////////////////////////////////////////////
|
||||
FloatRect Image::GetTexCoords(const IntRect& Rect, bool Adjust) const
|
||||
FloatRect Image::GetTexCoords(const IntRect& Rect) const
|
||||
{
|
||||
float Width = static_cast<float>(myTextureWidth);
|
||||
float Height = static_cast<float>(myTextureHeight);
|
||||
|
||||
if (Adjust && myIsSmooth)
|
||||
{
|
||||
return FloatRect((Rect.Left + 0.5f) / Width,
|
||||
(Rect.Top + 0.5f) / Height,
|
||||
(Rect.Right - 0.5f) / Width,
|
||||
(Rect.Bottom - 0.5f) / Height);
|
||||
}
|
||||
else
|
||||
{
|
||||
return FloatRect(Rect.Left / Width,
|
||||
Rect.Top / Height,
|
||||
Rect.Right / Width,
|
||||
Rect.Bottom / Height);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
|
@ -186,6 +186,10 @@ void Sprite::Render(RenderTarget&) const
|
||||
// Check if the image is valid
|
||||
if (myImage && (myImage->GetWidth() > 0) && (myImage->GetHeight() > 0))
|
||||
{
|
||||
// Use the "offset trick" to get pixel-perfect rendering
|
||||
// see http://www.opengl.org/resources/faq/technical/transformations.htm#tran0030
|
||||
GLCheck(glTranslatef(0.375f, 0.375f, 0.f));
|
||||
|
||||
// Bind the texture
|
||||
myImage->Bind();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user