CSFML 3.0.0
Loading...
Searching...
No Matches
Functions
Texture.h File Reference
`#include <CSFML/Graphics/Export.h>`
`#include <CSFML/Graphics/CoordinateType.h>`
`#include <CSFML/Graphics/Rect.h>`
`#include <CSFML/Graphics/Types.h>`
`#include <CSFML/System/InputStream.h>`
`#include <CSFML/System/Vector2.h>`
`#include <CSFML/Window/Types.h>`
`#include <stddef.h>`

Go to the source code of this file.

## Functions
sfTexture * | sfTexture_create (sfVector2u size)
| Create a new texture.
sfTexture * | sfTexture_createSrgb (sfVector2u size)
| Create a new sRGB-enabled texture.
sfTexture * | sfTexture_createFromFile (const char *filename, const sfIntRect *area)
| Create a new texture from a file.
sfTexture * | sfTexture_createSrgbFromFile (const char *filename, const sfIntRect *area)
| Create a new sRGB-enabled texture from a file.
sfTexture * | sfTexture_createFromMemory (const void *data, size_t sizeInBytes, const sfIntRect *area)
| Create a new texture from a file in memory.
sfTexture * | sfTexture_createSrgbFromMemory (const void *data, size_t sizeInBytes, const sfIntRect *area)
| Create a new sRGB-enabled texture from a file in memory.
sfTexture * | sfTexture_createFromStream (sfInputStream *stream, const sfIntRect *area)
| Create a new texture from a custom stream.
sfTexture * | sfTexture_createSrgbFromStream (sfInputStream *stream, const sfIntRect *area)
| Create a new sRGB-enabled texture from a custom stream.
sfTexture * | sfTexture_createFromImage (const sfImage *image, const sfIntRect *area)
| Create a new texture from an image.
sfTexture * | sfTexture_createSrgbFromImage (const sfImage *image, const sfIntRect *area)
| Create a new sRGB-enabled texture from an image.
sfTexture * | sfTexture_copy (const sfTexture *texture)
| Copy an existing texture.
void | sfTexture_destroy (const sfTexture *texture)
| Destroy an existing texture.
bool | sfTexture_resize (sfTexture *texture, sfVector2u size, bool sRgb)
| Resize the texture.
sfVector2u | sfTexture_getSize (const sfTexture *texture)
| Return the size of the texture.
sfImage * | sfTexture_copyToImage (const sfTexture *texture)
| Copy a texture's pixels to an image.
void | sfTexture_updateFromPixels (sfTexture *texture, const uint8_t *pixels, sfVector2u size, sfVector2u offset)
| Update a texture from an array of pixels.
void | sfTexture_updateFromTexture (sfTexture *destination, const sfTexture *source, sfVector2u offset)
| Update a part of this texture from another texture.
void | sfTexture_updateFromImage (sfTexture *texture, const sfImage *image, sfVector2u offset)
| Update a texture from an image.
void | sfTexture_updateFromWindow (sfTexture *texture, const sfWindow *window, sfVector2u offset)
| Update a texture from the contents of a window.
void | sfTexture_updateFromRenderWindow (sfTexture *texture, const sfRenderWindow *renderWindow, sfVector2u offset)
| Update a texture from the contents of a render-window.
void | sfTexture_setSmooth (sfTexture *texture, bool smooth)
| Enable or disable the smooth filter on a texture.
bool | sfTexture_isSmooth (const sfTexture *texture)
| Tell whether the smooth filter is enabled or not for a texture.
bool | sfTexture_isSrgb (const sfTexture *texture)
| Tell whether the texture source is converted from sRGB or not.
void | sfTexture_setRepeated (sfTexture *texture, bool repeated)
| Enable or disable repeating for a texture.
bool | sfTexture_isRepeated (const sfTexture *texture)
| Tell whether a texture is repeated or not.
bool | sfTexture_generateMipmap (sfTexture *texture)
| Generate a mipmap using the current texture data.
void | sfTexture_swap (sfTexture *left, sfTexture *right)
| Swap the contents of a texture with those of another.
unsigned int | sfTexture_getNativeHandle (const sfTexture *texture)
| Get the underlying OpenGL handle of the texture.
void | sfTexture_bind (const sfTexture *texture, sfCoordinateType type)
| Bind a texture for rendering.
unsigned int | sfTexture_getMaximumSize (void)
| Get the maximum texture size allowed.

## Function Documentation

## ◆ sfTexture_bind()

void sfTexture_bind | ( | const sfTexture * | texture,
|  | sfCoordinateType | type )

Bind a texture for rendering.

This function is not part of the graphics API, it mustn't be used when drawing SFML entities. It must be used only if you mix sfTexture with OpenGL code.

sfTexture *t1, *t2;
...
sfTexture_bind(t1);
// draw OpenGL stuff that use t1...
sfTexture_bind(t2);
// draw OpenGL stuff that use t2...
sfTexture_bind(NULL);
// draw OpenGL stuff that use no texture...
sfTexture
struct sfTexture sfTexture
Definition Graphics/Types.h:39
sfTexture_bind
void sfTexture_bind(const sfTexture *texture, sfCoordinateType type)
Bind a texture for rendering.

Parameters

  texture | Pointer to the texture to bind, can be null to use no texture
  type | Type of texture coordinates to use

## ◆ sfTexture_copy()

sfTexture * sfTexture_copy | ( | const sfTexture * | texture | ) |

Copy an existing texture.

Parameters

  texture | Texture to copy

Returns
  Copied object

## ◆ sfTexture_copyToImage()

sfImage * sfTexture_copyToImage | ( | const sfTexture * | texture | ) |

Copy a texture's pixels to an image.

Parameters

  texture | Texture to copy

Returns
  Image containing the texture's pixels

## ◆ sfTexture_create()

sfTexture * sfTexture_create | ( | sfVector2u | size | ) |

Create a new texture.

Parameters

  size | Texture size

Returns
  A new sfTexture object, or NULL if it failed

## ◆ sfTexture_createFromFile()

sfTexture * sfTexture_createFromFile | ( | const char * | filename,
|  | const sfIntRect * | area )

Create a new texture from a file.

Parameters

  filename | Path of the image file to load
  area | Area of the source image to load (NULL to load the entire image)

Returns
  A new sfTexture object, or NULL if it failed

## ◆ sfTexture_createFromImage()

sfTexture * sfTexture_createFromImage | ( | const sfImage * | image,
|  | const sfIntRect * | area )

Create a new texture from an image.

Parameters

  image | Image to upload to the texture
  area | Area of the source image to load (NULL to load the entire image)

Returns
  A new sfTexture object, or NULL if it failed

## ◆ sfTexture_createFromMemory()

sfTexture * sfTexture_createFromMemory | ( | const void * | data,
|  | size_t | sizeInBytes,
|  | const sfIntRect * | area )

Create a new texture from a file in memory.

Parameters

  data | Pointer to the file data in memory
  sizeInBytes | Size of the data to load, in bytes
  area | Area of the source image to load (NULL to load the entire image)

Returns
  A new sfTexture object, or NULL if it failed

## ◆ sfTexture_createFromStream()

sfTexture * sfTexture_createFromStream | ( | sfInputStream * | stream,
|  | const sfIntRect * | area )

Create a new texture from a custom stream.

Parameters

  stream | Source stream to read from
  area | Area of the source image to load (NULL to load the entire image)

Returns
  A new sfTexture object, or NULL if it failed

## ◆ sfTexture_createSrgb()

sfTexture * sfTexture_createSrgb | ( | sfVector2u | size | ) |

Create a new sRGB-enabled texture.

Parameters

  size | Texture size

Returns
  A new sfTexture object, or NULL if it failed

## ◆ sfTexture_createSrgbFromFile()

sfTexture * sfTexture_createSrgbFromFile | ( | const char * | filename,
|  | const sfIntRect * | area )

Create a new sRGB-enabled texture from a file.

When providing texture data from an image file or memory, it can either be stored in a linear color space or an sRGB color space. Most digital images account for gamma correction already, so they would need to be "uncorrected" back to linear color space before being processed by the hardware. The hardware can automatically convert it from the sRGB color space to a linear color space when it gets sampled. When the rendered image gets output to the final framebuffer, it gets converted back to sRGB.

This load option is only useful in conjunction with an sRGB capable framebuffer. This can be requested during window creation.

Parameters

  filename | Path of the image file to load
  area | Area of the source image to load (NULL to load the entire image)

Returns
  A new sfTexture object, or NULL if it failed

## ◆ sfTexture_createSrgbFromImage()

sfTexture * sfTexture_createSrgbFromImage | ( | const sfImage * | image,
|  | const sfIntRect * | area )

Create a new sRGB-enabled texture from an image.

Parameters

  image | Image to upload to the texture
  area | Area of the source image to load (NULL to load the entire image)

Returns
  A new sfTexture object, or NULL if it failed

## ◆ sfTexture_createSrgbFromMemory()

sfTexture * sfTexture_createSrgbFromMemory | ( | const void * | data,
|  | size_t | sizeInBytes,
|  | const sfIntRect * | area )

Create a new sRGB-enabled texture from a file in memory.

Parameters

  data | Pointer to the file data in memory
  sizeInBytes | Size of the data to load, in bytes
  area | Area of the source image to load (NULL to load the entire image)

Returns
  A new sfTexture object, or NULL if it failed

## ◆ sfTexture_createSrgbFromStream()

sfTexture * sfTexture_createSrgbFromStream | ( | sfInputStream * | stream,
|  | const sfIntRect * | area )

Create a new sRGB-enabled texture from a custom stream.

Parameters

  stream | Source stream to read from
  area | Area of the source image to load (NULL to load the entire image)

Returns
  A new sfTexture object, or NULL if it failed

## ◆ sfTexture_destroy()

void sfTexture_destroy | ( | const sfTexture * | texture | ) |

Destroy an existing texture.

Parameters

  texture | Texture to delete

## ◆ sfTexture_generateMipmap()

bool sfTexture_generateMipmap | ( | sfTexture * | texture | ) |

Generate a mipmap using the current texture data.

Mipmaps are pre-computed chains of optimized textures. Each level of texture in a mipmap is generated by halving each of the previous level's dimensions. This is done until the final level has the size of 1x1. The textures generated in this process may make use of more advanced filters which might improve the visual quality of textures when they are applied to objects much smaller than they are. This is known as minification. Because fewer texels (texture elements) have to be sampled from when heavily minified, usage of mipmaps can also improve rendering performance in certain scenarios.

Mipmap generation relies on the necessary OpenGL extension being available. If it is unavailable or generation fails due to another reason, this function will return false. Mipmap data is only valid from the time it is generated until the next time the base level image is modified, at which point this function will have to be called again to regenerate it.

Returns
  true if mipmap generation was successful, false if unsuccessful

## ◆ sfTexture_getMaximumSize()

unsigned int sfTexture_getMaximumSize | ( | void |  | ) |

Get the maximum texture size allowed.

Returns
  Maximum size allowed for textures, in pixels

## ◆ sfTexture_getNativeHandle()

unsigned int sfTexture_getNativeHandle | ( | const sfTexture * | texture | ) |

Get the underlying OpenGL handle of the texture.

You shouldn't need to use this function, unless you have very specific stuff to implement that SFML doesn't support, or implement a temporary workaround until a bug is fixed.

Parameters

  texture | The texture object

Returns
  OpenGL handle of the texture or 0 if not yet created

## ◆ sfTexture_getSize()

sfVector2u sfTexture_getSize | ( | const sfTexture * | texture | ) |

Return the size of the texture.

Parameters

  texture | Texture to read

Returns
  Size in pixels

## ◆ sfTexture_isRepeated()

bool sfTexture_isRepeated | ( | const sfTexture * | texture | ) |

Tell whether a texture is repeated or not.

Parameters

  texture | The texture object

Returns
  true if repeat mode is enabled, false if it is disabled

## ◆ sfTexture_isSmooth()

bool sfTexture_isSmooth | ( | const sfTexture * | texture | ) |

Tell whether the smooth filter is enabled or not for a texture.

Parameters

  texture | The texture object

Returns
  true if smoothing is enabled, false if it is disabled

## ◆ sfTexture_isSrgb()

bool sfTexture_isSrgb | ( | const sfTexture * | texture | ) |

Tell whether the texture source is converted from sRGB or not.

Returns
  True if the texture source is converted from sRGB, false if not

See also
  sfTexture_createSrgbFromFile
  sfTexture_createSrgbFromMemory
  sfTexture_createSrgbFromStream
  sfTexture_createSrgbFromImage

## ◆ sfTexture_resize()

bool sfTexture_resize | ( | sfTexture * | texture,
|  | sfVector2u | size,
|  | bool | sRgb )

Resize the texture.

If this function fails, the texture is left unchanged.

Parameters

  texture | Texture to resize
  size | Width and height of the texture
  sRgb | true to enable sRGB conversion, false to disable it

Returns
  true if resizing was successful, false if it failed

## ◆ sfTexture_setRepeated()

void sfTexture_setRepeated | ( | sfTexture * | texture,
|  | bool | repeated )

Enable or disable repeating for a texture.

Repeating is involved when using texture coordinates outside the texture rectangle [0, 0, width, height]. In this case, if repeat mode is enabled, the whole texture will be repeated as many times as needed to reach the coordinate (for example, if the X texture coordinate is 3 * width, the texture will be repeated 3 times). If repeat mode is disabled, the "extra space" will instead be filled with border pixels. Warning: on very old graphics cards, white pixels may appear when the texture is repeated. With such cards, repeat mode can be used reliably only if the texture has power-of-two dimensions (such as 256x128). Repeating is disabled by default.

Parameters

  texture | The texture object
  repeated | True to repeat the texture, false to disable repeating

## ◆ sfTexture_setSmooth()

void sfTexture_setSmooth | ( | sfTexture * | texture,
|  | bool | smooth )

Enable or disable the smooth filter on a texture.

Parameters

  texture | The texture object
  smooth | true to enable smoothing, false to disable it

## ◆ sfTexture_swap()

void sfTexture_swap | ( | sfTexture * | left,
|  | sfTexture * | right )

Swap the contents of a texture with those of another.

Parameters

  left | Instance to swap from
  right | Instance to swap with

## ◆ sfTexture_updateFromImage()

void sfTexture_updateFromImage | ( | sfTexture * | texture,
|  | const sfImage * | image,
|  | sfVector2u | offset )

Update a texture from an image.

Parameters

  texture | Texture to update
  image | Image to copy to the texture
  offset | Offset in the texture where to copy the source pixels

## ◆ sfTexture_updateFromPixels()

void sfTexture_updateFromPixels | ( | sfTexture * | texture,
|  | const uint8_t * | pixels,
|  | sfVector2u | size,
|  | sfVector2u | offset )

Update a texture from an array of pixels.

Parameters

  texture | Texture to update
  pixels | Array of pixels to copy to the texture
  size | size of the pixel region contained in pixels
  offset | Offset in the texture where to copy the source pixels

## ◆ sfTexture_updateFromRenderWindow()

void sfTexture_updateFromRenderWindow | ( | sfTexture * | texture,
|  | const sfRenderWindow * | renderWindow,
|  | sfVector2u | offset )

Update a texture from the contents of a render-window.

Parameters

  texture | Texture to update
  renderWindow | Render-window to copy to the texture
  offset | Offset in the texture where to copy the source pixels

## ◆ sfTexture_updateFromTexture()

void sfTexture_updateFromTexture | ( | sfTexture * | destination,
|  | const sfTexture * | source,
|  | sfVector2u | offset )

Update a part of this texture from another texture.

No additional check is performed on the size of the texture, passing an invalid combination of texture size and offset will lead to an undefined behavior.

This function does nothing if either texture was not previously created.

Parameters

  destination | Destination texture to copy source texture to
  source | Source texture to copy to destination texture
  offset | Offset in this texture where to copy the source texture

## ◆ sfTexture_updateFromWindow()

void sfTexture_updateFromWindow | ( | sfTexture * | texture,
|  | const sfWindow * | window,
|  | sfVector2u | offset )

Update a texture from the contents of a window.

Parameters

  texture | Texture to update
  window | Window to copy to the texture
  offset | Offset in the texture where to copy the source pixels