mirror of
https://github.com/SFML/SFML.git
synced 2025-02-16 21:38:00 +08:00
Changed the type of Vertex::TexCoords from integers to floats, to make it compatible with buggy ATI drivers
This commit is contained in:
parent
5a4e8d58af
commit
b65b19343a
@ -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
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
|
@ -201,7 +201,7 @@ void RenderTarget::Draw(const Vertex* vertices, unsigned int verticesCount,
|
||||
const char* data = reinterpret_cast<const char*>(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,
|
||||
|
@ -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<int>(myTextureRect.Left + myTextureRect.Width * xratio);
|
||||
myVertices[i].TexCoords.y = static_cast<int>(myTextureRect.Top + myTextureRect.Height * yratio);
|
||||
myVertices[i].TexCoords.x = myTextureRect.Left + myTextureRect.Width * xratio;
|
||||
myVertices[i].TexCoords.y = myTextureRect.Top + myTextureRect.Height * yratio;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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<float>(myTextureRect.Left);
|
||||
float right = left + myTextureRect.Width;
|
||||
float top = static_cast<float>(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
|
||||
|
@ -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<float>(glyph.TextureRect.Left);
|
||||
float v1 = static_cast<float>(glyph.TextureRect.Top);
|
||||
float u2 = static_cast<float>(glyph.TextureRect.Left + glyph.TextureRect.Width);
|
||||
float v2 = static_cast<float>(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
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user