Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions include/CSFML/Graphics/RenderTexture.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include <CSFML/Graphics/PrimitiveType.h>
#include <CSFML/Graphics/Rect.h>
#include <CSFML/Graphics/RenderStates.h>
#include <CSFML/Graphics/StencilMode.h>
#include <CSFML/Graphics/Types.h>
#include <CSFML/Graphics/Vertex.h>
#include <CSFML/System/Vector2.h>
Expand Down Expand Up @@ -108,6 +109,33 @@ CSFML_GRAPHICS_API void sfRenderTexture_display(sfRenderTexture* renderTexture);
////////////////////////////////////////////////////////////
CSFML_GRAPHICS_API void sfRenderTexture_clear(sfRenderTexture* renderTexture, sfColor color);

////////////////////////////////////////////////////////////
/// \brief Clear the stencil buffer to a specific value
///
/// The specified value is truncated to the bit width of
/// the current stencil buffer.
///
/// \param renderTexture Render texture object
/// \param stencilValue Stencil value to clear to
///
////////////////////////////////////////////////////////////
CSFML_GRAPHICS_API void sfRenderTexture_clearStencil(sfRenderTexture* renderTexture, sfStencilValue stencilValue);

////////////////////////////////////////////////////////////
/// \brief Clear the entire target with a single color and stencil value
///
/// The specified stencil value is truncated to the bit
/// width of the current stencil buffer.
///
/// \param renderTexture Render texture object
/// \param color Fill color to use to clear the render target
/// \param stencilValue Stencil value to clear to
///
////////////////////////////////////////////////////////////
CSFML_GRAPHICS_API void sfRenderTexture_clearColorAndStencil(sfRenderTexture* renderTexture,
sfColor color,
sfStencilValue stencilValue);

////////////////////////////////////////////////////////////
/// \brief Change the current active view of a render texture
///
Expand Down Expand Up @@ -148,6 +176,22 @@ CSFML_GRAPHICS_API const sfView* sfRenderTexture_getDefaultView(const sfRenderTe
////////////////////////////////////////////////////////////
CSFML_GRAPHICS_API sfIntRect sfRenderTexture_getViewport(const sfRenderTexture* renderTexture, const sfView* view);

////////////////////////////////////////////////////////////
/// \brief Get the scissor rectangle of a view, applied to this render target
///
/// The scissor rectangle is defined in the view as a ratio. This
/// function simply applies this ratio to the current dimensions
/// of the render target to calculate the pixels rectangle
/// that the scissor rectangle actually covers in the target.
///
/// \param renderTexture Render texture object
/// \param view The view for which we want to compute the scissor rectangle
///
/// \return Scissor rectangle, expressed in pixels
///
////////////////////////////////////////////////////////////
CSFML_GRAPHICS_API sfIntRect sfRenderTexture_getScissor(const sfRenderTexture* renderTexture, const sfView* view);

////////////////////////////////////////////////////////////
/// \brief Convert a point from texture coordinates to world coordinates
///
Expand Down
74 changes: 69 additions & 5 deletions include/CSFML/Graphics/RenderWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@
#include <CSFML/Graphics/PrimitiveType.h>
#include <CSFML/Graphics/Rect.h>
#include <CSFML/Graphics/RenderStates.h>
#include <CSFML/Graphics/StencilMode.h>
#include <CSFML/Graphics/Types.h>
#include <CSFML/Graphics/Vertex.h>
#include <CSFML/System/Time.h>
#include <CSFML/System/Vector2.h>
#include <CSFML/Window/Event.h>
#include <CSFML/Window/VideoMode.h>
Expand Down Expand Up @@ -122,26 +124,47 @@ CSFML_GRAPHICS_API bool sfRenderWindow_isOpen(const sfRenderWindow* renderWindow
CSFML_GRAPHICS_API sfContextSettings sfRenderWindow_getSettings(const sfRenderWindow* renderWindow);

////////////////////////////////////////////////////////////
/// \brief Get the event on top of event queue of a render window, if any, and pop it
/// \brief Pop the event on top of event queue, if any, and return it
///
/// This function is not blocking: if there's no pending event then
/// it will return false and leave \a event unmodified.
/// Note that more than one event may be present in the event queue,
/// thus you should always call this function in a loop
/// to make sure that you process every pending event.
///
/// \param renderWindow Render window object
/// \param event Event to fill, if any
///
/// \return true if an event was returned, false if event queue was empty
/// \return true if an event was returned, or false if the event queue was empty
///
////////////////////////////////////////////////////////////
CSFML_GRAPHICS_API bool sfRenderWindow_pollEvent(sfRenderWindow* renderWindow, sfEvent* event);

////////////////////////////////////////////////////////////
/// \brief Wait for an event and return it
///
/// This function is blocking: if there's no pending event then
/// it will wait until an event is received or until the provided
/// timeout elapses. Only if an error or a timeout occurs the
/// function returns `false`.
/// This function is typically used when you have a thread that is
/// dedicated to events handling: you want to make this thread sleep
/// as long as no new event is received.
/// \code
/// while (sfRenderWindow_waitEvent(renderWindow, timeout, &event))
/// {
/// // process event...
/// }
/// \endcode
///
/// \param renderWindow Render window object
/// \param event Event to fill
/// \param timeout Maximum time to wait (`sfTime_Zero` for infinite)
/// \param event Event to fill, if any
///
/// \return false if an error occurred
/// \return true if an event was returned, false if event queue was empty or function timed out
///
////////////////////////////////////////////////////////////
CSFML_GRAPHICS_API bool sfRenderWindow_waitEvent(sfRenderWindow* renderWindow, sfEvent* event);
CSFML_GRAPHICS_API bool sfRenderWindow_waitEvent(sfRenderWindow* renderWindow, sfTime timeout, sfEvent* event);

////////////////////////////////////////////////////////////
/// \brief Get the position of a render window
Expand Down Expand Up @@ -377,6 +400,31 @@ CSFML_GRAPHICS_API sfWindowHandle sfRenderWindow_getNativeHandle(const sfRenderW
////////////////////////////////////////////////////////////
CSFML_GRAPHICS_API void sfRenderWindow_clear(sfRenderWindow* renderWindow, sfColor color);

////////////////////////////////////////////////////////////
/// \brief Clear the stencil buffer to a specific value
///
/// The specified value is truncated to the bit width of
/// the current stencil buffer.
///
/// \param renderWindow Render window object
/// \param stencilValue Stencil value to clear to
///
////////////////////////////////////////////////////////////
CSFML_GRAPHICS_API void sfRenderWindow_clearStencil(sfRenderWindow* renderWindow, sfStencilValue stencilValue);

////////////////////////////////////////////////////////////
/// \brief Clear the entire target with a single color and stencil value
///
/// The specified stencil value is truncated to the bit
/// width of the current stencil buffer.
///
/// \param renderWindow Render window object
/// \param color Fill color to use to clear the render target
/// \param stencilValue Stencil value to clear to
///
////////////////////////////////////////////////////////////
CSFML_GRAPHICS_API void sfRenderWindow_clearColorAndStencil(sfRenderWindow* renderWindow, sfColor color, sfStencilValue stencilValue);

////////////////////////////////////////////////////////////
/// \brief Change the current active view of a render window
///
Expand Down Expand Up @@ -417,6 +465,22 @@ CSFML_GRAPHICS_API const sfView* sfRenderWindow_getDefaultView(const sfRenderWin
////////////////////////////////////////////////////////////
CSFML_GRAPHICS_API sfIntRect sfRenderWindow_getViewport(const sfRenderWindow* renderWindow, const sfView* view);

////////////////////////////////////////////////////////////
/// \brief Get the scissor rectangle of a view, applied to this render target
///
/// The scissor rectangle is defined in the view as a ratio. This
/// function simply applies this ratio to the current dimensions
/// of the render target to calculate the pixels rectangle
/// that the scissor rectangle actually covers in the target.
///
/// \param renderWindow Render window object
/// \param view The view for which we want to compute the scissor rectangle
///
/// \return Scissor rectangle, expressed in pixels
///
////////////////////////////////////////////////////////////
CSFML_GRAPHICS_API sfIntRect sfRenderWindow_getScissor(const sfRenderWindow* renderWindow, const sfView* view);

////////////////////////////////////////////////////////////
/// \brief Convert a point from window coordinates to world coordinates
///
Expand Down
96 changes: 96 additions & 0 deletions include/CSFML/Graphics/StencilMode.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2024 Laurent Gomila (laurent@sfml-dev.org)
//
// 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.
//
////////////////////////////////////////////////////////////

#pragma once

////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <CSFML/Graphics/Export.h>


////////////////////////////////////////////////////////
/// \brief Enumeration of the stencil test comparisons that can be performed
///
/// The comparisons are mapped directly to their OpenGL equivalents,
/// specified by `glStencilFunc()`.
////////////////////////////////////////////////////////
typedef enum
{
sfStencilComparisonNever, //!< The stencil test never passes
sfStencilComparisonLess, //!< The stencil test passes if the new value is less than the value in the stencil buffer
sfStencilComparisonLessEqual, //!< The stencil test passes if the new value is less than or equal to the value in the stencil buffer
sfStencilComparisonGreater, //!< The stencil test passes if the new value is greater than the value in the stencil buffer
sfStencilComparisonGreaterEqual, //!< The stencil test passes if the new value is greater than or equal to the value in the stencil buffer
sfStencilComparisonEqual, //!< The stencil test passes if the new value is strictly equal to the value in the stencil buffer
sfStencilComparisonNotEqual, //!< The stencil test passes if the new value is strictly unequal to the value in the stencil buffer
sfStencilComparisonAlways //!< The stencil test always passes
} sfStencilComparison;


////////////////////////////////////////////////////////
/// \brief Enumeration of the stencil buffer update operations
///
/// The update operations are mapped directly to their OpenGL equivalents,
/// specified by `glStencilOp()`.
////////////////////////////////////////////////////////
typedef enum
{
sfStencilUpdateOperationKeep, //!< If the stencil test passes, the value in the stencil buffer is not modified
sfStencilUpdateOperationZero, //!< If the stencil test passes, the value in the stencil buffer is set to zero
sfStencilUpdateOperationReplace, //!< If the stencil test passes, the value in the stencil buffer is set to the new value
sfStencilUpdateOperationIncrement, //!< If the stencil test passes, the value in the stencil buffer is incremented and if required clamped
sfStencilUpdateOperationDecrement, //!< If the stencil test passes, the value in the stencil buffer is decremented and if required clamped
sfStencilUpdateOperationInvert, //!< If the stencil test passes, the value in the stencil buffer is bitwise inverted
} sfStencilUpdateOperation;


////////////////////////////////////////////////////////
/// \brief Stencil value type (also used as a mask)
///
////////////////////////////////////////////////////////
typedef struct
{
unsigned int value; //!< The stored stencil value
} sfStencilValue;


////////////////////////////////////////////////////////////
/// \brief Stencil modes for drawing
///
////////////////////////////////////////////////////////////
typedef struct
{
sfStencilComparison stencilComparison; //!< The comparison we're performing the stencil test with
sfStencilUpdateOperation stencilUpdateOperation; //!< The update operation to perform if the stencil test passes
sfStencilValue stencilReference; //!< The reference value we're performing the stencil test with
sfStencilValue stencilMask; //!< The mask to apply to both the reference value and the value in the stencil buffer
bool stencilOnly; //!< Whether we should update the color buffer in addition to the stencil buffer
} sfStencilMode;

////////////////////////////////////////////////////////////
/// \brief Define the default values for a StencilMode
///
////////////////////////////////////////////////////////////
CSFML_GRAPHICS_API const sfStencilMode sfStencilMode_default;
10 changes: 10 additions & 0 deletions include/CSFML/Graphics/Texture.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,16 @@ typedef enum
////////////////////////////////////////////////////////////
CSFML_GRAPHICS_API sfTexture* sfTexture_create(sfVector2u size);

////////////////////////////////////////////////////////////
/// \brief Create a new sRGB-enabled texture
///
/// \param size Texture size
///
/// \return A new sfTexture object, or NULL if it failed
///
////////////////////////////////////////////////////////////
CSFML_GRAPHICS_API sfTexture* sfTexture_createSrgb(sfVector2u size);

////////////////////////////////////////////////////////////
/// \brief Create a new texture from a file
///
Expand Down
33 changes: 33 additions & 0 deletions include/CSFML/Graphics/View.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,29 @@ CSFML_GRAPHICS_API void sfView_setRotation(sfView* view, float angle);
////////////////////////////////////////////////////////////
CSFML_GRAPHICS_API void sfView_setViewport(sfView* view, sfFloatRect viewport);

////////////////////////////////////////////////////////////
/// \brief Set the target scissor rectangle
///
/// The scissor rectangle, expressed as a factor (between 0 and 1) of
/// the RenderTarget, specifies the region of the RenderTarget whose
/// pixels are able to be modified by draw or clear operations.
/// Any pixels which lie outside of the scissor rectangle will
/// not be modified by draw or clear operations.
/// For example, a scissor rectangle which only allows modifications
/// to the right side of the target would be defined
/// with `sfView_setScissor(view, (sfFloatRect){{0.5f, 0.f}, {0.5f, 1.f}})`.
/// By default, a view has a scissor rectangle which allows
/// modifications to the entire target. This is equivalent to
/// disabling the scissor test entirely. Passing the default
/// scissor rectangle to this function will also disable
/// scissor testing.
///
/// \param view View object
/// \param scissor New scissor rectangle
///
////////////////////////////////////////////////////////////
CSFML_GRAPHICS_API void sfView_setScissor(sfView* view, sfFloatRect scissor);

////////////////////////////////////////////////////////////
/// \brief Get the center of a view
///
Expand Down Expand Up @@ -157,6 +180,16 @@ CSFML_GRAPHICS_API float sfView_getRotation(const sfView* view);
////////////////////////////////////////////////////////////
CSFML_GRAPHICS_API sfFloatRect sfView_getViewport(const sfView* view);

////////////////////////////////////////////////////////////
/// \brief Get the scissor rectangle of the view
///
/// \param view View object
///
/// \return Scissor rectangle, expressed as a factor of the target size
///
////////////////////////////////////////////////////////////
CSFML_GRAPHICS_API sfFloatRect sfView_getScissor(const sfView* view);

////////////////////////////////////////////////////////////
/// \brief Move a view relatively to its current position
///
Expand Down
Loading