How to Read in Coordinates and Draw Shapes Sfml
Image living on the graphics carte that can be used for drawing. More...
#include <Texture.hpp>
Public Fellow member Functions | |
| Texture () | |
| Default constructor. More... | |
| Texture (const Texture ©) | |
| Copy constructor. More... | |
| ~Texture () | |
| Destructor. More... | |
| bool | create (unsigned int width, unsigned int height) |
| Create the texture. More... | |
| bool | loadFromFile (const std::string &filename, const IntRect &area=IntRect()) |
| Load the texture from a file on disk. More... | |
| bool | loadFromMemory (const void *data, std::size_t size, const IntRect &area=IntRect()) |
| Load the texture from a file in memory. More... | |
| bool | loadFromStream (sf::InputStream &stream, const IntRect &area=IntRect()) |
| Load the texture from a custom stream. More than... | |
| bool | loadFromImage (const Epitome &image, const IntRect &surface area=IntRect()) |
| Load the texture from an image. More... | |
| Vector2u | getSize () const |
| Return the size of the texture. More... | |
| Image | copyToImage () const |
| Copy the texture pixels to an image. More than... | |
| void | update (const Uint8 *pixels) |
| Update the whole texture from an assortment of pixels. More... | |
| void | update (const Uint8 *pixels, unsigned int width, unsigned int height, unsigned int ten, unsigned int y) |
| Update a function of the texture from an assortment of pixels. More... | |
| void | update (const Image &image) |
| Update the texture from an image. More... | |
| void | update (const Epitome &prototype, unsigned int 10, unsigned int y) |
| Update a office of the texture from an image. More... | |
| void | update (const Window &window) |
| Update the texture from the contents of a window. More... | |
| void | update (const Window &window, unsigned int ten, unsigned int y) |
| Update a role of the texture from the contents of a window. More... | |
| void | setSmooth (bool smooth) |
| Enable or disable the shine filter. More... | |
| bool | isSmooth () const |
| Tell whether the smooth filter is enabled or non. More... | |
| void | setRepeated (bool repeated) |
| Enable or disable repeating. More... | |
| bool | isRepeated () const |
| Tell whether the texture is repeated or non. More... | |
| Texture & | operator= (const Texture &right) |
| Overload of assignment operator. More... | |
Static Public Member Functions | |
| static void | bind (const Texture *texture, CoordinateType coordinateType=Normalized) |
| Bind a texture for rendering. More... | |
| static unsigned int | getMaximumSize () |
| Get the maximum texture size allowed. More than... | |
Static Private Member Functions | |
| static void | ensureGlContext () |
| Make sure that a valid OpenGL context exists in the current thread. More... | |
Friends | |
| class | RenderTexture |
| class | RenderTarget |
Epitome living on the graphics card that can be used for cartoon.
sf::Texture stores pixels that tin be drawn, with a sprite for case.
A texture lives in the graphics card memory, therefore it is very fast to depict a texture to a render target, or copy a render target to a texture (the graphics card can access both direct).
Beingness stored in the graphics menu retention has some drawbacks. A texture cannot exist manipulated as freely equally a sf::Image, you need to gear up the pixels first and and so upload them to the texture in a single operation (come across Texture::update).
sf::Texture makes it like shooting fish in a barrel to convert from/to sf::Paradigm, but go along in mind that these calls crave transfers betwixt the graphics card and the cardinal memory, therefore they are slow operations.
A texture can be loaded from an image, simply too direct from a file/memory/stream. The necessary shortcuts are defined and then that y'all don't demand an prototype start for the most common cases. However, if y'all desire to perform some modifications on the pixels before creating the final texture, yous tin load your file to a sf::Image, do whatever you need with the pixels, and and then phone call Texture::loadFromImage.
Since they alive in the graphics carte du jour retention, the pixels of a texture cannot be accessed without a boring re-create first. And they cannot be accessed individually. Therefore, if yous need to read the texture'southward pixels (similar for pixel-perfect collisions), it is recommended to store the collision information separately, for example in an array of booleans.
Like sf::Image, sf::Texture can handle a unique internal representation of pixels, which is RGBA 32 bits. This ways that a pixel must be composed of 8 $.25 red, green, blue and alpha channels – just similar a sf::Color.
Usage example:
return -1;
window.draw(sprite);
if (!texture.create(640, 480))
render -1;
while (...)
{
...
sf::Uint8* pixels = ...;
window.describe(sprite);
...
}
Like sf::Shader that can exist used as a raw OpenGL shader, sf::Texture can likewise be used directly as a raw texture for custom OpenGL geometry.
... render OpenGL geometry ...
sf::Texture::demark(NULL);
- See also
- sf::Sprite, sf::Image, sf::RenderTexture
Definition at line 47 of file Texture.hpp.
Types of texture coordinates that can be used for rendering.
| Enumerator | |
|---|---|
| Normalized | Texture coordinates in range [0 .. 1]. |
| Pixels | Texture coordinates in range [0 .. size]. |
Definition at line 55 of file Texture.hpp.
Default constructor.
Creates an empty texture.
| sf::Texture::Texture | ( | const Texture & | copy | ) |
Copy constructor.
- Parameters
| sf::Texture::~Texture | ( | ) |
Destructor.
Bind a texture for rendering.
This function is non function of the graphics API, it mustn't be used when drawing SFML entities. It must be used just if you mix sf::Texture with OpenGL code.
...
sf::Texture::demark(&t1);
The coordinateType statement controls how texture coordinates volition be interpreted. If Normalized (the default), they must be in range [0 .. one], which is the default way of handling texture coordinates with OpenGL. If Pixels, they must be given in pixels (range [0 .. size]). This mode is used internally past the graphics classes of SFML, it makes the definition of texture coordinates more intuitive for the high-level API, users don't demand to compute normalized values.
- Parameters
-
texture Pointer to the texture to bind, can be null to use no texture coordinateType Type of texture coordinates to use
| Prototype sf::Texture::copyToImage | ( | ) | const |
Copy the texture pixels to an image.
This role performs a ho-hum operation that downloads the texture's pixels from the graphics card and copies them to a new image, potentially applying transformations to pixels if necessary (texture may exist padded or flipped).
- Returns
- Image containing the texture's pixels
- See also
- loadFromImage
| bool sf::Texture::create | ( | unsigned int | width, |
| unsigned int | height | ||
| ) |
Create the texture.
If this part fails, the texture is left unchanged.
- Parameters
-
width Width of the texture height Height of the texture
- Returns
- True if creation was successful
| static |
Get the maximum texture size immune.
This maximum size is defined by the graphics driver. Y'all tin can await a value of 512 pixels for depression-stop graphics card, and up to 8192 pixels or more than for newer hardware.
Note: The first call to this part, whether by your code or SFML volition outcome in a context switch.
- Returns
- Maximum size allowed for textures, in pixels
Return the size of the texture.
- Returns
- Size in pixels
| bool sf::Texture::isRepeated | ( | ) | const |
Tell whether the texture is repeated or not.
- Returns
- True if repeat fashion is enabled, faux if it is disabled
- See also
- setRepeated
| bool sf::Texture::isSmooth | ( | ) | const |
Tell whether the smooth filter is enabled or not.
- Returns
- True if smoothing is enabled, false if information technology is disabled
- See likewise
- setSmooth
| bool sf::Texture::loadFromFile | ( | const std::string & | filename, |
| const IntRect & | area = IntRect() | ||
| ) |
Load the texture from a file on disk.
This function is a shortcut for the post-obit code:
The area argument can be used to load just a sub-rectangle of the whole image. If you want the entire image then exit the default value (which is an empty IntRect). If the expanse rectangle crosses the bounds of the image, it is adjusted to fit the image size.
The maximum size for a texture depends on the graphics driver and tin exist retrieved with the getMaximumSize role.
If this role fails, the texture is left unchanged.
- Parameters
-
filename Path of the image file to load area Area of the prototype to load
- Returns
- True if loading was successful
- See also
- loadFromMemory, loadFromStream, loadFromImage
Load the texture from an paradigm.
The area statement can be used to load just a sub-rectangle of the whole paradigm. If you desire the unabridged image then go out the default value (which is an empty IntRect). If the area rectangle crosses the premises of the epitome, it is adjusted to fit the image size.
The maximum size for a texture depends on the graphics driver and can exist retrieved with the getMaximumSize function.
If this office fails, the texture is left unchanged.
- Parameters
-
image Image to load into the texture surface area Area of the paradigm to load
- Returns
- True if loading was successful
- Encounter also
- loadFromFile, loadFromMemory
| bool sf::Texture::loadFromMemory | ( | const void * | data, |
| std::size_t | size, | ||
| const IntRect & | surface area = IntRect() | ||
| ) |
Load the texture from a file in memory.
This function is a shortcut for the following code:
The area argument tin be used to load just a sub-rectangle of the whole image. If you want the entire image then leave the default value (which is an empty IntRect). If the area rectangle crosses the premises of the prototype, it is adjusted to fit the paradigm size.
The maximum size for a texture depends on the graphics driver and can be retrieved with the getMaximumSize part.
If this office fails, the texture is left unchanged.
- Parameters
-
data Pointer to the file data in retentiveness size Size of the data to load, in bytes area Area of the image to load
- Returns
- True if loading was successful
- See also
- loadFromFile, loadFromStream, loadFromImage
Load the texture from a custom stream.
This function is a shortcut for the following code:
The area argument tin can be used to load only a sub-rectangle of the whole image. If you desire the entire image then get out the default value (which is an empty IntRect). If the area rectangle crosses the premises of the epitome, it is adapted to fit the image size.
The maximum size for a texture depends on the graphics commuter and can be retrieved with the getMaximumSize function.
If this part fails, the texture is left unchanged.
- Parameters
-
stream Source stream to read from area Area of the paradigm to load
- Returns
- Truthful if loading was successful
- Come across also
- loadFromFile, loadFromMemory, loadFromImage
Overload of assignment operator.
- Parameters
- Returns
- Reference to self
| void sf::Texture::setRepeated | ( | bool | repeated | ) |
Enable or disable repeating.
Repeating is involved when using texture coordinates outside the texture rectangle [0, 0, width, peak]. In this case, if repeat fashion is enabled, the whole texture will be repeated as many times as needed to reach the coordinate (for example, if the 10 texture coordinate is 3 * width, the texture will be repeated 3 times). If repeat mode is disabled, the "actress space" will instead be filled with border pixels. Warning: on very one-time graphics cards, white pixels may appear when the texture is repeated. With such cards, repeat mode tin be used reliably just if the texture has power-of-two dimensions (such as 256x128). Repeating is disabled by default.
- Parameters
-
repeated True to repeat the texture, false to disable repeating
- Come across also
- isRepeated
| void sf::Texture::setSmooth | ( | bool | smoothen | ) |
Enable or disable the smooth filter.
When the filter is activated, the texture appears smoother so that pixels are less noticeable. Still if you lot want the texture to look exactly the same every bit its source file, you should leave information technology disabled. The polish filter is disabled past default.
- Parameters
-
shine True to enable smoothing, simulated to disable it
- See as well
- isSmooth
| void sf::Texture::update | ( | const Uint8 * | pixels | ) |
Update the whole texture from an array of pixels.
The pixel array is causeless to have the same size as the expanse rectangle, and to contain 32-bits RGBA pixels.
No additional bank check is performed on the size of the pixel array, passing invalid arguments volition lead to an undefined behavior.
This function does nothing if pixels is null or if the texture was not previously created.
- Parameters
-
pixels Array of pixels to copy to the texture
| void sf::Texture::update | ( | const Uint8 * | pixels, |
| unsigned int | width, | ||
| unsigned int | superlative, | ||
| unsigned int | x, | ||
| unsigned int | y | ||
| ) |
Update a part of the texture from an assortment of pixels.
The size of the pixel array must friction match the width and pinnacle arguments, and it must incorporate 32-bits RGBA pixels.
No additional check is performed on the size of the pixel assortment or the bounds of the surface area to update, passing invalid arguments will lead to an undefined behavior.
This function does nix if pixels is null or if the texture was not previously created.
- Parameters
-
pixels Assortment of pixels to copy to the texture width Width of the pixel region independent in pixels height Height of the pixel region contained in pixels x X offset in the texture where to copy the source pixels y Y offset in the texture where to copy the source pixels
| void sf::Texture::update | ( | const Prototype & | prototype | ) |
Update the texture from an paradigm.
Although the source image can be smaller than the texture, this function is usually used for updating the whole texture. The other overload, which has (ten, y) additional arguments, is more convenient for updating a sub-area of the texture.
No additional cheque is performed on the size of the paradigm, passing an image bigger than the texture volition atomic number 82 to an undefined behavior.
This function does nothing if the texture was not previously created.
- Parameters
-
image Image to re-create to the texture
| void sf::Texture::update | ( | const Image & | paradigm, |
| unsigned int | 10, | ||
| unsigned int | y | ||
| ) |
Update a office of the texture from an image.
No boosted check is performed on the size of the image, passing an invalid combination of paradigm size and offset will lead to an undefined beliefs.
This function does nothing if the texture was not previously created.
- Parameters
-
prototype Prototype to copy to the texture x 10 beginning in the texture where to copy the source image y Y offset in the texture where to copy the source prototype
| void sf::Texture::update | ( | const Window & | window | ) |
Update the texture from the contents of a window.
Although the source window tin can be smaller than the texture, this role is usually used for updating the whole texture. The other overload, which has (x, y) additional arguments, is more convenient for updating a sub-area of the texture.
No additional check is performed on the size of the window, passing a window bigger than the texture will lead to an undefined beliefs.
This role does nothing if either the texture or the window was not previously created.
- Parameters
-
window Window to copy to the texture
| void sf::Texture::update | ( | const Window & | window, |
| unsigned int | x, | ||
| unsigned int | y | ||
| ) |
Update a part of the texture from the contents of a window.
No additional cheque is performed on the size of the window, passing an invalid combination of window size and offset volition atomic number 82 to an undefined beliefs.
This function does nix if either the texture or the window was not previously created.
- Parameters
-
window Window to copy to the texture ten 10 kickoff in the texture where to copy the source window y Y offset in the texture where to copy the source window
The documentation for this class was generated from the following file:
- Texture.hpp
Source: https://progsv.epfl.ch/www/doc-sfml/html/classsf_1_1Texture.htm
0 Response to "How to Read in Coordinates and Draw Shapes Sfml"
Post a Comment