Path: blob/main/system/include/SDL/SDL_render.h
6169 views
/*1Simple DirectMedia Layer2Copyright (C) 1997-2011 Sam Lantinga <[email protected]>34This software is provided 'as-is', without any express or implied5warranty. In no event will the authors be held liable for any damages6arising from the use of this software.78Permission is granted to anyone to use this software for any purpose,9including commercial applications, and to alter it and redistribute it10freely, subject to the following restrictions:11121. The origin of this software must not be misrepresented; you must not13claim that you wrote the original software. If you use this software14in a product, an acknowledgment in the product documentation would be15appreciated but is not required.162. Altered source versions must be plainly marked as such, and must not be17misrepresented as being the original software.183. This notice may not be removed or altered from any source distribution.19*/2021/**22* \file SDL_render.h23*24* Header file for SDL 2D rendering functions.25*26* This API supports the following features:27* * single pixel points28* * single pixel lines29* * filled rectangles30* * texture images31*32* The primitives may be drawn in opaque, blended, or additive modes.33*34* The texture images may be drawn in opaque, blended, or additive modes.35* They can have an additional color tint or alpha modulation applied to36* them, and may also be stretched with linear interpolation.37*38* This API is designed to accelerate simple 2D operations. You may39* want more functionality such as rotation and particle effects and40* in that case you should use SDL's OpenGL/Direct3D support or one41* of the many good 3D engines.42*/4344#ifndef _SDL_render_h45#define _SDL_render_h4647#include "SDL_stdinc.h"48#include "SDL_rect.h"49#include "SDL_video.h"5051#include "begin_code.h"52/* Set up for C function definitions, even when using C++ */53#ifdef __cplusplus54/* *INDENT-OFF* */55extern "C" {56/* *INDENT-ON* */57#endif5859/**60* \brief Flags used when creating a rendering context61*/62typedef enum63{64SDL_RENDERER_SOFTWARE = 0x00000001, /**< The renderer is a software fallback */65SDL_RENDERER_ACCELERATED = 0x00000002, /**< The renderer uses hardware66acceleration */67SDL_RENDERER_PRESENTVSYNC = 0x00000004 /**< Present is synchronized68with the refresh rate */69} SDL_RendererFlags;7071/**72* \brief Information on the capabilities of a render driver or context.73*/74typedef struct SDL_RendererInfo75{76const char *name; /**< The name of the renderer */77Uint32 flags; /**< Supported ::SDL_RendererFlags */78Uint32 num_texture_formats; /**< The number of available texture formats */79Uint32 texture_formats[16]; /**< The available texture formats */80int max_texture_width; /**< The maximimum texture width */81int max_texture_height; /**< The maximimum texture height */82} SDL_RendererInfo;8384/**85* \brief The access pattern allowed for a texture.86*/87typedef enum88{89SDL_TEXTUREACCESS_STATIC, /**< Changes rarely, not lockable */90SDL_TEXTUREACCESS_STREAMING /**< Changes frequently, lockable */91} SDL_TextureAccess;9293/**94* \brief The texture channel modulation used in SDL_RenderCopy().95*/96typedef enum97{98SDL_TEXTUREMODULATE_NONE = 0x00000000, /**< No modulation */99SDL_TEXTUREMODULATE_COLOR = 0x00000001, /**< srcC = srcC * color */100SDL_TEXTUREMODULATE_ALPHA = 0x00000002 /**< srcA = srcA * alpha */101} SDL_TextureModulate;102103/**104* \brief A structure representing rendering state105*/106struct SDL_Renderer;107typedef struct SDL_Renderer SDL_Renderer;108109/**110* \brief An efficient driver-specific representation of pixel data111*/112struct SDL_Texture;113typedef struct SDL_Texture SDL_Texture;114115116/* Function prototypes */117118/**119* \brief Get the number of 2D rendering drivers available for the current120* display.121*122* A render driver is a set of code that handles rendering and texture123* management on a particular display. Normally there is only one, but124* some drivers may have several available with different capabilities.125*126* \sa SDL_GetRenderDriverInfo()127* \sa SDL_CreateRenderer()128*/129extern DECLSPEC int SDLCALL SDL_GetNumRenderDrivers(void);130131/**132* \brief Get information about a specific 2D rendering driver for the current133* display.134*135* \param index The index of the driver to query information about.136* \param info A pointer to an SDL_RendererInfo struct to be filled with137* information on the rendering driver.138*139* \return 0 on success, -1 if the index was out of range.140*141* \sa SDL_CreateRenderer()142*/143extern DECLSPEC int SDLCALL SDL_GetRenderDriverInfo(int index,144SDL_RendererInfo * info);145146/**147* \brief Create a 2D rendering context for a window.148*149* \param window The window where rendering is displayed.150* \param index The index of the rendering driver to initialize, or -1 to151* initialize the first one supporting the requested flags.152* \param flags ::SDL_RendererFlags.153*154* \return A valid rendering context or NULL if there was an error.155*156* \sa SDL_CreateSoftwareRenderer()157* \sa SDL_GetRendererInfo()158* \sa SDL_DestroyRenderer()159*/160extern DECLSPEC SDL_Renderer * SDLCALL SDL_CreateRenderer(SDL_Window * window,161int index, Uint32 flags);162163/**164* \brief Create a 2D software rendering context for a surface.165*166* \param surface The surface where rendering is done.167*168* \return A valid rendering context or NULL if there was an error.169*170* \sa SDL_CreateRenderer()171* \sa SDL_DestroyRenderer()172*/173extern DECLSPEC SDL_Renderer * SDLCALL SDL_CreateSoftwareRenderer(SDL_Surface * surface);174175/**176* \brief Get the renderer associated with a window.177*/178extern DECLSPEC SDL_Renderer * SDLCALL SDL_GetRenderer(SDL_Window * window);179180/**181* \brief Get information about a rendering context.182*/183extern DECLSPEC int SDLCALL SDL_GetRendererInfo(SDL_Renderer * renderer,184SDL_RendererInfo * info);185186/**187* \brief Create a texture for a rendering context.188*189* \param format The format of the texture.190* \param access One of the enumerated values in ::SDL_TextureAccess.191* \param w The width of the texture in pixels.192* \param h The height of the texture in pixels.193*194* \return The created texture is returned, or 0 if no rendering context was195* active, the format was unsupported, or the width or height were out196* of range.197*198* \sa SDL_QueryTexture()199* \sa SDL_UpdateTexture()200* \sa SDL_DestroyTexture()201*/202extern DECLSPEC SDL_Texture * SDLCALL SDL_CreateTexture(SDL_Renderer * renderer,203Uint32 format,204int access, int w,205int h);206207/**208* \brief Create a texture from an existing surface.209*210* \param surface The surface containing pixel data used to fill the texture.211*212* \return The created texture is returned, or 0 on error.213*214* \note The surface is not modified or freed by this function.215*216* \sa SDL_QueryTexture()217* \sa SDL_DestroyTexture()218*/219extern DECLSPEC SDL_Texture * SDLCALL SDL_CreateTextureFromSurface(SDL_Renderer * renderer, SDL_Surface * surface);220221/**222* \brief Query the attributes of a texture223*224* \param texture A texture to be queried.225* \param format A pointer filled in with the raw format of the texture. The226* actual format may differ, but pixel transfers will use this227* format.228* \param access A pointer filled in with the actual access to the texture.229* \param w A pointer filled in with the width of the texture in pixels.230* \param h A pointer filled in with the height of the texture in pixels.231*232* \return 0 on success, or -1 if the texture is not valid.233*/234extern DECLSPEC int SDLCALL SDL_QueryTexture(SDL_Texture * texture,235Uint32 * format, int *access,236int *w, int *h);237238/**239* \brief Set an additional color value used in render copy operations.240*241* \param texture The texture to update.242* \param r The red color value multiplied into copy operations.243* \param g The green color value multiplied into copy operations.244* \param b The blue color value multiplied into copy operations.245*246* \return 0 on success, or -1 if the texture is not valid or color modulation247* is not supported.248*249* \sa SDL_GetTextureColorMod()250*/251extern DECLSPEC int SDLCALL SDL_SetTextureColorMod(SDL_Texture * texture,252Uint8 r, Uint8 g, Uint8 b);253254255/**256* \brief Get the additional color value used in render copy operations.257*258* \param texture The texture to query.259* \param r A pointer filled in with the current red color value.260* \param g A pointer filled in with the current green color value.261* \param b A pointer filled in with the current blue color value.262*263* \return 0 on success, or -1 if the texture is not valid.264*265* \sa SDL_SetTextureColorMod()266*/267extern DECLSPEC int SDLCALL SDL_GetTextureColorMod(SDL_Texture * texture,268Uint8 * r, Uint8 * g,269Uint8 * b);270271/**272* \brief Set an additional alpha value used in render copy operations.273*274* \param texture The texture to update.275* \param alpha The alpha value multiplied into copy operations.276*277* \return 0 on success, or -1 if the texture is not valid or alpha modulation278* is not supported.279*280* \sa SDL_GetTextureAlphaMod()281*/282extern DECLSPEC int SDLCALL SDL_SetTextureAlphaMod(SDL_Texture * texture,283Uint8 alpha);284285/**286* \brief Get the additional alpha value used in render copy operations.287*288* \param texture The texture to query.289* \param alpha A pointer filled in with the current alpha value.290*291* \return 0 on success, or -1 if the texture is not valid.292*293* \sa SDL_SetTextureAlphaMod()294*/295extern DECLSPEC int SDLCALL SDL_GetTextureAlphaMod(SDL_Texture * texture,296Uint8 * alpha);297298/**299* \brief Set the blend mode used for texture copy operations.300*301* \param texture The texture to update.302* \param blendMode ::SDL_BlendMode to use for texture blending.303*304* \return 0 on success, or -1 if the texture is not valid or the blend mode is305* not supported.306*307* \note If the blend mode is not supported, the closest supported mode is308* chosen.309*310* \sa SDL_GetTextureBlendMode()311*/312extern DECLSPEC int SDLCALL SDL_SetTextureBlendMode(SDL_Texture * texture,313SDL_BlendMode blendMode);314315/**316* \brief Get the blend mode used for texture copy operations.317*318* \param texture The texture to query.319* \param blendMode A pointer filled in with the current blend mode.320*321* \return 0 on success, or -1 if the texture is not valid.322*323* \sa SDL_SetTextureBlendMode()324*/325extern DECLSPEC int SDLCALL SDL_GetTextureBlendMode(SDL_Texture * texture,326SDL_BlendMode *blendMode);327328/**329* \brief Update the given texture rectangle with new pixel data.330*331* \param texture The texture to update332* \param rect A pointer to the rectangle of pixels to update, or NULL to333* update the entire texture.334* \param pixels The raw pixel data.335* \param pitch The number of bytes between rows of pixel data.336*337* \return 0 on success, or -1 if the texture is not valid.338*339* \note This is a fairly slow function.340*/341extern DECLSPEC int SDLCALL SDL_UpdateTexture(SDL_Texture * texture,342const SDL_Rect * rect,343const void *pixels, int pitch);344345/**346* \brief Lock a portion of the texture for pixel access.347*348* \param texture The texture to lock for access, which was created with349* ::SDL_TEXTUREACCESS_STREAMING.350* \param rect A pointer to the rectangle to lock for access. If the rect351* is NULL, the entire texture will be locked.352* \param pixels This is filled in with a pointer to the locked pixels,353* appropriately offset by the locked area.354* \param pitch This is filled in with the pitch of the locked pixels.355*356* \return 0 on success, or -1 if the texture is not valid or was not created with ::SDL_TEXTUREACCESS_STREAMING.357*358* \sa SDL_UnlockTexture()359*/360extern DECLSPEC int SDLCALL SDL_LockTexture(SDL_Texture * texture,361const SDL_Rect * rect,362void **pixels, int *pitch);363364/**365* \brief Unlock a texture, uploading the changes to video memory, if needed.366*367* \sa SDL_LockTexture()368*/369extern DECLSPEC void SDLCALL SDL_UnlockTexture(SDL_Texture * texture);370371/**372* \brief Set the drawing area for rendering on the current target.373*374* \param rect The rectangle representing the drawing area, or NULL to set the viewport to the entire target.375*376* The x,y of the viewport rect represents the origin for rendering.377*378* \note When the window is resized, the current viewport is automatically379* centered within the new window size.380*/381extern DECLSPEC int SDLCALL SDL_RenderSetViewport(SDL_Renderer * renderer,382const SDL_Rect * rect);383384/**385* \brief Get the drawing area for the current target.386*/387extern DECLSPEC void SDLCALL SDL_RenderGetViewport(SDL_Renderer * renderer,388SDL_Rect * rect);389390/**391* \brief Set the color used for drawing operations (Fill and Line).392*393* \param r The red value used to draw on the rendering target.394* \param g The green value used to draw on the rendering target.395* \param b The blue value used to draw on the rendering target.396* \param a The alpha value used to draw on the rendering target, usually397* ::SDL_ALPHA_OPAQUE (255).398*399* \return 0 on success, or -1 on error400*/401extern DECLSPEC int SDL_SetRenderDrawColor(SDL_Renderer * renderer,402Uint8 r, Uint8 g, Uint8 b,403Uint8 a);404405/**406* \brief Get the color used for drawing operations (Fill and Line).407*408* \param r A pointer to the red value used to draw on the rendering target.409* \param g A pointer to the green value used to draw on the rendering target.410* \param b A pointer to the blue value used to draw on the rendering target.411* \param a A pointer to the alpha value used to draw on the rendering target,412* usually ::SDL_ALPHA_OPAQUE (255).413*414* \return 0 on success, or -1 on error415*/416extern DECLSPEC int SDL_GetRenderDrawColor(SDL_Renderer * renderer,417Uint8 * r, Uint8 * g, Uint8 * b,418Uint8 * a);419420/**421* \brief Set the blend mode used for drawing operations (Fill and Line).422*423* \param blendMode ::SDL_BlendMode to use for blending.424*425* \return 0 on success, or -1 on error426*427* \note If the blend mode is not supported, the closest supported mode is428* chosen.429*430* \sa SDL_GetRenderDrawBlendMode()431*/432extern DECLSPEC int SDLCALL SDL_SetRenderDrawBlendMode(SDL_Renderer * renderer,433SDL_BlendMode blendMode);434435/**436* \brief Get the blend mode used for drawing operations.437*438* \param blendMode A pointer filled in with the current blend mode.439*440* \return 0 on success, or -1 on error441*442* \sa SDL_SetRenderDrawBlendMode()443*/444extern DECLSPEC int SDLCALL SDL_GetRenderDrawBlendMode(SDL_Renderer * renderer,445SDL_BlendMode *blendMode);446447/**448* \brief Clear the current rendering target with the drawing color449*450* This function clears the entire rendering target, ignoring the viewport.451*/452extern DECLSPEC int SDLCALL SDL_RenderClear(SDL_Renderer * renderer);453454/**455* \brief Draw a point on the current rendering target.456*457* \param x The x coordinate of the point.458* \param y The y coordinate of the point.459*460* \return 0 on success, or -1 on error461*/462extern DECLSPEC int SDLCALL SDL_RenderDrawPoint(SDL_Renderer * renderer,463int x, int y);464465/**466* \brief Draw multiple points on the current rendering target.467*468* \param points The points to draw469* \param count The number of points to draw470*471* \return 0 on success, or -1 on error472*/473extern DECLSPEC int SDLCALL SDL_RenderDrawPoints(SDL_Renderer * renderer,474const SDL_Point * points,475int count);476477/**478* \brief Draw a line on the current rendering target.479*480* \param x1 The x coordinate of the start point.481* \param y1 The y coordinate of the start point.482* \param x2 The x coordinate of the end point.483* \param y2 The y coordinate of the end point.484*485* \return 0 on success, or -1 on error486*/487extern DECLSPEC int SDLCALL SDL_RenderDrawLine(SDL_Renderer * renderer,488int x1, int y1, int x2, int y2);489490/**491* \brief Draw a series of connected lines on the current rendering target.492*493* \param points The points along the lines494* \param count The number of points, drawing count-1 lines495*496* \return 0 on success, or -1 on error497*/498extern DECLSPEC int SDLCALL SDL_RenderDrawLines(SDL_Renderer * renderer,499const SDL_Point * points,500int count);501502/**503* \brief Draw a rectangle on the current rendering target.504*505* \param rect A pointer to the destination rectangle, or NULL to outline the entire rendering target.506*507* \return 0 on success, or -1 on error508*/509extern DECLSPEC int SDLCALL SDL_RenderDrawRect(SDL_Renderer * renderer,510const SDL_Rect * rect);511512/**513* \brief Draw some number of rectangles on the current rendering target.514*515* \param rects A pointer to an array of destination rectangles.516* \param count The number of rectangles.517*518* \return 0 on success, or -1 on error519*/520extern DECLSPEC int SDLCALL SDL_RenderDrawRects(SDL_Renderer * renderer,521const SDL_Rect * rects,522int count);523524/**525* \brief Fill a rectangle on the current rendering target with the drawing color.526*527* \param rect A pointer to the destination rectangle, or NULL for the entire528* rendering target.529*530* \return 0 on success, or -1 on error531*/532extern DECLSPEC int SDLCALL SDL_RenderFillRect(SDL_Renderer * renderer,533const SDL_Rect * rect);534535/**536* \brief Fill some number of rectangles on the current rendering target with the drawing color.537*538* \param rects A pointer to an array of destination rectangles.539* \param count The number of rectangles.540*541* \return 0 on success, or -1 on error542*/543extern DECLSPEC int SDLCALL SDL_RenderFillRects(SDL_Renderer * renderer,544const SDL_Rect * rects,545int count);546547/**548* \brief Copy a portion of the texture to the current rendering target.549*550* \param texture The source texture.551* \param srcrect A pointer to the source rectangle, or NULL for the entire552* texture.553* \param dstrect A pointer to the destination rectangle, or NULL for the554* entire rendering target.555*556* \return 0 on success, or -1 on error557*/558extern DECLSPEC int SDLCALL SDL_RenderCopy(SDL_Renderer * renderer,559SDL_Texture * texture,560const SDL_Rect * srcrect,561const SDL_Rect * dstrect);562563/**564* \brief Read pixels from the current rendering target.565*566* \param rect A pointer to the rectangle to read, or NULL for the entire567* render target.568* \param format The desired format of the pixel data, or 0 to use the format569* of the rendering target570* \param pixels A pointer to be filled in with the pixel data571* \param pitch The pitch of the pixels parameter.572*573* \return 0 on success, or -1 if pixel reading is not supported.574*575* \warning This is a very slow operation, and should not be used frequently.576*/577extern DECLSPEC int SDLCALL SDL_RenderReadPixels(SDL_Renderer * renderer,578const SDL_Rect * rect,579Uint32 format,580void *pixels, int pitch);581582/**583* \brief Update the screen with rendering performed.584*/585extern DECLSPEC void SDLCALL SDL_RenderPresent(SDL_Renderer * renderer);586587/**588* \brief Destroy the specified texture.589*590* \sa SDL_CreateTexture()591* \sa SDL_CreateTextureFromSurface()592*/593extern DECLSPEC void SDLCALL SDL_DestroyTexture(SDL_Texture * texture);594595/**596* \brief Destroy the rendering context for a window and free associated597* textures.598*599* \sa SDL_CreateRenderer()600*/601extern DECLSPEC void SDLCALL SDL_DestroyRenderer(SDL_Renderer * renderer);602603604/* Ends C function definitions when using C++ */605#ifdef __cplusplus606/* *INDENT-OFF* */607}608/* *INDENT-ON* */609#endif610#include "close_code.h"611612#endif /* _SDL_render_h */613614/* vi: set ts=4 sw=4 expandtab: */615616617