Added sfTexture, renamed sfRenderImage to sfRenderTexture, removed sfSprite_GetPixel, added sfImage_FlipHorizontally and sfImage_FlipVertically

This commit is contained in:
Laurent Gomila committed 2011-08-06 14:50:14 +02:00
1 parent 29663b351d
commit f4eda513af
22 files changed
+1032 -530

No files matched your search

+2 -1
View File
@@ -35,11 +35,12 @@
#include <SFML/Graphics/Image.h>
#include <SFML/Graphics/Rect.h>
#include <SFML/Graphics/RenderWindow.h>
#include <SFML/Graphics/RenderImage.h>
#include <SFML/Graphics/RenderTexture.h>
#include <SFML/Graphics/Shader.h>
#include <SFML/Graphics/Shape.h>
#include <SFML/Graphics/Sprite.h>
#include <SFML/Graphics/Text.h>
#include <SFML/Graphics/Texture.h>
#include <SFML/Graphics/View.h>
+3 -3
View File
@@ -122,15 +122,15 @@ CSFML_API int sfFont_GetKerning(sfFont* font, sfUint32 first, sfUint32 second, u
CSFML_API int sfFont_GetLineSpacing(sfFont* font, unsigned int characterSize);
////////////////////////////////////////////////////////////
/// Get the image containing the glyphs of a given size in a font
/// Get the texture containing the glyphs of a given size in a font
///
/// \param font : Source font
/// \param characterSize : Character size, in pixels
///
/// \return Read-only pointer to the image
/// \return Read-only pointer to the texture
///
////////////////////////////////////////////////////////////
CSFML_API const sfImage* sfFont_GetImage(sfFont* font, unsigned int characterSize);
CSFML_API const sfTexture* sfFont_GetTexture(sfFont* font, unsigned int characterSize);
////////////////////////////////////////////////////////////
/// Get the built-in default font (Arial)
+11 -50
View File
@@ -144,19 +144,6 @@ CSFML_API void sfImage_CreateMaskFromColor(sfImage* image, sfColor colorKey, sfU
////////////////////////////////////////////////////////////
CSFML_API void sfImage_CopyImage(sfImage* image, const sfImage* source, unsigned int destX, unsigned int destY, sfIntRect sourceRect);
////////////////////////////////////////////////////////////
/// Create the image from the current contents of the
/// given window
///
/// \param image : Destination image
/// \param window : Window to capture
/// \param sourceRect : Sub-rectangle of the screen to copy (empty by default - entire image)
///
/// \return True if creation was successful
///
////////////////////////////////////////////////////////////
CSFML_API sfBool sfImage_CopyScreen(sfImage* image, sfRenderWindow* window, sfIntRect sourceRect);
////////////////////////////////////////////////////////////
/// Change the color of a pixel of an image
///
@@ -192,38 +179,6 @@ CSFML_API sfColor sfImage_GetPixel(const sfImage* image, unsigned int x, unsigne
////////////////////////////////////////////////////////////
CSFML_API const sfUint8* sfImage_GetPixelsPtr(const sfImage* image);
////////////////////////////////////////////////////////////
/// Update a sub-rectangle of the image from an array of pixels
///
/// Warning: for performances reasons, this function doesn't
/// perform any check; thus you're responsible of ensuring that
/// \a rectangle does not exceed the image size, and that
/// \a pixels contains enough elements.
///
/// \param image : Image to update
/// \param rectangle : Sub-rectangle of the image to update
/// \param pixels : Array of pixels to write to the image
///
////////////////////////////////////////////////////////////
CSFML_API void sfImage_UpdatePixels(const sfImage* image, const sfUint8* pixels, sfIntRect rectangle);
////////////////////////////////////////////////////////////
/// Bind the image for rendering
///
/// \param image : Image to bind
///
////////////////////////////////////////////////////////////
CSFML_API void sfImage_Bind(const sfImage* image);
////////////////////////////////////////////////////////////
/// Enable or disable image smooth filter
///
/// \param image : Image to modify
/// \param smooth : sfTrue to enable smoothing filter, false to disable it
///
////////////////////////////////////////////////////////////
CSFML_API void sfImage_SetSmooth(sfImage* image, sfBool smooth);
////////////////////////////////////////////////////////////
/// Return the width of the image
///
@@ -245,14 +200,20 @@ CSFML_API unsigned int sfImage_GetWidth(const sfImage* image);
CSFML_API unsigned int sfImage_GetHeight(const sfImage* image);
////////////////////////////////////////////////////////////
/// Tells whether the smoothing filter is enabled or not on an image
/// Flip an image horizontally (left <-> right)
///
/// \param image : Image to read
///
/// \return sfTrue if the smoothing filter is enabled
/// \param image : Image to flip
///
////////////////////////////////////////////////////////////
CSFML_API sfBool sfImage_IsSmooth(const sfImage* image);
CSFML_API void sfImage_FlipHorizontally(sfImage* image);
////////////////////////////////////////////////////////////
/// Flip an image vertically (top <-> bottom)
///
/// \param image : Image to flip
///
////////////////////////////////////////////////////////////
CSFML_API void sfImage_FlipVertically(sfImage* image);
#endif // SFML_IMAGE_H
@@ -22,8 +22,8 @@
//
////////////////////////////////////////////////////////////
#ifndef SFML_RENDERIMAGE_H
#define SFML_RENDERIMAGE_H
#ifndef SFML_RENDERTEXTURE_H
#define SFML_RENDERTEXTURE_H
////////////////////////////////////////////////////////////
// Headers
@@ -35,53 +35,53 @@
////////////////////////////////////////////////////////////
/// Construct a new renderimage
/// Construct a new rendertexture
///
/// \param width : Width of the renderimage
/// \param height : Height of the renderimage
/// \param depthBuffer : Do you want a depth-buffer attached? (useful only if you're doing 3D OpenGL on the renderimage)
/// \param width : Width of the rendertexture
/// \param height : Height of the rendertexture
/// \param depthBuffer : Do you want a depth-buffer attached? (useful only if you're doing 3D OpenGL on the rendertexture)
///
////////////////////////////////////////////////////////////
CSFML_API sfRenderImage* sfRenderImage_Create(unsigned int width, unsigned int height, sfBool depthBuffer);
CSFML_API sfRenderTexture* sfRenderTexture_Create(unsigned int width, unsigned int height, sfBool depthBuffer);
////////////////////////////////////////////////////////////
/// Destroy an existing renderimage
/// Destroy an existing rendertexture
///
/// \param renderImage : renderimage to destroy
/// \param renderTexture : rendertexture to destroy
///
////////////////////////////////////////////////////////////
CSFML_API void sfRenderImage_Destroy(sfRenderImage* renderImage);
CSFML_API void sfRenderTexture_Destroy(sfRenderTexture* renderTexture);
////////////////////////////////////////////////////////////
/// Get the width of the rendering region of a renderimage
/// Get the width of the rendering region of a rendertexture
///
/// \param renderImage : Renderimage object
/// \param renderTexture : Rendertexture object
///
/// \return Width in pixels
///
////////////////////////////////////////////////////////////
CSFML_API unsigned int sfRenderImage_GetWidth(const sfRenderImage* renderImage);
CSFML_API unsigned int sfRenderTexture_GetWidth(const sfRenderTexture* renderTexture);
////////////////////////////////////////////////////////////
/// Get the height of the rendering region of a renderimage
/// Get the height of the rendering region of a rendertexture
///
/// \param renderImage : Renderimage object
/// \param renderTexture : Rendertexture object
///
/// \return Height in pixels
///
////////////////////////////////////////////////////////////
CSFML_API unsigned int sfRenderImage_GetHeight(const sfRenderImage* renderImage);
CSFML_API unsigned int sfRenderTexture_GetHeight(const sfRenderTexture* renderTexture);
////////////////////////////////////////////////////////////
/// Activate or deactivate a renderimage as the current target for rendering
/// Activate or deactivate a rendertexture as the current target for rendering
///
/// \param renderImage : Renderimage object
/// \param renderTexture : Rendertexture object
/// \param active : sfTrue to activate, sfFalse to deactivate
///
/// \return True if operation was successful, false otherwise
///
////////////////////////////////////////////////////////////
CSFML_API sfBool sfRenderImage_SetActive(sfRenderImage* renderImage, sfBool active);
CSFML_API sfBool sfRenderTexture_SetActive(sfRenderTexture* renderTexture, sfBool active);
////////////////////////////////////////////////////////////
/// Save the current OpenGL render states and matrices
@@ -89,7 +89,7 @@ CSFML_API sfBool sfRenderImage_SetActive(sfRenderImage* renderImage, sfBool acti
/// \param renderWindow : Renderwindow object
///
////////////////////////////////////////////////////////////
CSFML_API void sfRenderImage_SaveGLStates(sfRenderImage* renderImage);
CSFML_API void sfRenderTexture_SaveGLStates(sfRenderTexture* renderTexture);
////////////////////////////////////////////////////////////
/// Restore the previously saved OpenGL render states and matrices
@@ -97,110 +97,110 @@ CSFML_API void sfRenderImage_SaveGLStates(sfRenderImage* renderImage);
/// \param renderWindow : Renderwindow object
///
////////////////////////////////////////////////////////////
CSFML_API void sfRenderImage_RestoreGLStates(sfRenderImage* renderImage);
CSFML_API void sfRenderTexture_RestoreGLStates(sfRenderTexture* renderTexture);
////////////////////////////////////////////////////////////
/// Update the contents of the target image
/// Update the contents of the target texture
///
/// \param renderImage : Renderimage object
/// \param renderTexture : Rendertexture object
///
////////////////////////////////////////////////////////////
CSFML_API void sfRenderImage_Display(sfRenderImage* renderImage);
CSFML_API void sfRenderTexture_Display(sfRenderTexture* renderTexture);
////////////////////////////////////////////////////////////
/// Draw something on a renderimage
/// Draw something on a rendertexture
///
/// \param renderImage : Renderimage to draw in
/// \param renderTexture : Rendertexture to draw in
/// \param sprite / text / shape : Object to draw
///
////////////////////////////////////////////////////////////
CSFML_API void sfRenderImage_DrawSprite(sfRenderImage* renderImage, const sfSprite* sprite);
CSFML_API void sfRenderImage_DrawShape (sfRenderImage* renderImage, const sfShape* shape);
CSFML_API void sfRenderImage_DrawText (sfRenderImage* renderImage, const sfText* text);
CSFML_API void sfRenderTexture_DrawSprite(sfRenderTexture* renderTexture, const sfSprite* sprite);
CSFML_API void sfRenderTexture_DrawShape (sfRenderTexture* renderTexture, const sfShape* shape);
CSFML_API void sfRenderTexture_DrawText (sfRenderTexture* renderTexture, const sfText* text);
////////////////////////////////////////////////////////////
/// Draw something on a renderimage with a shader
/// Draw something on a rendertexture with a shader
///
/// \param renderImage : Renderimage to draw in
/// \param renderTexture : Rendertexture to draw in
/// \param sprite / text / shape : Object to draw
/// \param shader : Shader to use
///
////////////////////////////////////////////////////////////
CSFML_API void sfRenderImage_DrawSpriteWithShader(sfRenderImage* renderImage, const sfSprite* sprite, const sfShader* shader);
CSFML_API void sfRenderImage_DrawShapeWithShader (sfRenderImage* renderImage, const sfShape* shape, const sfShader* shader);
CSFML_API void sfRenderImage_DrawTextWithShader (sfRenderImage* renderImage, const sfText* text, const sfShader* shader);
CSFML_API void sfRenderTexture_DrawSpriteWithShader(sfRenderTexture* renderTexture, const sfSprite* sprite, const sfShader* shader);
CSFML_API void sfRenderTexture_DrawShapeWithShader (sfRenderTexture* renderTexture, const sfShape* shape, const sfShader* shader);
CSFML_API void sfRenderTexture_DrawTextWithShader (sfRenderTexture* renderTexture, const sfText* text, const sfShader* shader);
////////////////////////////////////////////////////////////
/// Clear the renderimage with the given color
/// Clear the rendertexture with the given color
///
/// \param renderImage : Renderimage to modify
/// \param renderTexture : Rendertexture to modify
/// \param color : Fill color
///
////////////////////////////////////////////////////////////
CSFML_API void sfRenderImage_Clear(sfRenderImage* renderImage, sfColor color);
CSFML_API void sfRenderTexture_Clear(sfRenderTexture* renderTexture, sfColor color);
////////////////////////////////////////////////////////////
/// Change the current active view of a renderimage
/// Change the current active view of a rendertexture
///
/// \param renderImage : Renderimage to modify
/// \param renderTexture : Rendertexture to modify
/// \param view : Pointer to the new view
///
////////////////////////////////////////////////////////////
CSFML_API void sfRenderImage_SetView(sfRenderImage* renderImage, const sfView* view);
CSFML_API void sfRenderTexture_SetView(sfRenderTexture* renderTexture, const sfView* view);
////////////////////////////////////////////////////////////
/// Get the current active view of a renderimage
/// Get the current active view of a rendertexture
///
/// \param renderImage : Renderimage
/// \param renderTexture : Rendertexture
///
/// \return Current active view
///
////////////////////////////////////////////////////////////
CSFML_API const sfView* sfRenderImage_GetView(const sfRenderImage* renderImage);
CSFML_API const sfView* sfRenderTexture_GetView(const sfRenderTexture* renderTexture);
////////////////////////////////////////////////////////////
/// Get the default view of a renderimage
/// Get the default view of a rendertexture
///
/// \param renderImage : Renderimage
/// \param renderTexture : Rendertexture
///
/// \return Default view of the renderimage
/// \return Default view of the rendertexture
///
////////////////////////////////////////////////////////////
CSFML_API const sfView* sfRenderImage_GetDefaultView(const sfRenderImage* renderImage);
CSFML_API const sfView* sfRenderTexture_GetDefaultView(const sfRenderTexture* renderTexture);
////////////////////////////////////////////////////////////
/// Get the viewport of a view applied to this target
///
/// \param renderImage : Renderimage object
/// \param renderTexture : Rendertexture object
/// \param view : Target view
///
/// \return Viewport rectangle, expressed in pixels in the current target
///
////////////////////////////////////////////////////////////
CSFML_API sfIntRect sfRenderImage_GetViewport(const sfRenderImage* renderImage, const sfView* view);
CSFML_API sfIntRect sfRenderTexture_GetViewport(const sfRenderTexture* renderTexture, const sfView* view);
////////////////////////////////////////////////////////////
/// Convert a point in image coordinates into view coordinates
/// Convert a point in texture coordinates into view coordinates
///
/// \param renderImage : Renderimage object
/// \param windowX : X coordinate of the point to convert, relative to the image
/// \param windowY : Y coordinate of the point to convert, relative to the image
/// \param renderTexture : Rendertexture object
/// \param windowX : X coordinate of the point to convert, relative to the texture
/// \param windowY : Y coordinate of the point to convert, relative to the texture
/// \param viewX : Pointer to fill with the X coordinate of the converted point
/// \param viewY : Pointer to fill with the Y coordinate of the converted point
/// \param targetView : Target view to convert the point to (pass NULL to use the current view)
///
////////////////////////////////////////////////////////////
CSFML_API void sfRenderImage_ConvertCoords(const sfRenderImage* renderImage, unsigned int windowX, unsigned int windowY, float* viewX, float* viewY, const sfView* targetView);
CSFML_API void sfRenderTexture_ConvertCoords(const sfRenderTexture* renderTexture, unsigned int windowX, unsigned int windowY, float* viewX, float* viewY, const sfView* targetView);
////////////////////////////////////////////////////////////
/// Get the target image
/// Get the target texture
///
/// \param renderImage : Renderimage object
/// \param renderTexture : Render-texture object
///
/// \return Pointer to the target image
/// \return Pointer to the target texture
///
////////////////////////////////////////////////////////////
CSFML_API const sfImage* sfRenderImage_GetImage(const sfRenderImage* renderImage);
CSFML_API const sfTexture* sfRenderTexture_GetTexture(const sfRenderTexture* renderTexture);
#endif // SFML_RENDERIMAGE_H
#endif // SFML_RENDERTEXTURE_H
+18
View File
@@ -371,5 +371,23 @@ CSFML_API sfIntRect sfRenderWindow_GetViewport(const sfRenderWindow* renderWindo
////////////////////////////////////////////////////////////
CSFML_API void sfRenderWindow_ConvertCoords(const sfRenderWindow* renderWindow, unsigned int windowX, unsigned int windowY, float* viewX, float* viewY, const sfView* targetView);
////////////////////////////////////////////////////////////
/// Copy the current contents of a window to an image
///
/// This is a slow operation, whose main purpose is to make
/// screenshots of the application. If you want to update an
/// image with the contents of the window and then use it for
/// drawing, you should rather use a sfTexture and its
/// Update(sfWindow*) function.
/// You can also draw things directly to a texture with the
/// sfRenderTexture class.
///
/// \param renderWindow : Render window to capture
///
/// \return New image containing the captured contents
///
////////////////////////////////////////////////////////////
sfImage* sfRenderWindow_Capture(const sfRenderWindow* renderWindow);
#endif // SFML_RENDERWINDOW_H
+2 -2
View File
@@ -126,10 +126,10 @@ CSFML_API void sfShader_SetParameter4(sfShader* shader, const char* name, float
///
/// \param shader : Shader to modify
/// \param name : Texture name in the effect
/// \param texture : Image to set
/// \param texture : Texture to set
///
////////////////////////////////////////////////////////////
CSFML_API void sfShader_SetTexture(sfShader* shader, const char* name, const sfImage* texture);
CSFML_API void sfShader_SetTexture(sfShader* shader, const char* name, const sfTexture* texture);
////////////////////////////////////////////////////////////
/// Set the current texture parameter in a shader
+7 -19
View File
@@ -301,14 +301,14 @@ CSFML_API void sfSprite_TransformToLocal(const sfSprite* sprite, float pointX, f
CSFML_API void sfSprite_TransformToGlobal(const sfSprite* sprite, float pointX, float pointY, float* x, float* y);
////////////////////////////////////////////////////////////
/// Change the image of a sprite
/// Change the texture of a sprite
///
/// \param sprite : Sprite to modify
/// \param image : New image
/// \param adjustToNewSize : If true, the SubRect of the sprite will be adjusted to the size of the new image
/// \param texture : New texture
/// \param adjustToNewSize : If true, the SubRect of the sprite will be adjusted to the size of the new texture
///
////////////////////////////////////////////////////////////
CSFML_API void sfSprite_SetImage(sfSprite* sprite, const sfImage* image, sfBool adjustToNewSize);
CSFML_API void sfSprite_SetTexture(sfSprite* sprite, const sfTexture* texture, sfBool adjustToNewSize);
////////////////////////////////////////////////////////////
/// Set the sub-rectangle of a sprite inside the source image
@@ -348,14 +348,14 @@ CSFML_API void sfSprite_FlipX(sfSprite* sprite, sfBool flipped);
CSFML_API void sfSprite_FlipY(sfSprite* sprite, sfBool flipped);
////////////////////////////////////////////////////////////
/// Get the source image of a sprite
/// Get the source texture of a sprite
///
/// \param sprite : Sprite to read
///
/// \return Pointer to the image (can be NULL)
/// \return Pointer to the texture (can be NULL)
///
////////////////////////////////////////////////////////////
CSFML_API const sfImage* sfSprite_GetImage(const sfSprite* sprite);
CSFML_API const sfTexture* sfSprite_GetTexture(const sfSprite* sprite);
////////////////////////////////////////////////////////////
/// Get the sub-rectangle of a sprite inside the source image
@@ -387,17 +387,5 @@ CSFML_API float sfSprite_GetWidth(const sfSprite* sprite);
////////////////////////////////////////////////////////////
CSFML_API float sfSprite_GetHeight(const sfSprite* sprite);
////////////////////////////////////////////////////////////
/// Get the color of a given pixel in a sprite
///
/// \param sprite : Sprite to read
/// \param x : X coordinate of the pixel to get
/// \param y : Y coordinate of the pixel to get
///
/// \return Color of pixel (X, Y)
///
////////////////////////////////////////////////////////////
CSFML_API sfColor sfSprite_GetPixel(const sfSprite* sprite, unsigned int x, unsigned int y);
#endif // SFML_SPRITE_H
+236
View File
@@ -0,0 +1,236 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#ifndef SFML_TEXTURE_H
#define SFML_TEXTURE_H
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Config.h>
#include <SFML/Graphics/Rect.h>
#include <SFML/Graphics/Types.h>
#include <SFML/Window/Types.h>
#include <SFML/System/InputStream.h>
#include <stddef.h>
////////////////////////////////////////////////////////////
/// Create a new texture
///
/// \param width : Texture width
/// \param height : Texture height
///
/// \return A new sfTexture object, or NULL if it failed
///
////////////////////////////////////////////////////////////
CSFML_API sfTexture* sfTexture_Create(unsigned int width, unsigned int height);
////////////////////////////////////////////////////////////
/// Create a new texture from a file
///
/// \param filename : Path of the image file to load
/// \param area : Area of the source image to load (NULL to load the entire image)
///
/// \return A new sfTexture object, or NULL if it failed
///
////////////////////////////////////////////////////////////
CSFML_API sfTexture* sfTexture_CreateFromFile(const char* filename, const sfIntRect* area);
////////////////////////////////////////////////////////////
/// Create a new texture from a file in memory
///
/// \param data : Pointer to the file data in memory
/// \param sizeInBytes : Size of the data to load, in bytes
/// \param area : Area of the source image to load (NULL to load the entire image)
///
/// \return A new sfTexture object, or NULL if it failed
///
////////////////////////////////////////////////////////////
CSFML_API sfTexture* sfTexture_CreateFromMemory(const void* data, size_t sizeInBytes, const sfIntRect* area);
////////////////////////////////////////////////////////////
/// Create a new texture from a custom stream
///
/// \param stream : Source stream to read from
/// \param area : Area of the source image to load (NULL to load the entire image)
///
/// \return A new sfTexture object, or NULL if it failed
///
////////////////////////////////////////////////////////////
CSFML_API sfTexture* sfTexture_CreateFromStream(sfInputStream* stream, const sfIntRect* area);
////////////////////////////////////////////////////////////
/// Create a new texture from an image
///
/// \param image : Image to upload to the texture
/// \param area : Area of the source image to load (NULL to load the entire image)
///
/// \return A new sfTexture object, or NULL if it failed
///
////////////////////////////////////////////////////////////
CSFML_API sfTexture* sfTexture_CreateFromImage(const sfImage* image, const sfIntRect* area);
////////////////////////////////////////////////////////////
/// Copy an existing texture
///
/// \param texture : Texture to copy
///
/// \return Copied object
///
////////////////////////////////////////////////////////////
CSFML_API sfTexture* sfTexture_Copy(sfTexture* texture);
////////////////////////////////////////////////////////////
/// Destroy an existing texture
///
/// \param texture : Texture to delete
///
////////////////////////////////////////////////////////////
CSFML_API void sfTexture_Destroy(sfTexture* texture);
////////////////////////////////////////////////////////////
/// Return the width of the texture
///
/// \param texture : Texture to read
///
/// \return Width in pixels
///
////////////////////////////////////////////////////////////
CSFML_API unsigned int sfTexture_GetWidth(const sfTexture* texture);
////////////////////////////////////////////////////////////
/// Return the height of the texture
///
/// \param texture : Texture to read
///
/// \return Height in pixels
///
////////////////////////////////////////////////////////////
CSFML_API unsigned int sfTexture_GetHeight(const sfTexture* texture);
////////////////////////////////////////////////////////////
/// Copy a texture's pixels to an image
///
/// \param texture : Texture to copy
///
/// \return Image containing the texture's pixels
///
////////////////////////////////////////////////////////////
CSFML_API sfImage* sfTexture_CopyToImage(const sfTexture* texture);
////////////////////////////////////////////////////////////
/// Update a texture from an array of pixels
///
/// \param texture : Texture to update
/// \param pixels : Array of pixels to copy to the texture
/// \param width : Width of the pixel region contained in \a pixels
/// \param height : Height of the pixel region contained in \a pixels
/// \param x : X offset in the texture where to copy the source pixels
/// \param y : Y offset in the texture where to copy the source pixels
///
////////////////////////////////////////////////////////////
CSFML_API void sfTexture_UpdateFromPixels(sfTexture* texture, const sfUint8* pixels, unsigned int width, unsigned int height, unsigned int x, unsigned int y);
////////////////////////////////////////////////////////////
/// Update a texture from an image
///
/// \param texture : Texture to update
/// \param image : Image to copy to the texture
/// \param x : X offset in the texture where to copy the source pixels
/// \param y : Y offset in the texture where to copy the source pixels
///
////////////////////////////////////////////////////////////
CSFML_API void sfTexture_UpdateFromImage(sfTexture* texture, const sfImage* image, unsigned int x, unsigned int y);
////////////////////////////////////////////////////////////
/// Update a texture from the contents of a window
///
/// \param texture : Texture to update
/// \param window : Window to copy to the texture
/// \param x : X offset in the texture where to copy the source pixels
/// \param y : Y offset in the texture where to copy the source pixels
///
////////////////////////////////////////////////////////////
CSFML_API void sfTexture_UpdateFromWindow(sfTexture* texture, const sfWindow* window, unsigned int x, unsigned int y);
////////////////////////////////////////////////////////////
/// Update a texture from the contents of a render-window
///
/// \param texture : Texture to update
/// \param renderWindow : Render-window to copy to the texture
/// \param x : X offset in the texture where to copy the source pixels
/// \param y : Y offset in the texture where to copy the source pixels
///
////////////////////////////////////////////////////////////
CSFML_API void sfTexture_UpdateFromRenderWindow(sfTexture* texture, const sfRenderWindow* renderWindow, unsigned int x, unsigned int y);
////////////////////////////////////////////////////////////
/// Activate a texture for rendering
///
/// \param texture : Texture to bind
///
////////////////////////////////////////////////////////////
CSFML_API void sfTexture_Bind(const sfTexture* texture);
////////////////////////////////////////////////////////////
/// Enable or disable the smooth filter on a texture
///
/// \param texture : The texture object
/// \param smooth : sfTrue to enable smoothing, sfFalse to disable it
///
////////////////////////////////////////////////////////////
CSFML_API void sfTexture_SetSmooth(sfTexture* texture, sfBool smooth);
////////////////////////////////////////////////////////////
/// Tell whether the smooth filter is enabled or not for a texture
///
/// \param texture : The texture object
///
/// \return sfTrue if smoothing is enabled, sfFalse if it is disabled
///
////////////////////////////////////////////////////////////
CSFML_API sfBool sfTexture_IsSmooth(const sfTexture* texture);
////////////////////////////////////////////////////////////
/// Convert a rectangle of pixels into texture coordinates
///
/// \param texture : Texture to use for conversion
/// \param rectangle : Rectangle to convert
///
/// \return Texture coordinates corresponding to \a rectangle
///
////////////////////////////////////////////////////////////
CSFML_API sfFloatRect sfTexture_GetTexCoords(const sfTexture* texture, sfIntRect rectangle);
////////////////////////////////////////////////////////////
/// Get the maximum texture size allowed
///
/// \return Maximum size allowed for textures, in pixels
///
////////////////////////////////////////////////////////////
CSFML_API unsigned int sfTexture_GetMaximumSize();
#endif // SFML_TEXTURE_H
+2 -1
View File
@@ -29,11 +29,12 @@
typedef struct sfFont sfFont;
typedef struct sfImage sfImage;
typedef struct sfShader sfShader;
typedef struct sfRenderImage sfRenderImage;
typedef struct sfRenderTexture sfRenderTexture;
typedef struct sfRenderWindow sfRenderWindow;
typedef struct sfShape sfShape;
typedef struct sfSprite sfSprite;
typedef struct sfText sfText;
typedef struct sfTexture sfTexture;
typedef struct sfView sfView;
+5 -5
View File
@@ -145,15 +145,15 @@ int sfFont_GetLineSpacing(sfFont* font, unsigned int characterSize)
////////////////////////////////////////////////////////////
/// Get the image containing the glyphs of a given size in a font
/// Get the texture containing the glyphs of a given size in a font
////////////////////////////////////////////////////////////
const sfImage* sfFont_GetImage(sfFont* font, unsigned int characterSize)
const sfTexture* sfFont_GetTexture(sfFont* font, unsigned int characterSize)
{
CSFML_CHECK_RETURN(font, NULL);
*font->Images[characterSize].This = font->This.GetImage(characterSize);
*font->Textures[characterSize].This = font->This.GetTexture(characterSize);
return &font->Images[characterSize];
return &font->Textures[characterSize];
}
@@ -162,7 +162,7 @@ const sfImage* sfFont_GetImage(sfFont* font, unsigned int characterSize)
////////////////////////////////////////////////////////////
const sfFont* sfFont_GetDefaultFont(void)
{
static sfFont defaultFont = {sf::Font::GetDefaultFont(), std::map<unsigned int, sfImage>()};
static sfFont defaultFont = {sf::Font::GetDefaultFont(), std::map<unsigned int, sfTexture>()};
return &defaultFont;
}
+2 -2
View File
@@ -29,7 +29,7 @@
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics/Font.hpp>
#include <SFML/Graphics/ImageStruct.h>
#include <SFML/Graphics/TextureStruct.h>
#include <SFML/CallbackStream.h>
#include <map>
@@ -40,7 +40,7 @@
struct sfFont
{
sf::Font This;
std::map<unsigned int, sfImage> Images;
std::map<unsigned int, sfTexture> Textures;
CallbackStream Stream;
};
+25 -67
View File
@@ -27,7 +27,6 @@
////////////////////////////////////////////////////////////
#include <SFML/Graphics/Image.h>
#include <SFML/Graphics/ImageStruct.h>
#include <SFML/Graphics/RenderWindowStruct.h>
#include <SFML/Internal.h>
#include <SFML/CallbackStream.h>
@@ -38,12 +37,7 @@
sfImage* sfImage_CreateFromColor(unsigned int width, unsigned int height, sfColor color)
{
sfImage* image = new sfImage;
if (!image->This->Create(width, height, sf::Color(color.r, color.g, color.b, color.a)))
{
delete image;
image = NULL;
}
image->This.Create(width, height, sf::Color(color.r, color.g, color.b, color.a));
return image;
}
@@ -55,12 +49,7 @@ sfImage* sfImage_CreateFromColor(unsigned int width, unsigned int height, sfColo
sfImage* sfImage_CreateFromPixels(unsigned int width, unsigned int height, const sfUint8* data)
{
sfImage* image = new sfImage;
if (!image->This->LoadFromPixels(width, height, data))
{
delete image;
image = NULL;
}
image->This.Create(width, height, data);
return image;
}
@@ -73,7 +62,7 @@ sfImage* sfImage_CreateFromFile(const char* filename)
{
sfImage* image = new sfImage;
if (!image->This->LoadFromFile(filename))
if (!image->This.LoadFromFile(filename))
{
delete image;
image = NULL;
@@ -90,7 +79,7 @@ sfImage* sfImage_CreateFromMemory(const void* data, size_t sizeInBytes)
{
sfImage* image = new sfImage;
if (!image->This->LoadFromMemory(data, sizeInBytes))
if (!image->This.LoadFromMemory(data, sizeInBytes))
{
delete image;
image = NULL;
@@ -110,7 +99,7 @@ sfImage* sfImage_CreateFromStream(sfInputStream* stream)
sfImage* image = new sfImage;
CallbackStream sfmlStream(stream);
if (!image->This->LoadFromStream(sfmlStream))
if (!image->This.LoadFromStream(sfmlStream))
{
delete image;
image = NULL;
@@ -145,7 +134,7 @@ void sfImage_Destroy(sfImage* image)
////////////////////////////////////////////////////////////
sfBool sfImage_SaveToFile(const sfImage* image, const char* filename)
{
CSFML_CALL_PTR_RETURN(image, SaveToFile(filename), sfFalse);
CSFML_CALL_RETURN(image, SaveToFile(filename), sfFalse);
}
@@ -155,7 +144,7 @@ sfBool sfImage_SaveToFile(const sfImage* image, const char* filename)
void sfImage_CreateMaskFromColor(sfImage* image, sfColor colorKey, sfUint8 alpha)
{
sf::Color SFMLColor(colorKey.r, colorKey.g, colorKey.b, colorKey.a);
CSFML_CALL_PTR(image, CreateMaskFromColor(SFMLColor, alpha));
CSFML_CALL(image, CreateMaskFromColor(SFMLColor, alpha));
}
@@ -168,19 +157,7 @@ void sfImage_CopyImage(sfImage* image, const sfImage* source, unsigned int destX
{
CSFML_CHECK(source);
sf::IntRect SFMLRect(sourceRect.Left, sourceRect.Top, sourceRect.Width, sourceRect.Height);
CSFML_CALL_PTR(image, Copy(*source->This, destX, destY, SFMLRect));
}
////////////////////////////////////////////////////////////
/// Create the image from the current contents of the
/// given window
////////////////////////////////////////////////////////////
CSFML_API sfBool sfImage_CopyScreen(sfImage* image, sfRenderWindow* window, sfIntRect sourceRect)
{
CSFML_CHECK_RETURN(window, sfFalse);
sf::IntRect SFMLRect(sourceRect.Left, sourceRect.Top, sourceRect.Width, sourceRect.Height);
CSFML_CALL_PTR_RETURN(image, CopyScreen(window->This, SFMLRect), sfFalse);
CSFML_CALL(image, Copy(source->This, destX, destY, SFMLRect));
}
@@ -191,7 +168,7 @@ CSFML_API sfBool sfImage_CopyScreen(sfImage* image, sfRenderWindow* window, sfIn
void sfImage_SetPixel(sfImage* image, unsigned int x, unsigned int y, sfColor color)
{
sf::Color SFMLColor(color.r, color.g, color.b, color.a);
CSFML_CALL_PTR(image, SetPixel(x, y, SFMLColor));
CSFML_CALL(image, SetPixel(x, y, SFMLColor));
}
@@ -203,7 +180,7 @@ sfColor sfImage_GetPixel(const sfImage* image, unsigned int x, unsigned int y)
sfColor color = {0, 0, 0, 0};
CSFML_CHECK_RETURN(image, color);
sf::Color SFMLColor = image->This->GetPixel(x, y);
sf::Color SFMLColor = image->This.GetPixel(x, y);
return sfColor_FromRGBA(SFMLColor.r, SFMLColor.g, SFMLColor.b, SFMLColor.a);
}
@@ -216,35 +193,7 @@ sfColor sfImage_GetPixel(const sfImage* image, unsigned int x, unsigned int y)
////////////////////////////////////////////////////////////
const sfUint8* sfImage_GetPixelsPtr(const sfImage* image)
{
CSFML_CALL_PTR_RETURN(image, GetPixelsPtr(), NULL);
}
////////////////////////////////////////////////////////////
/// Update a sub-rectangle of the image from an array of pixels
////////////////////////////////////////////////////////////
void sfImage_UpdatePixels(const sfImage* image, const sfUint8* pixels, sfIntRect rectangle)
{
sf::IntRect rect(rectangle.Left, rectangle.Top, rectangle.Width, rectangle.Height);
CSFML_CALL_PTR(image, UpdatePixels(pixels, rect));
}
////////////////////////////////////////////////////////////
/// Bind the image for rendering
////////////////////////////////////////////////////////////
void sfImage_Bind(const sfImage* image)
{
CSFML_CALL_PTR(image, Bind());
}
////////////////////////////////////////////////////////////
/// Enable or disable image smooth filter
////////////////////////////////////////////////////////////
void sfImage_SetSmooth(sfImage* image, sfBool smooth)
{
CSFML_CALL_PTR(image, SetSmooth(smooth == sfTrue));
CSFML_CALL_RETURN(image, GetPixelsPtr(), NULL);
}
@@ -253,7 +202,7 @@ void sfImage_SetSmooth(sfImage* image, sfBool smooth)
////////////////////////////////////////////////////////////
unsigned int sfImage_GetWidth(const sfImage* image)
{
CSFML_CALL_PTR_RETURN(image, GetWidth(), 0);
CSFML_CALL_RETURN(image, GetWidth(), 0);
}
@@ -262,14 +211,23 @@ unsigned int sfImage_GetWidth(const sfImage* image)
////////////////////////////////////////////////////////////
unsigned int sfImage_GetHeight(const sfImage* image)
{
CSFML_CALL_PTR_RETURN(image, GetHeight(), 0);
CSFML_CALL_RETURN(image, GetHeight(), 0);
}
////////////////////////////////////////////////////////////
/// Tells whether the smoothing filter is enabled or not on an image
/// Flip an image horizontally (left <-> right)
////////////////////////////////////////////////////////////
sfBool sfImage_IsSmooth(const sfImage* image)
void sfImage_FlipHorizontally(sfImage* image)
{
CSFML_CALL_PTR_RETURN(image, IsSmooth(), sfFalse);
CSFML_CALL(image, FlipHorizontally());
}
////////////////////////////////////////////////////////////
/// Flip an image vertically (top <-> bottom)
////////////////////////////////////////////////////////////
void sfImage_FlipVertically(sfImage* image)
{
CSFML_CALL(image, FlipVertically());
}
+1 -26
View File
@@ -36,32 +36,7 @@
////////////////////////////////////////////////////////////
struct sfImage
{
sfImage()
{
This = new sf::Image;
OwnInstance = true;
}
sfImage(sf::Image* image)
{
This = image;
OwnInstance = false;
}
sfImage(const sfImage& image)
{
This = image.This ? new sf::Image(*image.This) : NULL;
OwnInstance = true;
}
~sfImage()
{
if (OwnInstance)
delete This;
}
sf::Image* This;
bool OwnInstance;
sf::Image This;
};
-248
View File
@@ -1,248 +0,0 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics/RenderImage.h>
#include <SFML/Graphics/RenderImageStruct.h>
#include <SFML/Graphics/ShapeStruct.h>
#include <SFML/Graphics/ShaderStruct.h>
#include <SFML/Graphics/SpriteStruct.h>
#include <SFML/Graphics/TextStruct.h>
#include <SFML/Internal.h>
////////////////////////////////////////////////////////////
/// Construct a new renderimage
////////////////////////////////////////////////////////////
sfRenderImage* sfRenderImage_Create(unsigned int width, unsigned int height, sfBool depthBuffer)
{
sfRenderImage* renderImage = new sfRenderImage;
renderImage->This.Create(width, height, depthBuffer == sfTrue);
renderImage->Target = new sfImage(const_cast<sf::Image*>(&renderImage->This.GetImage()));
renderImage->DefaultView.This = renderImage->This.GetDefaultView();
renderImage->CurrentView.This = renderImage->This.GetView();
return renderImage;
}
////////////////////////////////////////////////////////////
/// Destroy an existing renderimage
////////////////////////////////////////////////////////////
void sfRenderImage_Destroy(sfRenderImage* renderImage)
{
delete renderImage->Target;
delete renderImage;
}
////////////////////////////////////////////////////////////
/// Get the width of the rendering region of a renderimage
////////////////////////////////////////////////////////////
unsigned int sfRenderImage_GetWidth(const sfRenderImage* renderImage)
{
CSFML_CALL_RETURN(renderImage, GetWidth(), 0);
}
////////////////////////////////////////////////////////////
/// Get the height of the rendering region of a renderimage
////////////////////////////////////////////////////////////
unsigned int sfRenderImage_GetHeight(const sfRenderImage* renderImage)
{
CSFML_CALL_RETURN(renderImage, GetHeight(), 0);
}
////////////////////////////////////////////////////////////
/// Set a renderimage as the current target for rendering
////////////////////////////////////////////////////////////
sfBool sfRenderImage_SetActive(sfRenderImage* renderImage, sfBool active)
{
CSFML_CALL_RETURN(renderImage, SetActive(active == sfTrue), sfFalse)
}
////////////////////////////////////////////////////////////
/// Save the current OpenGL render states and matrices
////////////////////////////////////////////////////////////
void sfRenderImage_SaveGLStates(sfRenderImage* renderImage)
{
CSFML_CALL(renderImage, SaveGLStates());
}
////////////////////////////////////////////////////////////
/// Restore the previously saved OpenGL render states and matrices
////////////////////////////////////////////////////////////
void sfRenderImage_RestoreGLStates(sfRenderImage* renderImage)
{
CSFML_CALL(renderImage, RestoreGLStates());
}
////////////////////////////////////////////////////////////
/// Update the contents of the target image
////////////////////////////////////////////////////////////
void sfRenderImage_Display(sfRenderImage* renderImage)
{
CSFML_CALL(renderImage, Display())
}
////////////////////////////////////////////////////////////
/// Draw something on a renderimage
////////////////////////////////////////////////////////////
void sfRenderImage_DrawSprite(sfRenderImage* renderImage, const sfSprite* sprite)
{
CSFML_CHECK(sprite);
CSFML_CALL(renderImage, Draw(sprite->This));
}
void sfRenderImage_DrawShape(sfRenderImage* renderImage, const sfShape* shape)
{
CSFML_CHECK(shape);
CSFML_CALL(renderImage, Draw(shape->This));
}
void sfRenderImage_DrawText(sfRenderImage* renderImage, const sfText* text)
{
CSFML_CHECK(text);
CSFML_CALL(renderImage, Draw(text->This));
}
////////////////////////////////////////////////////////////
/// Draw something on a renderimage with a shader
////////////////////////////////////////////////////////////
void sfRenderImage_DrawSpriteWithShader(sfRenderImage* renderImage, const sfSprite* sprite, const sfShader* shader)
{
CSFML_CHECK(sprite);
CSFML_CHECK(shader);
CSFML_CALL(renderImage, Draw(sprite->This, shader->This));
}
void sfRenderImage_DrawShapeWithShader(sfRenderImage* renderImage, const sfShape* shape, const sfShader* shader)
{
CSFML_CHECK(shape);
CSFML_CHECK(shader);
CSFML_CALL(renderImage, Draw(shape->This, shader->This));
}
void sfRenderImage_DrawTextWithShader(sfRenderImage* renderImage, const sfText* text, const sfShader* shader)
{
CSFML_CHECK(text);
CSFML_CHECK(shader);
CSFML_CALL(renderImage, Draw(text->This, shader->This));
}
////////////////////////////////////////////////////////////
/// Clear the renderimage with the given color
////////////////////////////////////////////////////////////
void sfRenderImage_Clear(sfRenderImage* renderImage, sfColor color)
{
sf::Color SFMLColor(color.r, color.g, color.b, color.a);
CSFML_CALL(renderImage, Clear(SFMLColor));
}
////////////////////////////////////////////////////////////
/// Change the current active view of a renderimage
////////////////////////////////////////////////////////////
void sfRenderImage_SetView(sfRenderImage* renderImage, const sfView* view)
{
CSFML_CHECK(view);
CSFML_CALL(renderImage, SetView(view->This));
renderImage->CurrentView.This = view->This;
}
////////////////////////////////////////////////////////////
/// Get the current active view of a renderimage
////////////////////////////////////////////////////////////
const sfView* sfRenderImage_GetView(const sfRenderImage* renderImage)
{
CSFML_CHECK_RETURN(renderImage, NULL);
return &renderImage->CurrentView;
}
////////////////////////////////////////////////////////////
/// Get the default view of a renderimage
////////////////////////////////////////////////////////////
const sfView* sfRenderImage_GetDefaultView(const sfRenderImage* renderImage)
{
CSFML_CHECK_RETURN(renderImage, NULL);
return &renderImage->DefaultView;
}
////////////////////////////////////////////////////////////
/// Get the viewport of a view applied to this target
////////////////////////////////////////////////////////////
sfIntRect sfRenderImage_GetViewport(const sfRenderImage* renderImage, const sfView* view)
{
sfIntRect rect = {0, 0, 0, 0};
CSFML_CHECK_RETURN(view, rect);
CSFML_CHECK_RETURN(renderImage, rect);
sf::IntRect SFMLrect = renderImage->This.GetViewport(view->This);
rect.Left = SFMLrect.Left;
rect.Top = SFMLrect.Top;
rect.Width = SFMLrect.Width;
rect.Height = SFMLrect.Height;
return rect;
}
////////////////////////////////////////////////////////////
/// Convert a point in image coordinates into view coordinates
////////////////////////////////////////////////////////////
void sfRenderImage_ConvertCoords(const sfRenderImage* renderImage, unsigned int imageX, unsigned int imageY, float* viewX, float* viewY, const sfView* targetView)
{
CSFML_CHECK(renderImage);
sf::Vector2f point;
if (targetView)
point = renderImage->This.ConvertCoords(imageX, imageY, targetView->This);
else
point = renderImage->This.ConvertCoords(imageX, imageY);
if (viewX) *viewX = point.x;
if (viewY) *viewY = point.y;
}
////////////////////////////////////////////////////////////
/// Get the target image
////////////////////////////////////////////////////////////
const sfImage* sfRenderImage_GetImage(const sfRenderImage* renderImage)
{
CSFML_CHECK_RETURN(renderImage, NULL);
return renderImage->Target;
}
+248
View File
@@ -0,0 +1,248 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics/RenderTexture.h>
#include <SFML/Graphics/RenderTextureStruct.h>
#include <SFML/Graphics/ShapeStruct.h>
#include <SFML/Graphics/ShaderStruct.h>
#include <SFML/Graphics/SpriteStruct.h>
#include <SFML/Graphics/TextStruct.h>
#include <SFML/Internal.h>
////////////////////////////////////////////////////////////
/// Construct a new rendertexture
////////////////////////////////////////////////////////////
sfRenderTexture* sfRenderTexture_Create(unsigned int width, unsigned int height, sfBool depthBuffer)
{
sfRenderTexture* renderTexture = new sfRenderTexture;
renderTexture->This.Create(width, height, depthBuffer == sfTrue);
renderTexture->Target = new sfTexture(const_cast<sf::Texture*>(&renderTexture->This.GetTexture()));
renderTexture->DefaultView.This = renderTexture->This.GetDefaultView();
renderTexture->CurrentView.This = renderTexture->This.GetView();
return renderTexture;
}
////////////////////////////////////////////////////////////
/// Destroy an existing rendertexture
////////////////////////////////////////////////////////////
void sfRenderTexture_Destroy(sfRenderTexture* renderTexture)
{
delete renderTexture->Target;
delete renderTexture;
}
////////////////////////////////////////////////////////////
/// Get the width of the rendering region of a rendertexture
////////////////////////////////////////////////////////////
unsigned int sfRenderTexture_GetWidth(const sfRenderTexture* renderTexture)
{
CSFML_CALL_RETURN(renderTexture, GetWidth(), 0);
}
////////////////////////////////////////////////////////////
/// Get the height of the rendering region of a rendertexture
////////////////////////////////////////////////////////////
unsigned int sfRenderTexture_GetHeight(const sfRenderTexture* renderTexture)
{
CSFML_CALL_RETURN(renderTexture, GetHeight(), 0);
}
////////////////////////////////////////////////////////////
/// Set a rendertexture as the current target for rendering
////////////////////////////////////////////////////////////
sfBool sfRenderTexture_SetActive(sfRenderTexture* renderTexture, sfBool active)
{
CSFML_CALL_RETURN(renderTexture, SetActive(active == sfTrue), sfFalse)
}
////////////////////////////////////////////////////////////
/// Save the current OpenGL render states and matrices
////////////////////////////////////////////////////////////
void sfRenderTexture_SaveGLStates(sfRenderTexture* renderTexture)
{
CSFML_CALL(renderTexture, SaveGLStates());
}
////////////////////////////////////////////////////////////
/// Restore the previously saved OpenGL render states and matrices
////////////////////////////////////////////////////////////
void sfRenderTexture_RestoreGLStates(sfRenderTexture* renderTexture)
{
CSFML_CALL(renderTexture, RestoreGLStates());
}
////////////////////////////////////////////////////////////
/// Update the contents of the target texture
////////////////////////////////////////////////////////////
void sfRenderTexture_Display(sfRenderTexture* renderTexture)
{
CSFML_CALL(renderTexture, Display())
}
////////////////////////////////////////////////////////////
/// Draw something on a rendertexture
////////////////////////////////////////////////////////////
void sfRenderTexture_DrawSprite(sfRenderTexture* renderTexture, const sfSprite* sprite)
{
CSFML_CHECK(sprite);
CSFML_CALL(renderTexture, Draw(sprite->This));
}
void sfRenderTexture_DrawShape(sfRenderTexture* renderTexture, const sfShape* shape)
{
CSFML_CHECK(shape);
CSFML_CALL(renderTexture, Draw(shape->This));
}
void sfRenderTexture_DrawText(sfRenderTexture* renderTexture, const sfText* text)
{
CSFML_CHECK(text);
CSFML_CALL(renderTexture, Draw(text->This));
}
////////////////////////////////////////////////////////////
/// Draw something on a rendertexture with a shader
////////////////////////////////////////////////////////////
void sfRenderTexture_DrawSpriteWithShader(sfRenderTexture* renderTexture, const sfSprite* sprite, const sfShader* shader)
{
CSFML_CHECK(sprite);
CSFML_CHECK(shader);
CSFML_CALL(renderTexture, Draw(sprite->This, shader->This));
}
void sfRenderTexture_DrawShapeWithShader(sfRenderTexture* renderTexture, const sfShape* shape, const sfShader* shader)
{
CSFML_CHECK(shape);
CSFML_CHECK(shader);
CSFML_CALL(renderTexture, Draw(shape->This, shader->This));
}
void sfRenderTexture_DrawTextWithShader(sfRenderTexture* renderTexture, const sfText* text, const sfShader* shader)
{
CSFML_CHECK(text);
CSFML_CHECK(shader);
CSFML_CALL(renderTexture, Draw(text->This, shader->This));
}
////////////////////////////////////////////////////////////
/// Clear the rendertexture with the given color
////////////////////////////////////////////////////////////
void sfRenderTexture_Clear(sfRenderTexture* renderTexture, sfColor color)
{
sf::Color SFMLColor(color.r, color.g, color.b, color.a);
CSFML_CALL(renderTexture, Clear(SFMLColor));
}
////////////////////////////////////////////////////////////
/// Change the current active view of a rendertexture
////////////////////////////////////////////////////////////
void sfRenderTexture_SetView(sfRenderTexture* renderTexture, const sfView* view)
{
CSFML_CHECK(view);
CSFML_CALL(renderTexture, SetView(view->This));
renderTexture->CurrentView.This = view->This;
}
////////////////////////////////////////////////////////////
/// Get the current active view of a rendertexture
////////////////////////////////////////////////////////////
const sfView* sfRenderTexture_GetView(const sfRenderTexture* renderTexture)
{
CSFML_CHECK_RETURN(renderTexture, NULL);
return &renderTexture->CurrentView;
}
////////////////////////////////////////////////////////////
/// Get the default view of a rendertexture
////////////////////////////////////////////////////////////
const sfView* sfRenderTexture_GetDefaultView(const sfRenderTexture* renderTexture)
{
CSFML_CHECK_RETURN(renderTexture, NULL);
return &renderTexture->DefaultView;
}
////////////////////////////////////////////////////////////
/// Get the viewport of a view applied to this target
////////////////////////////////////////////////////////////
sfIntRect sfRenderTexture_GetViewport(const sfRenderTexture* renderTexture, const sfView* view)
{
sfIntRect rect = {0, 0, 0, 0};
CSFML_CHECK_RETURN(view, rect);
CSFML_CHECK_RETURN(renderTexture, rect);
sf::IntRect SFMLrect = renderTexture->This.GetViewport(view->This);
rect.Left = SFMLrect.Left;
rect.Top = SFMLrect.Top;
rect.Width = SFMLrect.Width;
rect.Height = SFMLrect.Height;
return rect;
}
////////////////////////////////////////////////////////////
/// Convert a point in texture coordinates into view coordinates
////////////////////////////////////////////////////////////
void sfRenderTexture_ConvertCoords(const sfRenderTexture* renderTexture, unsigned int textureX, unsigned int textureY, float* viewX, float* viewY, const sfView* targetView)
{
CSFML_CHECK(renderTexture);
sf::Vector2f point;
if (targetView)
point = renderTexture->This.ConvertCoords(textureX, textureY, targetView->This);
else
point = renderTexture->This.ConvertCoords(textureX, textureY);
if (viewX) *viewX = point.x;
if (viewY) *viewY = point.y;
}
////////////////////////////////////////////////////////////
/// Get the target texture
////////////////////////////////////////////////////////////
const sfTexture* sfRenderTexture_GetTexture(const sfRenderTexture* renderTexture)
{
CSFML_CHECK_RETURN(renderTexture, NULL);
return renderTexture->Target;
}
@@ -22,27 +22,27 @@
//
////////////////////////////////////////////////////////////
#ifndef SFML_RENDERIMAGESTRUCT_H
#define SFML_RENDERIMAGESTRUCT_H
#ifndef SFML_RENDERTEXTURESTRUCT_H
#define SFML_RENDERTEXTURESTRUCT_H
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics/RenderImage.hpp>
#include <SFML/Graphics/ImageStruct.h>
#include <SFML/Graphics/RenderTexture.hpp>
#include <SFML/Graphics/TextureStruct.h>
#include <SFML/Graphics/ViewStruct.h>
////////////////////////////////////////////////////////////
// Internal structure of sfRenderWindow
// Internal structure of sfRenderTexture
////////////////////////////////////////////////////////////
struct sfRenderImage
struct sfRenderTexture
{
sf::RenderImage This;
const sfImage* Target;
sfView DefaultView;
sfView CurrentView;
sf::RenderTexture This;
const sfTexture* Target;
sfView DefaultView;
sfView CurrentView;
};
#endif // SFML_RENDERIMAGESTRUCT_H
#endif // SFML_RENDERTEXTURESTRUCT_H
+14
View File
@@ -470,3 +470,17 @@ void sfRenderWindow_ConvertCoords(const sfRenderWindow* renderWindow, unsigned i
if (viewX) *viewX = point.x;
if (viewY) *viewY = point.y;
}
////////////////////////////////////////////////////////////
/// Copy the current contents of a window to an image
////////////////////////////////////////////////////////////
sfImage* sfRenderWindow_Capture(const sfRenderWindow* renderWindow)
{
CSFML_CHECK(renderWindow);
sfImage* image = new sfImage;
image->This = renderWindow->This.Capture();
return image;
}
+2 -2
View File
@@ -27,7 +27,7 @@
////////////////////////////////////////////////////////////
#include <SFML/Graphics/Shader.h>
#include <SFML/Graphics/ShaderStruct.h>
#include <SFML/Graphics/ImageStruct.h>
#include <SFML/Graphics/TextureStruct.h>
#include <SFML/Internal.h>
#include <SFML/CallbackStream.h>
@@ -145,7 +145,7 @@ void sfShader_SetParameter4(sfShader* shader, const char* name, float x, float y
////////////////////////////////////////////////////////////
/// Set a texture parameter in a shader
////////////////////////////////////////////////////////////
void sfShader_SetTexture(sfShader* shader, const char* name, const sfImage* texture)
void sfShader_SetTexture(sfShader* shader, const char* name, const sfTexture* texture)
{
CSFML_CHECK(texture);
CSFML_CALL(shader, SetTexture(name, *texture->This))
+18 -29
View File
@@ -37,12 +37,8 @@
////////////////////////////////////////////////////////////
sfSprite* sfSprite_Create(void)
{
sfSprite* sprite = new sfSprite;
sprite->Image = NULL;
sprite->SubRect.Left = sprite->This.GetSubRect().Left;
sprite->SubRect.Top = sprite->This.GetSubRect().Top;
sprite->SubRect.Width = sprite->This.GetSubRect().Width;
sprite->SubRect.Height = sprite->This.GetSubRect().Height;
sfSprite* sprite = new sfSprite;
sprite->Texture = NULL;
return sprite;
}
@@ -302,14 +298,14 @@ void sfSprite_TransformToGlobal(const sfSprite* sprite, float pointX, float poin
////////////////////////////////////////////////////////////
/// Change the image of a sprite
/// Change the texture of a sprite
////////////////////////////////////////////////////////////
void sfSprite_SetImage(sfSprite* sprite, const sfImage* image, sfBool adjustToNewSize)
void sfSprite_SetTexture(sfSprite* sprite, const sfTexture* texture, sfBool adjustToNewSize)
{
if (image)
if (texture && texture->This)
{
CSFML_CALL(sprite, SetImage(*image->This, adjustToNewSize == sfTrue))
sprite->Image = image;
CSFML_CALL(sprite, SetTexture(*texture->This, adjustToNewSize == sfTrue))
sprite->Texture = texture;
}
}
@@ -320,7 +316,6 @@ void sfSprite_SetImage(sfSprite* sprite, const sfImage* image, sfBool adjustToNe
void sfSprite_SetSubRect(sfSprite* sprite, sfIntRect rectangle)
{
CSFML_CALL(sprite, SetSubRect(sf::IntRect(rectangle.Left, rectangle.Top, rectangle.Width, rectangle.Height)))
sprite->SubRect = rectangle;
}
@@ -352,13 +347,13 @@ void sfSprite_FlipY(sfSprite* sprite, sfBool flipped)
////////////////////////////////////////////////////////////
/// Get the source image of a sprite
/// Get the source texture of a sprite
////////////////////////////////////////////////////////////
const sfImage* sfSprite_GetImage(const sfSprite* sprite)
const sfTexture* sfSprite_GetTexture(const sfSprite* sprite)
{
CSFML_CHECK_RETURN(sprite, NULL)
return sprite->Image;
return sprite->Texture;
}
@@ -370,7 +365,14 @@ sfIntRect sfSprite_GetSubRect(const sfSprite* sprite)
sfIntRect rect = {0, 0, 0, 0};
CSFML_CHECK_RETURN(sprite, rect)
return sprite->SubRect;
sf::IntRect sfmlRect = sprite->This.GetSubRect();
rect.Left = sfmlRect.Left;
rect.Top = sfmlRect.Top;
rect.Width = sfmlRect.Width;
rect.Height = sfmlRect.Height;
return rect;
}
@@ -390,16 +392,3 @@ float sfSprite_GetHeight(const sfSprite* sprite)
{
CSFML_CALL_RETURN(sprite, GetSize().y, 0.f)
}
////////////////////////////////////////////////////////////
/// Get the color of a given pixel in a sprite
////////////////////////////////////////////////////////////
sfColor sfSprite_GetPixel(const sfSprite* sprite, unsigned int x, unsigned int y)
{
sfColor color = {0, 0, 0, 0};
CSFML_CHECK_RETURN(sprite, color)
sf::Color SFMLColor = sprite->This.GetPixel(x, y);
return sfColor_FromRGBA(SFMLColor.r, SFMLColor.g, SFMLColor.b, SFMLColor.a);
}
+3 -5
View File
@@ -29,8 +29,7 @@
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics/Sprite.hpp>
#include <SFML/Graphics/ImageStruct.h>
#include <SFML/Graphics/Rect.h>
#include <SFML/Graphics/TextureStruct.h>
////////////////////////////////////////////////////////////
@@ -38,9 +37,8 @@
////////////////////////////////////////////////////////////
struct sfSprite
{
sf::Sprite This;
const sfImage* Image;
sfIntRect SubRect;
sf::Sprite This;
const sfTexture* Texture;
};
+295
View File
@@ -0,0 +1,295 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics/Texture.h>
#include <SFML/Graphics/TextureStruct.h>
#include <SFML/Graphics/ImageStruct.h>
#include <SFML/Graphics/RenderWindowStruct.h>
#include <SFML/Window/WindowStruct.h>
#include <SFML/Internal.h>
#include <SFML/CallbackStream.h>
////////////////////////////////////////////////////////////
/// Create a new texture
////////////////////////////////////////////////////////////
sfTexture* sfTexture_Create(unsigned int width, unsigned int height)
{
sfTexture* texture = new sfTexture;
if (!texture->This->Create(width, height))
{
delete texture;
texture = NULL;
}
return texture;
}
////////////////////////////////////////////////////////////
/// Create a new texture from a file
////////////////////////////////////////////////////////////
sfTexture* sfTexture_CreateFromFile(const char* filename, const sfIntRect* area)
{
sfTexture* texture = new sfTexture;
sf::IntRect rect;
if (area)
rect = sf::IntRect(area->Left, area->Top, area->Width, area->Height);
if (!texture->This->LoadFromFile(filename))
{
delete texture;
texture = NULL;
}
return texture;
}
////////////////////////////////////////////////////////////
/// Create a new texture from a file in memory
////////////////////////////////////////////////////////////
sfTexture* sfTexture_CreateFromMemory(const void* data, size_t sizeInBytes, const sfIntRect* area)
{
sfTexture* texture = new sfTexture;
sf::IntRect rect;
if (area)
rect = sf::IntRect(area->Left, area->Top, area->Width, area->Height);
if (!texture->This->LoadFromMemory(data, sizeInBytes))
{
delete texture;
texture = NULL;
}
return texture;
}
////////////////////////////////////////////////////////////
/// Create a new texture from a custom stream
////////////////////////////////////////////////////////////
sfTexture* sfTexture_CreateFromStream(sfInputStream* stream, const sfIntRect* area)
{
CSFML_CHECK_RETURN(stream, NULL);
sfTexture* texture = new sfTexture;
sf::IntRect rect;
if (area)
rect = sf::IntRect(area->Left, area->Top, area->Width, area->Height);
CallbackStream sfmlStream(stream);
if (!texture->This->LoadFromStream(sfmlStream))
{
delete texture;
texture = NULL;
}
return texture;
}
////////////////////////////////////////////////////////////
/// Create a new texture from an image
////////////////////////////////////////////////////////////
sfTexture* sfTexture_CreateFromImage(const sfImage* image, const sfIntRect* area)
{
CSFML_CHECK_RETURN(image, NULL);
sfTexture* texture = new sfTexture;
sf::IntRect rect;
if (area)
rect = sf::IntRect(area->Left, area->Top, area->Width, area->Height);
if (!texture->This->LoadFromImage(image->This, rect))
{
delete texture;
texture = NULL;
}
return texture;
}
////////////////////////////////////////////////////////////
/// Copy an existing texture
////////////////////////////////////////////////////////////
sfTexture* sfTexture_Copy(sfTexture* texture)
{
CSFML_CHECK_RETURN(texture, NULL);
return new sfTexture(*texture);
}
////////////////////////////////////////////////////////////
/// Destroy an existing texture
////////////////////////////////////////////////////////////
void sfTexture_Destroy(sfTexture* texture)
{
delete texture;
}
////////////////////////////////////////////////////////////
/// Return the width of the texture
////////////////////////////////////////////////////////////
unsigned int sfTexture_GetWidth(const sfTexture* texture)
{
CSFML_CALL_PTR_RETURN(texture, GetWidth(), 0);
}
////////////////////////////////////////////////////////////
/// Return the height of the texture
////////////////////////////////////////////////////////////
unsigned int sfTexture_GetHeight(const sfTexture* texture)
{
CSFML_CALL_PTR_RETURN(texture, GetHeight(), 0);
}
////////////////////////////////////////////////////////////
/// Copy a texture's pixels to an image
////////////////////////////////////////////////////////////
sfImage* sfTexture_CopyToImage(const sfTexture* texture)
{
CSFML_CHECK_RETURN(texture, NULL);
CSFML_CHECK_RETURN(texture->This, NULL);
sfImage* image = new sfImage;
image->This = texture->This->CopyToImage();
return image;
}
////////////////////////////////////////////////////////////
/// Update a texture from an array of pixels
////////////////////////////////////////////////////////////
void sfTexture_UpdateFromPixels(sfTexture* texture, const sfUint8* pixels, unsigned int width, unsigned int height, unsigned int x, unsigned int y)
{
CSFML_CALL_PTR(texture, Update(pixels, width, height, x, y));
}
////////////////////////////////////////////////////////////
/// Update a texture from an image
////////////////////////////////////////////////////////////
void sfTexture_UpdateFromImage(sfTexture* texture, const sfImage* image, unsigned int x, unsigned int y)
{
CSFML_CHECK(image);
CSFML_CALL_PTR(texture, Update(image->This, x, y));
}
////////////////////////////////////////////////////////////
/// Update a texture from the contents of a window
////////////////////////////////////////////////////////////
void sfTexture_UpdateFromWindow(sfTexture* texture, const sfWindow* window, unsigned int x, unsigned int y)
{
CSFML_CHECK(window);
CSFML_CALL_PTR(texture, Update(window->This, x, y));
}
////////////////////////////////////////////////////////////
/// Update a texture from the contents of a render-window
////////////////////////////////////////////////////////////
void sfTexture_UpdateFromRenderWindow(sfTexture* texture, const sfRenderWindow* renderWindow, unsigned int x, unsigned int y)
{
CSFML_CHECK(renderWindow);
CSFML_CALL_PTR(texture, Update(renderWindow->This, x, y));
}
////////////////////////////////////////////////////////////
/// Activate a texture for rendering
////////////////////////////////////////////////////////////
void sfTexture_Bind(const sfTexture* texture)
{
CSFML_CALL_PTR(texture, Bind());
}
////////////////////////////////////////////////////////////
/// Enable or disable the smooth filter on a texture
////////////////////////////////////////////////////////////
void sfTexture_SetSmooth(sfTexture* texture, sfBool smooth)
{
CSFML_CALL_PTR(texture, SetSmooth(smooth == sfTrue));
}
////////////////////////////////////////////////////////////
/// Tell whether the smooth filter is enabled or not for a texture
////////////////////////////////////////////////////////////
sfBool sfTexture_IsSmooth(const sfTexture* texture)
{
CSFML_CHECK_RETURN(texture, sfFalse);
CSFML_CHECK_RETURN(texture->This, sfFalse);
return texture->This->IsSmooth();
}
////////////////////////////////////////////////////////////
/// Convert a rectangle of pixels into texture coordinates
////////////////////////////////////////////////////////////
sfFloatRect sfTexture_GetTexCoords(const sfTexture* texture, sfIntRect rectangle)
{
sfFloatRect result = {0, 0, 0, 0};
CSFML_CHECK_RETURN(texture, result);
CSFML_CHECK_RETURN(texture->This, result);
sf::IntRect rect(rectangle.Left, rectangle.Top, rectangle.Width, rectangle.Height);
sf::FloatRect sfmlResult = texture->This->GetTexCoords(rect);
result.Left = sfmlResult.Left;
result.Top = sfmlResult.Top;
result.Width = sfmlResult.Width;
result.Height = sfmlResult.Height;
return result;
}
////////////////////////////////////////////////////////////
/// Get the maximum texture size allowed
////////////////////////////////////////////////////////////
unsigned int sfTexture_GetMaximumSize()
{
return sf::Texture::GetMaximumSize();
}
+68
View File
@@ -0,0 +1,68 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#ifndef SFML_TEXTURESTRUCT_H
#define SFML_TEXTURESTRUCT_H
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics/Texture.hpp>
////////////////////////////////////////////////////////////
// Internal structure of sfTexture
////////////////////////////////////////////////////////////
struct sfTexture
{
sfTexture()
{
This = new sf::Texture;
OwnInstance = true;
}
sfTexture(sf::Texture* texture)
{
This = texture;
OwnInstance = false;
}
sfTexture(const sfTexture& texture)
{
This = texture.This ? new sf::Texture(*texture.This) : NULL;
OwnInstance = true;
}
~sfTexture()
{
if (OwnInstance)
delete This;
}
sf::Texture* This;
bool OwnInstance;
};
#endif // SFML_TEXTURESTRUCT_H