From 06525907c1e4699702ad9e534212d191142662ab Mon Sep 17 00:00:00 2001 From: LaurentGom Date: Sat, 4 Jul 2009 19:20:13 +0000 Subject: [PATCH] FS#121 - Improve accuracy of rendering git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/trunk@1157 4e206d99-4929-0410-ac5d-dfc041789085 --- include/SFML/Graphics/Image.hpp | 5 ++--- src/SFML/Graphics/FontLoader.cpp | 6 +----- src/SFML/Graphics/Image.cpp | 20 +++++--------------- src/SFML/Graphics/Sprite.cpp | 4 ++++ 4 files changed, 12 insertions(+), 23 deletions(-) diff --git a/include/SFML/Graphics/Image.hpp b/include/SFML/Graphics/Image.hpp index 2a3227162..0c6538e09 100644 --- a/include/SFML/Graphics/Image.hpp +++ b/include/SFML/Graphics/Image.hpp @@ -252,13 +252,12 @@ public : /// Convert a subrect expressed in pixels, into float /// texture coordinates /// - /// \param Rect : Sub-rectangle of image to convert - /// \param Adjust : Pass true to apply the half-texel adjustment + /// \param Rect : Sub-rectangle of image to convert /// /// \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 diff --git a/src/SFML/Graphics/FontLoader.cpp b/src/SFML/Graphics/FontLoader.cpp index 922cac984..0f6e67bf3 100644 --- a/src/SFML/Graphics/FontLoader.cpp +++ b/src/SFML/Graphics/FontLoader.cpp @@ -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) diff --git a/src/SFML/Graphics/Image.cpp b/src/SFML/Graphics/Image.cpp index f90673cd0..14346fb9d 100644 --- a/src/SFML/Graphics/Image.cpp +++ b/src/SFML/Graphics/Image.cpp @@ -542,25 +542,15 @@ 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(myTextureWidth); float Height = static_cast(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); - } + return FloatRect(Rect.Left / Width, + Rect.Top / Height, + Rect.Right / Width, + Rect.Bottom / Height); } diff --git a/src/SFML/Graphics/Sprite.cpp b/src/SFML/Graphics/Sprite.cpp index a728d4b58..375bd5e70 100644 --- a/src/SFML/Graphics/Sprite.cpp +++ b/src/SFML/Graphics/Sprite.cpp @@ -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();