I am digging up this old thread because this issue still is a problem for me and because I want to present a solution how I "fixed" it for myself. The change is made in SFML directly as it's not possible to fix within my own application but the change is pretty small, pretty simple and -in my opinion- pretty helpful for people like me who desire/demand pixel-preciseness even during antialiased/smoothed rendering. So without further ado I will now post a patch against r936 of SFML. Just copy&paste the following text into a file called "subpixelaccuracy.patch" and apply it to SFML - under Windows simply with TortoiseSVN and "Apply patch..." or under Linux with the diff command (if I remember correctly).
Laurent, I'd really like to see this implemented in SFML and I tried to make it as small and as easy and as reasonable for you as possible. In case you are not convinced of its necessity yet I can give you an example application clearly demonstrating the whole issue.
Index: include/SFML/Graphics/Image.hpp
===================================================================
--- include/SFML/Graphics/Image.hpp (revision 936)
+++ include/SFML/Graphics/Image.hpp (working copy)
@@ -224,6 +224,16 @@
void SetSmooth(bool Smooth);
////////////////////////////////////////////////////////////
+ /// Enable or disable half-texel adjustment.
+ /// This parameter is enabled by default
+ /// and only relevant if Smooth is enabled, too
+ ///
+ /// \param Adjust : True to enable half-texel adjustment, false to disable it
+ ///
+ ////////////////////////////////////////////////////////////
+ void SetAdjust(bool Adjust);
+
+ ////////////////////////////////////////////////////////////
/// Return the width of the image
///
/// \return Width in pixels
@@ -248,6 +258,14 @@
bool IsSmooth() const;
////////////////////////////////////////////////////////////
+ /// Tells whether the half-texel adjustment is enabled or not
+ ///
+ /// \return True if half-texel adjustment is enabled
+ ///
+ ////////////////////////////////////////////////////////////
+ bool IsAdjust() const;
+
+ ////////////////////////////////////////////////////////////
/// Convert a subrect expressed in pixels, into float
/// texture coordinates
///
@@ -324,6 +342,7 @@
unsigned int myTextureHeight; ///< Actual texture height (can be greater than image height because of padding)
unsigned int myTexture; ///< Internal texture identifier
bool myIsSmooth; ///< Status of the smooth filter
+ bool myIsAdjust; ///< Status of the texel adjustment
mutable std::vector<Color> myPixels; ///< Pixels of the image
mutable bool myNeedTextureUpdate; ///< Status of synchronization between pixels in central memory and the internal texture un video memory
mutable bool myNeedArrayUpdate; ///< Status of synchronization between pixels in central memory and the internal texture un video memory
Index: src/SFML/Graphics/Image.cpp
===================================================================
--- src/SFML/Graphics/Image.cpp (revision 936)
+++ src/SFML/Graphics/Image.cpp (working copy)
@@ -47,6 +47,7 @@
myTextureHeight (0),
myTexture (0),
myIsSmooth (true),
+myIsAdjust (true),
myNeedTextureUpdate(false),
myNeedArrayUpdate (false)
{
@@ -65,6 +66,7 @@
myTextureHeight (Copy.myTextureHeight),
myTexture (0),
myIsSmooth (Copy.myIsSmooth),
+myIsAdjust (Copy.myIsAdjust),
myPixels (Copy.myPixels),
myNeedTextureUpdate(false),
myNeedArrayUpdate (false)
@@ -83,6 +85,7 @@
myTextureHeight (0),
myTexture (0),
myIsSmooth (true),
+myIsAdjust (true),
myNeedTextureUpdate(false),
myNeedArrayUpdate (false)
{
@@ -100,6 +103,7 @@
myTextureHeight (0),
myTexture (0),
myIsSmooth (true),
+myIsAdjust (true),
myNeedTextureUpdate(false),
myNeedArrayUpdate (false)
{
@@ -483,6 +487,15 @@
////////////////////////////////////////////////////////////
+/// Enable or disable half-texel adjustment
+////////////////////////////////////////////////////////////
+void Image::SetAdjust(bool Adjust)
+{
+ myIsAdjust = Adjust;
+}
+
+
+////////////////////////////////////////////////////////////
/// Return the width of the image
////////////////////////////////////////////////////////////
unsigned int Image::GetWidth() const
@@ -510,6 +523,14 @@
////////////////////////////////////////////////////////////
+/// Tells whether the half-texel adjustment is enabled or not
+////////////////////////////////////////////////////////////
+bool Image::IsAdjust() const
+{
+ return myIsAdjust;
+}
+
+////////////////////////////////////////////////////////////
/// Convert a subrect expressed in pixels, into float
/// texture coordinates
////////////////////////////////////////////////////////////
@@ -518,7 +539,7 @@
float Width = static_cast<float>(myTextureWidth);
float Height = static_cast<float>(myTextureHeight);
- if (Adjust && myIsSmooth)
+ if (Adjust && myIsAdjust && myIsSmooth)
{
return FloatRect((Rect.Left + 0.5f) / Width,
(Rect.Top + 0.5f) / Height,
@@ -573,6 +594,7 @@
std::swap(myTextureHeight, Temp.myTextureHeight);
std::swap(myTexture, Temp.myTexture);
std::swap(myIsSmooth, Temp.myIsSmooth);
+ std::swap(myIsAdjust, Temp.myIsAdjust);
std::swap(myNeedArrayUpdate, Temp.myNeedArrayUpdate);
std::swap(myNeedTextureUpdate, Temp.myNeedTextureUpdate);
myPixels.swap(Temp.myPixels);
@@ -729,6 +751,7 @@
myTextureHeight = 0;
myTexture = 0;
myIsSmooth = true;
+ myIsAdjust = true;
myNeedTextureUpdate = false;
myNeedArrayUpdate = false;
myPixels.clear();