From b65b19343abf9e1becd13b3fcd87b003f67eb2a3 Mon Sep 17 00:00:00 2001 From: Laurent Gomila Date: Wed, 21 Dec 2011 22:44:21 +0100 Subject: [PATCH] Changed the type of Vertex::TexCoords from integers to floats, to make it compatible with buggy ATI drivers --- include/SFML/Graphics/Vertex.hpp | 18 ++++++++++------- src/SFML/Graphics/RenderTarget.cpp | 2 +- src/SFML/Graphics/Shape.cpp | 4 ++-- src/SFML/Graphics/Sprite.cpp | 16 +++++++-------- src/SFML/Graphics/Text.cpp | 32 +++++++++++++++--------------- src/SFML/Graphics/Vertex.cpp | 4 ++-- 6 files changed, 40 insertions(+), 36 deletions(-) diff --git a/include/SFML/Graphics/Vertex.hpp b/include/SFML/Graphics/Vertex.hpp index f8a091196..f7e9ae60e 100644 --- a/include/SFML/Graphics/Vertex.hpp +++ b/include/SFML/Graphics/Vertex.hpp @@ -78,7 +78,7 @@ public : /// \param texCoords Vertex texture coordinates /// //////////////////////////////////////////////////////////// - Vertex(const Vector2f& position, const Vector2i& texCoords); + Vertex(const Vector2f& position, const Vector2f& texCoords); //////////////////////////////////////////////////////////// /// \brief Construct the vertex from its position, color and texture coordinates @@ -88,14 +88,14 @@ public : /// \param texCoords Vertex texture coordinates /// //////////////////////////////////////////////////////////// - Vertex(const Vector2f& position, const sf::Color& color, const Vector2i& texCoords); + Vertex(const Vector2f& position, const sf::Color& color, const Vector2f& texCoords); //////////////////////////////////////////////////////////// // Member data //////////////////////////////////////////////////////////// Vector2f Position; ///< 2D position of the vertex sf::Color Color; ///< Color of the vertex - Vector2i TexCoords; ///< Coordinates of the texture's pixel to map to the vertex + Vector2f TexCoords; ///< Coordinates of the texture's pixel to map to the vertex }; } // namespace sf @@ -128,16 +128,20 @@ public : /// // define a 100x100 square, red, with a 10x10 texture mapped on it /// sf::Vertex vertices[] = /// { -/// sf::Vertex(sf::Vector2f( 0, 0), sf::Color::Red, sf::Vector2i( 0, 0)), -/// sf::Vertex(sf::Vector2f( 0, 100), sf::Color::Red, sf::Vector2i( 0, 10)), -/// sf::Vertex(sf::Vector2f(100, 100), sf::Color::Red, sf::Vector2i(10, 10)), -/// sf::Vertex(sf::Vector2f(100, 0), sf::Color::Red, sf::Vector2i(10, 0)) +/// sf::Vertex(sf::Vector2f( 0, 0), sf::Color::Red, sf::Vector2f( 0, 0)), +/// sf::Vertex(sf::Vector2f( 0, 100), sf::Color::Red, sf::Vector2f( 0, 10)), +/// sf::Vertex(sf::Vector2f(100, 100), sf::Color::Red, sf::Vector2f(10, 10)), +/// sf::Vertex(sf::Vector2f(100, 0), sf::Color::Red, sf::Vector2f(10, 0)) /// }; /// /// // draw it /// window.Draw(vertices, 4, sf::Quads); /// \endcode /// +/// Note: although texture coordinates are supposed to be an integer +/// amount of pixels, their type is float because of some buggy graphics +/// drivers that are not able to process integer coordinates correctly. +/// /// \see sf::VertexArray /// //////////////////////////////////////////////////////////// diff --git a/src/SFML/Graphics/RenderTarget.cpp b/src/SFML/Graphics/RenderTarget.cpp index 4d8d593fe..3fbf730cc 100644 --- a/src/SFML/Graphics/RenderTarget.cpp +++ b/src/SFML/Graphics/RenderTarget.cpp @@ -201,7 +201,7 @@ void RenderTarget::Draw(const Vertex* vertices, unsigned int verticesCount, const char* data = reinterpret_cast(vertices); GLCheck(glVertexPointer(2, GL_FLOAT, sizeof(Vertex), data + 0)); GLCheck(glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(Vertex), data + 8)); - GLCheck(glTexCoordPointer(2, GL_INT, sizeof(Vertex), data + 12)); + GLCheck(glTexCoordPointer(2, GL_FLOAT, sizeof(Vertex), data + 12)); // Find the OpenGL primitive type static const GLenum modes[] = {GL_POINTS, GL_LINES, GL_LINE_STRIP, diff --git a/src/SFML/Graphics/Shape.cpp b/src/SFML/Graphics/Shape.cpp index 656cc370c..de585e92e 100644 --- a/src/SFML/Graphics/Shape.cpp +++ b/src/SFML/Graphics/Shape.cpp @@ -239,8 +239,8 @@ void Shape::UpdateTexCoords() { float xratio = (myVertices[i].Position.x - myInsideBounds.Left) / myInsideBounds.Width; float yratio = (myVertices[i].Position.y - myInsideBounds.Top) / myInsideBounds.Height; - myVertices[i].TexCoords.x = static_cast(myTextureRect.Left + myTextureRect.Width * xratio); - myVertices[i].TexCoords.y = static_cast(myTextureRect.Top + myTextureRect.Height * yratio); + myVertices[i].TexCoords.x = myTextureRect.Left + myTextureRect.Width * xratio; + myVertices[i].TexCoords.y = myTextureRect.Top + myTextureRect.Height * yratio; } } diff --git a/src/SFML/Graphics/Sprite.cpp b/src/SFML/Graphics/Sprite.cpp index 23ac67a83..cb8b1db07 100644 --- a/src/SFML/Graphics/Sprite.cpp +++ b/src/SFML/Graphics/Sprite.cpp @@ -160,15 +160,15 @@ void Sprite::UpdatePositions() //////////////////////////////////////////////////////////// void Sprite::UpdateTexCoords() { - int left = myTextureRect.Left; - int right = myTextureRect.Left + myTextureRect.Width; - int top = myTextureRect.Top; - int bottom = myTextureRect.Top + myTextureRect.Height; + float left = static_cast(myTextureRect.Left); + float right = left + myTextureRect.Width; + float top = static_cast(myTextureRect.Top); + float bottom = top + myTextureRect.Height; - myVertices[0].TexCoords = Vector2i(left, top); - myVertices[1].TexCoords = Vector2i(left, bottom); - myVertices[2].TexCoords = Vector2i(right, bottom); - myVertices[3].TexCoords = Vector2i(right, top); + myVertices[0].TexCoords = Vector2f(left, top); + myVertices[1].TexCoords = Vector2f(left, bottom); + myVertices[2].TexCoords = Vector2f(right, bottom); + myVertices[3].TexCoords = Vector2f(right, top); } } // namespace sf diff --git a/src/SFML/Graphics/Text.cpp b/src/SFML/Graphics/Text.cpp index 62b4a8127..a602818ba 100644 --- a/src/SFML/Graphics/Text.cpp +++ b/src/SFML/Graphics/Text.cpp @@ -260,10 +260,10 @@ void Text::UpdateGeometry() float top = y + underlineOffset; float bottom = top + underlineThickness; - myVertices.Append(Vertex(Vector2f(0, top), myColor, Vector2i(1, 1))); - myVertices.Append(Vertex(Vector2f(x, top), myColor, Vector2i(2, 1))); - myVertices.Append(Vertex(Vector2f(x, bottom), myColor, Vector2i(2, 2))); - myVertices.Append(Vertex(Vector2f(0, bottom), myColor, Vector2i(1, 2))); + myVertices.Append(Vertex(Vector2f(0, top), myColor, Vector2f(1, 1))); + myVertices.Append(Vertex(Vector2f(x, top), myColor, Vector2f(2, 1))); + myVertices.Append(Vertex(Vector2f(x, bottom), myColor, Vector2f(2, 2))); + myVertices.Append(Vertex(Vector2f(0, bottom), myColor, Vector2f(1, 2))); } // Handle special characters @@ -283,16 +283,16 @@ void Text::UpdateGeometry() int right = glyph.Bounds.Left + glyph.Bounds.Width; int bottom = glyph.Bounds.Top + glyph.Bounds.Height; - int u1 = glyph.TextureRect.Left; - int v1 = glyph.TextureRect.Top; - int u2 = glyph.TextureRect.Left + glyph.TextureRect.Width; - int v2 = glyph.TextureRect.Top + glyph.TextureRect.Height; + float u1 = static_cast(glyph.TextureRect.Left); + float v1 = static_cast(glyph.TextureRect.Top); + float u2 = static_cast(glyph.TextureRect.Left + glyph.TextureRect.Width); + float v2 = static_cast(glyph.TextureRect.Top + glyph.TextureRect.Height); // Add a quad for the current character - myVertices.Append(Vertex(Vector2f(x + left - italic * top, y + top), myColor, Vector2i(u1, v1))); - myVertices.Append(Vertex(Vector2f(x + right - italic * top, y + top), myColor, Vector2i(u2, v1))); - myVertices.Append(Vertex(Vector2f(x + right - italic * bottom, y + bottom), myColor, Vector2i(u2, v2))); - myVertices.Append(Vertex(Vector2f(x + left - italic * bottom, y + bottom), myColor, Vector2i(u1, v2))); + myVertices.Append(Vertex(Vector2f(x + left - italic * top, y + top), myColor, Vector2f(u1, v1))); + myVertices.Append(Vertex(Vector2f(x + right - italic * top, y + top), myColor, Vector2f(u2, v1))); + myVertices.Append(Vertex(Vector2f(x + right - italic * bottom, y + bottom), myColor, Vector2f(u2, v2))); + myVertices.Append(Vertex(Vector2f(x + left - italic * bottom, y + bottom), myColor, Vector2f(u1, v2))); // Advance to the next character x += glyph.Advance; @@ -304,10 +304,10 @@ void Text::UpdateGeometry() float top = y + underlineOffset; float bottom = top + underlineThickness; - myVertices.Append(Vertex(Vector2f(0, top), myColor, Vector2i(1, 1))); - myVertices.Append(Vertex(Vector2f(x, top), myColor, Vector2i(2, 1))); - myVertices.Append(Vertex(Vector2f(x, bottom), myColor, Vector2i(2, 2))); - myVertices.Append(Vertex(Vector2f(0, bottom), myColor, Vector2i(1, 2))); + myVertices.Append(Vertex(Vector2f(0, top), myColor, Vector2f(1, 1))); + myVertices.Append(Vertex(Vector2f(x, top), myColor, Vector2f(2, 1))); + myVertices.Append(Vertex(Vector2f(x, bottom), myColor, Vector2f(2, 2))); + myVertices.Append(Vertex(Vector2f(0, bottom), myColor, Vector2f(1, 2))); } // Recompute the bounding rectangle diff --git a/src/SFML/Graphics/Vertex.cpp b/src/SFML/Graphics/Vertex.cpp index 43cf19056..abdbedcdd 100644 --- a/src/SFML/Graphics/Vertex.cpp +++ b/src/SFML/Graphics/Vertex.cpp @@ -58,7 +58,7 @@ TexCoords(0, 0) //////////////////////////////////////////////////////////// -Vertex::Vertex(const Vector2f& position, const Vector2i& texCoords) : +Vertex::Vertex(const Vector2f& position, const Vector2f& texCoords) : Position (position), Color (255, 255, 255), TexCoords(texCoords) @@ -67,7 +67,7 @@ TexCoords(texCoords) //////////////////////////////////////////////////////////// -Vertex::Vertex(const Vector2f& position, const sf::Color& color, const Vector2i& texCoords) : +Vertex::Vertex(const Vector2f& position, const sf::Color& color, const Vector2f& texCoords) : Position (position), Color (color), TexCoords(texCoords)