banner



What Is Different Between Sprites And Drawing Shapes?

Become a Patron! Buy me a coffee!

Textures, Sprites and Shapes

In this tutorial we volition swoop deep into the differences between textures, sprites and shapes for SFML.

Textures : sf::Texture

The texture is basically an epitome loaded into the VRAM, the VRAM is the memory of the graphics card if you take a graphic menu with dedicated retention. If y'all have an integrated retentivity card the RAM of the computer is used instead.
That is good to know but what does it ways concretly for a texture ?

The texture is employ for the sprite if you want to display information technology on the screen.

If you desire to admission the pixels and practice some images manipulation other than size and rotation you need to have the paradigm in the RAM.
For that that you volition use the class sf::Image, keep in mind if you lot desire to display the paradigm after some pixels modifications yous will need to convert bakc the image to a texture.

The operation of loading textures/images, converting between texture and image are slow operations.

And so if you really need to do it, do the work once and cache it!
If you want to know all the methods bachelor for the sf:Texture become check the sf:Texture Documentation
For the sf::Epitome : sf::Image Documentation

Sprites : sf::Sprite

If you want to display a texture you lot must utilise a sprite. Why ? Well to display something you need to take a sf::RenderWindow or a sf::sf::RenderTexture. In the documentation the draw methods are:

          void 	draw (const Drawable &drawable, const RenderStates &states=RenderStates::Default) void	draw (const Vertex *vertices, std::size_t vertexCount, PrimitiveType blazon, const RenderStates &states=RenderStates::Default) void 	depict (const VertexBuffer &vertexBuffer, const RenderStates &states=RenderStates::Default) void 	depict (const VertexBuffer &vertexBuffer, std::size_t firstVertex, std::size_t vertexCount, const RenderStates &states=RenderStates::Default)        

classes Hierarchy

Shapes

Circles : sf::CircleShape

To depict a circle you must use the form sf::CircleShape, in the constructor you lot must specify the radius of the circumvolve. And then you tin can gear up the filling color and the outline color.

          sf::CircleShape shape(30.f); shape.setFillColor(sf::Color(0, 0, 255)); shape.setOutlineThickness(5.f); shape.setOutlineColor(sf::Color(255, 0, 0));        

You tin also ready a texture with shape.setTexture(&tex); and simply take a small part of the texture with shape.setTextureRect(sf::IntRect(ii, v, l, twenty));

Rectangle

To draw a rectangle you will need to apply the class sf::rectangleShape:

          sf::RectangleShape rectangle(sf::Vector2f(10.f, 30.f)); rectangle.setSize(sf::Vector2f(200.f, 50.f));        

Polygon

To display a polygon you lot tin can use the class sf::ConvexShape:

          sf::ConvexShape poly;  poly.setPointCount(6); poly.setPoint(0, sf::Vector2f(142.f, 112.f)); poly.setPoint(ane, sf::Vector2f(204.f, 74.f)); poly.setPoint(two, sf::Vector2f(234.f, 101.f)); poly.setPoint(3, sf::Vector2f(261.f, 145.f)); poly.setPoint(four, sf::Vector2f(176.f, 184.f)); poly.setPoint(iv, sf::Vector2f(135.f, 143.f)); poly.setFillColor(sf::Color(255, 0, 0));        

The points need to be in clockwise order or anti-clowise lodge !
If you have a concave shape you tin split information technology into a convex shape into triangles with a Delaunay triangulation, you tin can observe libraries and algorithm to compute the decompositon.

Source: https://glusoft.com/tutorials/sfml/textures-sprites-shapes

Posted by: crawfordthereque1967.blogspot.com

0 Response to "What Is Different Between Sprites And Drawing Shapes?"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel