SDL_render.h 61 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2023 Sam Lantinga <[email protected]>
  4. This software is provided 'as-is', without any express or implied
  5. warranty. In no event will the authors be held liable for any damages
  6. arising from the use of this software.
  7. Permission is granted to anyone to use this software for any purpose,
  8. including commercial applications, and to alter it and redistribute it
  9. freely, subject to the following restrictions:
  10. 1. The origin of this software must not be misrepresented; you must not
  11. claim that you wrote the original software. If you use this software
  12. in a product, an acknowledgment in the product documentation would be
  13. appreciated but is not required.
  14. 2. Altered source versions must be plainly marked as such, and must not be
  15. misrepresented as being the original software.
  16. 3. This notice may not be removed or altered from any source distribution.
  17. */
  18. /**
  19. * \file SDL_render.h
  20. *
  21. * Header file for SDL 2D rendering functions.
  22. *
  23. * This API supports the following features:
  24. * * single pixel points
  25. * * single pixel lines
  26. * * filled rectangles
  27. * * texture images
  28. *
  29. * The primitives may be drawn in opaque, blended, or additive modes.
  30. *
  31. * The texture images may be drawn in opaque, blended, or additive modes.
  32. * They can have an additional color tint or alpha modulation applied to
  33. * them, and may also be stretched with linear interpolation.
  34. *
  35. * This API is designed to accelerate simple 2D operations. You may
  36. * want more functionality such as polygons and particle effects and
  37. * in that case you should use SDL's OpenGL/Direct3D support or one
  38. * of the many good 3D engines.
  39. *
  40. * These functions must be called from the main thread.
  41. * See this bug for details: https://github.com/libsdl-org/SDL/issues/986
  42. */
  43. #ifndef SDL_render_h_
  44. #define SDL_render_h_
  45. #include <SDL3/SDL_stdinc.h>
  46. #include <SDL3/SDL_events.h>
  47. #include <SDL3/SDL_properties.h>
  48. #include <SDL3/SDL_rect.h>
  49. #include <SDL3/SDL_video.h>
  50. #include <SDL3/SDL_begin_code.h>
  51. /* Set up for C function definitions, even when using C++ */
  52. #ifdef __cplusplus
  53. extern "C" {
  54. #endif
  55. /**
  56. * Flags used when creating a rendering context
  57. */
  58. typedef enum
  59. {
  60. SDL_RENDERER_SOFTWARE = 0x00000001, /**< The renderer is a software fallback */
  61. SDL_RENDERER_ACCELERATED = 0x00000002, /**< The renderer uses hardware
  62. acceleration */
  63. SDL_RENDERER_PRESENTVSYNC = 0x00000004 /**< Present is synchronized
  64. with the refresh rate */
  65. } SDL_RendererFlags;
  66. /**
  67. * Information on the capabilities of a render driver or context.
  68. */
  69. typedef struct SDL_RendererInfo
  70. {
  71. const char *name; /**< The name of the renderer */
  72. Uint32 flags; /**< Supported ::SDL_RendererFlags */
  73. Uint32 num_texture_formats; /**< The number of available texture formats */
  74. Uint32 texture_formats[16]; /**< The available texture formats */
  75. int max_texture_width; /**< The maximum texture width */
  76. int max_texture_height; /**< The maximum texture height */
  77. } SDL_RendererInfo;
  78. /**
  79. * Vertex structure
  80. */
  81. typedef struct SDL_Vertex
  82. {
  83. SDL_FPoint position; /**< Vertex position, in SDL_Renderer coordinates */
  84. SDL_Color color; /**< Vertex color */
  85. SDL_FPoint tex_coord; /**< Normalized texture coordinates, if needed */
  86. } SDL_Vertex;
  87. /**
  88. * The scaling mode for a texture.
  89. */
  90. typedef enum
  91. {
  92. SDL_SCALEMODE_NEAREST, /**< nearest pixel sampling */
  93. SDL_SCALEMODE_LINEAR, /**< linear filtering */
  94. SDL_SCALEMODE_BEST /**< anisotropic filtering */
  95. } SDL_ScaleMode;
  96. /**
  97. * The access pattern allowed for a texture.
  98. */
  99. typedef enum
  100. {
  101. SDL_TEXTUREACCESS_STATIC, /**< Changes rarely, not lockable */
  102. SDL_TEXTUREACCESS_STREAMING, /**< Changes frequently, lockable */
  103. SDL_TEXTUREACCESS_TARGET /**< Texture can be used as a render target */
  104. } SDL_TextureAccess;
  105. /**
  106. * Flip constants for SDL_RenderTextureRotated
  107. */
  108. typedef enum
  109. {
  110. SDL_FLIP_NONE = 0x00000000, /**< Do not flip */
  111. SDL_FLIP_HORIZONTAL = 0x00000001, /**< flip horizontally */
  112. SDL_FLIP_VERTICAL = 0x00000002 /**< flip vertically */
  113. } SDL_RendererFlip;
  114. /**
  115. * How the logical size is mapped to the output
  116. */
  117. typedef enum
  118. {
  119. SDL_LOGICAL_PRESENTATION_DISABLED, /**< There is no logical size in effect */
  120. SDL_LOGICAL_PRESENTATION_STRETCH, /**< The rendered content is stretched to the output resolution */
  121. SDL_LOGICAL_PRESENTATION_LETTERBOX, /**< The rendered content is fit to the largest dimension and the other dimension is letterboxed with black bars */
  122. SDL_LOGICAL_PRESENTATION_OVERSCAN, /**< The rendered content is fit to the smallest dimension and the other dimension extends beyond the output bounds */
  123. SDL_LOGICAL_PRESENTATION_INTEGER_SCALE /**< The rendered content is scaled up by integer multiples to fit the output resolution */
  124. } SDL_RendererLogicalPresentation;
  125. /**
  126. * A structure representing rendering state
  127. */
  128. struct SDL_Renderer;
  129. typedef struct SDL_Renderer SDL_Renderer;
  130. /**
  131. * An efficient driver-specific representation of pixel data
  132. */
  133. struct SDL_Texture;
  134. typedef struct SDL_Texture SDL_Texture;
  135. /* Function prototypes */
  136. /**
  137. * Get the number of 2D rendering drivers available for the current display.
  138. *
  139. * A render driver is a set of code that handles rendering and texture
  140. * management on a particular display. Normally there is only one, but some
  141. * drivers may have several available with different capabilities.
  142. *
  143. * There may be none if SDL was compiled without render support.
  144. *
  145. * \returns a number >= 0 on success or a negative error code on failure; call
  146. * SDL_GetError() for more information.
  147. *
  148. * \since This function is available since SDL 3.0.0.
  149. *
  150. * \sa SDL_CreateRenderer
  151. * \sa SDL_GetRenderDriver
  152. */
  153. extern DECLSPEC int SDLCALL SDL_GetNumRenderDrivers(void);
  154. /**
  155. * Use this function to get the name of a built in 2D rendering driver.
  156. *
  157. * The list of rendering drivers is given in the order that they are normally
  158. * initialized by default; the drivers that seem more reasonable to choose
  159. * first (as far as the SDL developers believe) are earlier in the list.
  160. *
  161. * The names of drivers are all simple, low-ASCII identifiers, like "opengl",
  162. * "direct3d12" or "metal". These never have Unicode characters, and are not
  163. * meant to be proper names.
  164. *
  165. * The returned value points to a static, read-only string; do not modify or
  166. * free it!
  167. *
  168. * \param index the index of the rendering driver; the value ranges from 0 to
  169. * SDL_GetNumRenderDrivers() - 1
  170. * \returns the name of the rendering driver at the requested index, or NULL
  171. * if an invalid index was specified.
  172. *
  173. * \since This function is available since SDL 3.0.0.
  174. *
  175. * \sa SDL_GetNumRenderDrivers
  176. */
  177. extern DECLSPEC const char *SDLCALL SDL_GetRenderDriver(int index);
  178. /**
  179. * Create a window and default renderer.
  180. *
  181. * \param width the width of the window
  182. * \param height the height of the window
  183. * \param window_flags the flags used to create the window (see
  184. * SDL_CreateWindow())
  185. * \param window a pointer filled with the window, or NULL on error
  186. * \param renderer a pointer filled with the renderer, or NULL on error
  187. * \returns 0 on success or a negative error code on failure; call
  188. * SDL_GetError() for more information.
  189. *
  190. * \since This function is available since SDL 3.0.0.
  191. *
  192. * \sa SDL_CreateRenderer
  193. * \sa SDL_CreateWindow
  194. */
  195. extern DECLSPEC int SDLCALL SDL_CreateWindowAndRenderer(int width, int height, Uint32 window_flags, SDL_Window **window, SDL_Renderer **renderer);
  196. /**
  197. * Create a 2D rendering context for a window.
  198. *
  199. * If you want a specific renderer, you can specify its name here. A list of
  200. * available renderers can be obtained by calling SDL_GetRenderDriver multiple
  201. * times, with indices from 0 to SDL_GetNumRenderDrivers()-1. If you don't
  202. * need a specific renderer, specify NULL and SDL will attempt to chooes the
  203. * best option for you, based on what is available on the user's system.
  204. *
  205. * By default the rendering size matches the window size in pixels, but you
  206. * can call SDL_SetRenderLogicalPresentation() to change the content size and
  207. * scaling options.
  208. *
  209. * \param window the window where rendering is displayed
  210. * \param name the name of the rendering driver to initialize, or NULL to
  211. * initialize the first one supporting the requested flags
  212. * \param flags 0, or one or more SDL_RendererFlags OR'd together
  213. * \returns a valid rendering context or NULL if there was an error; call
  214. * SDL_GetError() for more information.
  215. *
  216. * \since This function is available since SDL 3.0.0.
  217. *
  218. * \sa SDL_CreateSoftwareRenderer
  219. * \sa SDL_DestroyRenderer
  220. * \sa SDL_GetNumRenderDrivers
  221. * \sa SDL_GetRenderDriver
  222. * \sa SDL_GetRendererInfo
  223. */
  224. extern DECLSPEC SDL_Renderer *SDLCALL SDL_CreateRenderer(SDL_Window *window, const char *name, Uint32 flags);
  225. /**
  226. * Create a 2D software rendering context for a surface.
  227. *
  228. * Two other API which can be used to create SDL_Renderer:
  229. * SDL_CreateRenderer() and SDL_CreateWindowAndRenderer(). These can _also_
  230. * create a software renderer, but they are intended to be used with an
  231. * SDL_Window as the final destination and not an SDL_Surface.
  232. *
  233. * \param surface the SDL_Surface structure representing the surface where
  234. * rendering is done
  235. * \returns a valid rendering context or NULL if there was an error; call
  236. * SDL_GetError() for more information.
  237. *
  238. * \since This function is available since SDL 3.0.0.
  239. *
  240. * \sa SDL_CreateRenderer
  241. * \sa SDL_CreateWindowRenderer
  242. * \sa SDL_DestroyRenderer
  243. */
  244. extern DECLSPEC SDL_Renderer *SDLCALL SDL_CreateSoftwareRenderer(SDL_Surface *surface);
  245. /**
  246. * Get the renderer associated with a window.
  247. *
  248. * \param window the window to query
  249. * \returns the rendering context on success or NULL on failure; call
  250. * SDL_GetError() for more information.
  251. *
  252. * \since This function is available since SDL 3.0.0.
  253. *
  254. * \sa SDL_CreateRenderer
  255. */
  256. extern DECLSPEC SDL_Renderer *SDLCALL SDL_GetRenderer(SDL_Window *window);
  257. /**
  258. * Get the window associated with a renderer.
  259. *
  260. * \param renderer the renderer to query
  261. * \returns the window on success or NULL on failure; call SDL_GetError() for
  262. * more information.
  263. *
  264. * \since This function is available since SDL 3.0.0.
  265. */
  266. extern DECLSPEC SDL_Window *SDLCALL SDL_GetRenderWindow(SDL_Renderer *renderer);
  267. /**
  268. * Get information about a rendering context.
  269. *
  270. * \param renderer the rendering context
  271. * \param info an SDL_RendererInfo structure filled with information about the
  272. * current renderer
  273. * \returns 0 on success or a negative error code on failure; call
  274. * SDL_GetError() for more information.
  275. *
  276. * \since This function is available since SDL 3.0.0.
  277. *
  278. * \sa SDL_CreateRenderer
  279. */
  280. extern DECLSPEC int SDLCALL SDL_GetRendererInfo(SDL_Renderer *renderer, SDL_RendererInfo *info);
  281. /**
  282. * Get the properties associated with a renderer.
  283. *
  284. * The following properties are provided by SDL: "SDL.renderer.d3d9.device" -
  285. * the IDirect3DDevice9 associated with the renderer
  286. * "SDL.renderer.d3d11.device" - the ID3D11Device associated with the renderer
  287. * "SDL.renderer.d3d12.device" - the ID3D12Device associated with the renderer
  288. * "SDL.renderer.d3d12.command_queue" - the ID3D12CommandQueue associated with
  289. * the renderer
  290. *
  291. * \param renderer the rendering context
  292. * \returns a valid property ID on success or 0 on failure; call
  293. * SDL_GetError() for more information.
  294. *
  295. * \since This function is available since SDL 3.0.0.
  296. *
  297. * \sa SDL_GetProperty
  298. * \sa SDL_SetProperty
  299. */
  300. extern DECLSPEC SDL_PropertiesID SDLCALL SDL_GetRendererProperties(SDL_Renderer *renderer);
  301. /**
  302. * Get the output size in pixels of a rendering context.
  303. *
  304. * This returns the true output size in pixels, ignoring any render targets or
  305. * logical size and presentation.
  306. *
  307. * \param renderer the rendering context
  308. * \param w a pointer filled in with the width in pixels
  309. * \param h a pointer filled in with the height in pixels
  310. * \returns 0 on success or a negative error code on failure; call
  311. * SDL_GetError() for more information.
  312. *
  313. * \since This function is available since SDL 3.0.0.
  314. *
  315. * \sa SDL_GetRenderer
  316. */
  317. extern DECLSPEC int SDLCALL SDL_GetRenderOutputSize(SDL_Renderer *renderer, int *w, int *h);
  318. /**
  319. * Get the current output size in pixels of a rendering context.
  320. *
  321. * If a rendering target is active, this will return the size of the rendering
  322. * target in pixels, otherwise if a logical size is set, it will return the
  323. * logical size, otherwise it will return the value of
  324. * SDL_GetRenderOutputSize().
  325. *
  326. * \param renderer the rendering context
  327. * \param w a pointer filled in with the current width
  328. * \param h a pointer filled in with the current height
  329. * \returns 0 on success or a negative error code on failure; call
  330. * SDL_GetError() for more information.
  331. *
  332. * \since This function is available since SDL 3.0.0.
  333. *
  334. * \sa SDL_GetRenderOutputSize
  335. * \sa SDL_GetRenderer
  336. */
  337. extern DECLSPEC int SDLCALL SDL_GetCurrentRenderOutputSize(SDL_Renderer *renderer, int *w, int *h);
  338. /**
  339. * Create a texture for a rendering context.
  340. *
  341. * You can set the texture scaling method by setting
  342. * `SDL_HINT_RENDER_SCALE_QUALITY` before creating the texture.
  343. *
  344. * \param renderer the rendering context
  345. * \param format one of the enumerated values in SDL_PixelFormatEnum
  346. * \param access one of the enumerated values in SDL_TextureAccess
  347. * \param w the width of the texture in pixels
  348. * \param h the height of the texture in pixels
  349. * \returns a pointer to the created texture or NULL if no rendering context
  350. * was active, the format was unsupported, or the width or height
  351. * were out of range; call SDL_GetError() for more information.
  352. *
  353. * \since This function is available since SDL 3.0.0.
  354. *
  355. * \sa SDL_CreateTextureFromSurface
  356. * \sa SDL_DestroyTexture
  357. * \sa SDL_QueryTexture
  358. * \sa SDL_UpdateTexture
  359. */
  360. extern DECLSPEC SDL_Texture *SDLCALL SDL_CreateTexture(SDL_Renderer *renderer, Uint32 format, int access, int w, int h);
  361. /**
  362. * Create a texture from an existing surface.
  363. *
  364. * The surface is not modified or freed by this function.
  365. *
  366. * The SDL_TextureAccess hint for the created texture is
  367. * `SDL_TEXTUREACCESS_STATIC`.
  368. *
  369. * The pixel format of the created texture may be different from the pixel
  370. * format of the surface. Use SDL_QueryTexture() to query the pixel format of
  371. * the texture.
  372. *
  373. * \param renderer the rendering context
  374. * \param surface the SDL_Surface structure containing pixel data used to fill
  375. * the texture
  376. * \returns the created texture or NULL on failure; call SDL_GetError() for
  377. * more information.
  378. *
  379. * \since This function is available since SDL 3.0.0.
  380. *
  381. * \sa SDL_CreateTexture
  382. * \sa SDL_DestroyTexture
  383. * \sa SDL_QueryTexture
  384. */
  385. extern DECLSPEC SDL_Texture *SDLCALL SDL_CreateTextureFromSurface(SDL_Renderer *renderer, SDL_Surface *surface);
  386. /**
  387. * Get the properties associated with a texture.
  388. *
  389. * \param texture the texture to query
  390. * \returns a valid property ID on success or 0 on failure; call
  391. * SDL_GetError() for more information.
  392. *
  393. * \since This function is available since SDL 3.0.0.
  394. *
  395. * \sa SDL_GetProperty
  396. * \sa SDL_SetProperty
  397. */
  398. extern DECLSPEC SDL_PropertiesID SDLCALL SDL_GetTextureProperties(SDL_Texture *texture);
  399. /**
  400. * Query the attributes of a texture.
  401. *
  402. * \param texture the texture to query
  403. * \param format a pointer filled in with the raw format of the texture; the
  404. * actual format may differ, but pixel transfers will use this
  405. * format (one of the SDL_PixelFormatEnum values). This argument
  406. * can be NULL if you don't need this information.
  407. * \param access a pointer filled in with the actual access to the texture
  408. * (one of the SDL_TextureAccess values). This argument can be
  409. * NULL if you don't need this information.
  410. * \param w a pointer filled in with the width of the texture in pixels. This
  411. * argument can be NULL if you don't need this information.
  412. * \param h a pointer filled in with the height of the texture in pixels. This
  413. * argument can be NULL if you don't need this information.
  414. * \returns 0 on success or a negative error code on failure; call
  415. * SDL_GetError() for more information.
  416. *
  417. * \since This function is available since SDL 3.0.0.
  418. *
  419. * \sa SDL_CreateTexture
  420. */
  421. extern DECLSPEC int SDLCALL SDL_QueryTexture(SDL_Texture *texture, Uint32 *format, int *access, int *w, int *h);
  422. /**
  423. * Set an additional color value multiplied into render copy operations.
  424. *
  425. * When this texture is rendered, during the copy operation each source color
  426. * channel is modulated by the appropriate color value according to the
  427. * following formula:
  428. *
  429. * `srcC = srcC * (color / 255)`
  430. *
  431. * Color modulation is not always supported by the renderer; it will return -1
  432. * if color modulation is not supported.
  433. *
  434. * \param texture the texture to update
  435. * \param r the red color value multiplied into copy operations
  436. * \param g the green color value multiplied into copy operations
  437. * \param b the blue color value multiplied into copy operations
  438. * \returns 0 on success or a negative error code on failure; call
  439. * SDL_GetError() for more information.
  440. *
  441. * \since This function is available since SDL 3.0.0.
  442. *
  443. * \sa SDL_GetTextureColorMod
  444. * \sa SDL_SetTextureAlphaMod
  445. */
  446. extern DECLSPEC int SDLCALL SDL_SetTextureColorMod(SDL_Texture *texture, Uint8 r, Uint8 g, Uint8 b);
  447. /**
  448. * Get the additional color value multiplied into render copy operations.
  449. *
  450. * \param texture the texture to query
  451. * \param r a pointer filled in with the current red color value
  452. * \param g a pointer filled in with the current green color value
  453. * \param b a pointer filled in with the current blue color value
  454. * \returns 0 on success or a negative error code on failure; call
  455. * SDL_GetError() for more information.
  456. *
  457. * \since This function is available since SDL 3.0.0.
  458. *
  459. * \sa SDL_GetTextureAlphaMod
  460. * \sa SDL_SetTextureColorMod
  461. */
  462. extern DECLSPEC int SDLCALL SDL_GetTextureColorMod(SDL_Texture *texture, Uint8 *r, Uint8 *g, Uint8 *b);
  463. /**
  464. * Set an additional alpha value multiplied into render copy operations.
  465. *
  466. * When this texture is rendered, during the copy operation the source alpha
  467. * value is modulated by this alpha value according to the following formula:
  468. *
  469. * `srcA = srcA * (alpha / 255)`
  470. *
  471. * Alpha modulation is not always supported by the renderer; it will return -1
  472. * if alpha modulation is not supported.
  473. *
  474. * \param texture the texture to update
  475. * \param alpha the source alpha value multiplied into copy operations
  476. * \returns 0 on success or a negative error code on failure; call
  477. * SDL_GetError() for more information.
  478. *
  479. * \since This function is available since SDL 3.0.0.
  480. *
  481. * \sa SDL_GetTextureAlphaMod
  482. * \sa SDL_SetTextureColorMod
  483. */
  484. extern DECLSPEC int SDLCALL SDL_SetTextureAlphaMod(SDL_Texture *texture, Uint8 alpha);
  485. /**
  486. * Get the additional alpha value multiplied into render copy operations.
  487. *
  488. * \param texture the texture to query
  489. * \param alpha a pointer filled in with the current alpha value
  490. * \returns 0 on success or a negative error code on failure; call
  491. * SDL_GetError() for more information.
  492. *
  493. * \since This function is available since SDL 3.0.0.
  494. *
  495. * \sa SDL_GetTextureColorMod
  496. * \sa SDL_SetTextureAlphaMod
  497. */
  498. extern DECLSPEC int SDLCALL SDL_GetTextureAlphaMod(SDL_Texture *texture, Uint8 *alpha);
  499. /**
  500. * Set the blend mode for a texture, used by SDL_RenderTexture().
  501. *
  502. * If the blend mode is not supported, the closest supported mode is chosen
  503. * and this function returns -1.
  504. *
  505. * \param texture the texture to update
  506. * \param blendMode the SDL_BlendMode to use for texture blending
  507. * \returns 0 on success or a negative error code on failure; call
  508. * SDL_GetError() for more information.
  509. *
  510. * \since This function is available since SDL 3.0.0.
  511. *
  512. * \sa SDL_GetTextureBlendMode
  513. * \sa SDL_RenderTexture
  514. */
  515. extern DECLSPEC int SDLCALL SDL_SetTextureBlendMode(SDL_Texture *texture, SDL_BlendMode blendMode);
  516. /**
  517. * Get the blend mode used for texture copy operations.
  518. *
  519. * \param texture the texture to query
  520. * \param blendMode a pointer filled in with the current SDL_BlendMode
  521. * \returns 0 on success or a negative error code on failure; call
  522. * SDL_GetError() for more information.
  523. *
  524. * \since This function is available since SDL 3.0.0.
  525. *
  526. * \sa SDL_SetTextureBlendMode
  527. */
  528. extern DECLSPEC int SDLCALL SDL_GetTextureBlendMode(SDL_Texture *texture, SDL_BlendMode *blendMode);
  529. /**
  530. * Set the scale mode used for texture scale operations.
  531. *
  532. * If the scale mode is not supported, the closest supported mode is chosen.
  533. *
  534. * \param texture The texture to update.
  535. * \param scaleMode the SDL_ScaleMode to use for texture scaling.
  536. * \returns 0 on success or a negative error code on failure; call
  537. * SDL_GetError() for more information.
  538. *
  539. * \since This function is available since SDL 3.0.0.
  540. *
  541. * \sa SDL_GetTextureScaleMode
  542. */
  543. extern DECLSPEC int SDLCALL SDL_SetTextureScaleMode(SDL_Texture *texture, SDL_ScaleMode scaleMode);
  544. /**
  545. * Get the scale mode used for texture scale operations.
  546. *
  547. * \param texture the texture to query.
  548. * \param scaleMode a pointer filled in with the current scale mode.
  549. * \returns 0 on success or a negative error code on failure; call
  550. * SDL_GetError() for more information.
  551. *
  552. * \since This function is available since SDL 3.0.0.
  553. *
  554. * \sa SDL_SetTextureScaleMode
  555. */
  556. extern DECLSPEC int SDLCALL SDL_GetTextureScaleMode(SDL_Texture *texture, SDL_ScaleMode *scaleMode);
  557. /**
  558. * Update the given texture rectangle with new pixel data.
  559. *
  560. * The pixel data must be in the pixel format of the texture. Use
  561. * SDL_QueryTexture() to query the pixel format of the texture.
  562. *
  563. * This is a fairly slow function, intended for use with static textures that
  564. * do not change often.
  565. *
  566. * If the texture is intended to be updated often, it is preferred to create
  567. * the texture as streaming and use the locking functions referenced below.
  568. * While this function will work with streaming textures, for optimization
  569. * reasons you may not get the pixels back if you lock the texture afterward.
  570. *
  571. * \param texture the texture to update
  572. * \param rect an SDL_Rect structure representing the area to update, or NULL
  573. * to update the entire texture
  574. * \param pixels the raw pixel data in the format of the texture
  575. * \param pitch the number of bytes in a row of pixel data, including padding
  576. * between lines
  577. * \returns 0 on success or a negative error code on failure; call
  578. * SDL_GetError() for more information.
  579. *
  580. * \since This function is available since SDL 3.0.0.
  581. *
  582. * \sa SDL_CreateTexture
  583. * \sa SDL_LockTexture
  584. * \sa SDL_UnlockTexture
  585. */
  586. extern DECLSPEC int SDLCALL SDL_UpdateTexture(SDL_Texture *texture, const SDL_Rect *rect, const void *pixels, int pitch);
  587. /**
  588. * Update a rectangle within a planar YV12 or IYUV texture with new pixel
  589. * data.
  590. *
  591. * You can use SDL_UpdateTexture() as long as your pixel data is a contiguous
  592. * block of Y and U/V planes in the proper order, but this function is
  593. * available if your pixel data is not contiguous.
  594. *
  595. * \param texture the texture to update
  596. * \param rect a pointer to the rectangle of pixels to update, or NULL to
  597. * update the entire texture
  598. * \param Yplane the raw pixel data for the Y plane
  599. * \param Ypitch the number of bytes between rows of pixel data for the Y
  600. * plane
  601. * \param Uplane the raw pixel data for the U plane
  602. * \param Upitch the number of bytes between rows of pixel data for the U
  603. * plane
  604. * \param Vplane the raw pixel data for the V plane
  605. * \param Vpitch the number of bytes between rows of pixel data for the V
  606. * plane
  607. * \returns 0 on success or a negative error code on failure; call
  608. * SDL_GetError() for more information.
  609. *
  610. * \since This function is available since SDL 3.0.0.
  611. *
  612. * \sa SDL_UpdateTexture
  613. */
  614. extern DECLSPEC int SDLCALL SDL_UpdateYUVTexture(SDL_Texture *texture,
  615. const SDL_Rect *rect,
  616. const Uint8 *Yplane, int Ypitch,
  617. const Uint8 *Uplane, int Upitch,
  618. const Uint8 *Vplane, int Vpitch);
  619. /**
  620. * Update a rectangle within a planar NV12 or NV21 texture with new pixels.
  621. *
  622. * You can use SDL_UpdateTexture() as long as your pixel data is a contiguous
  623. * block of NV12/21 planes in the proper order, but this function is available
  624. * if your pixel data is not contiguous.
  625. *
  626. * \param texture the texture to update
  627. * \param rect a pointer to the rectangle of pixels to update, or NULL to
  628. * update the entire texture.
  629. * \param Yplane the raw pixel data for the Y plane.
  630. * \param Ypitch the number of bytes between rows of pixel data for the Y
  631. * plane.
  632. * \param UVplane the raw pixel data for the UV plane.
  633. * \param UVpitch the number of bytes between rows of pixel data for the UV
  634. * plane.
  635. * \returns 0 on success or a negative error code on failure; call
  636. * SDL_GetError() for more information.
  637. *
  638. * \since This function is available since SDL 3.0.0.
  639. */
  640. extern DECLSPEC int SDLCALL SDL_UpdateNVTexture(SDL_Texture *texture,
  641. const SDL_Rect *rect,
  642. const Uint8 *Yplane, int Ypitch,
  643. const Uint8 *UVplane, int UVpitch);
  644. /**
  645. * Lock a portion of the texture for **write-only** pixel access.
  646. *
  647. * As an optimization, the pixels made available for editing don't necessarily
  648. * contain the old texture data. This is a write-only operation, and if you
  649. * need to keep a copy of the texture data you should do that at the
  650. * application level.
  651. *
  652. * You must use SDL_UnlockTexture() to unlock the pixels and apply any
  653. * changes.
  654. *
  655. * \param texture the texture to lock for access, which was created with
  656. * `SDL_TEXTUREACCESS_STREAMING`
  657. * \param rect an SDL_Rect structure representing the area to lock for access;
  658. * NULL to lock the entire texture
  659. * \param pixels this is filled in with a pointer to the locked pixels,
  660. * appropriately offset by the locked area
  661. * \param pitch this is filled in with the pitch of the locked pixels; the
  662. * pitch is the length of one row in bytes
  663. * \returns 0 on success or a negative error code if the texture is not valid
  664. * or was not created with `SDL_TEXTUREACCESS_STREAMING`; call
  665. * SDL_GetError() for more information.
  666. *
  667. * \since This function is available since SDL 3.0.0.
  668. *
  669. * \sa SDL_UnlockTexture
  670. */
  671. extern DECLSPEC int SDLCALL SDL_LockTexture(SDL_Texture *texture,
  672. const SDL_Rect *rect,
  673. void **pixels, int *pitch);
  674. /**
  675. * Lock a portion of the texture for **write-only** pixel access, and expose
  676. * it as a SDL surface.
  677. *
  678. * Besides providing an SDL_Surface instead of raw pixel data, this function
  679. * operates like SDL_LockTexture.
  680. *
  681. * As an optimization, the pixels made available for editing don't necessarily
  682. * contain the old texture data. This is a write-only operation, and if you
  683. * need to keep a copy of the texture data you should do that at the
  684. * application level.
  685. *
  686. * You must use SDL_UnlockTexture() to unlock the pixels and apply any
  687. * changes.
  688. *
  689. * The returned surface is freed internally after calling SDL_UnlockTexture()
  690. * or SDL_DestroyTexture(). The caller should not free it.
  691. *
  692. * \param texture the texture to lock for access, which must be created with
  693. * `SDL_TEXTUREACCESS_STREAMING`
  694. * \param rect a pointer to the rectangle to lock for access. If the rect is
  695. * NULL, the entire texture will be locked
  696. * \param surface this is filled in with an SDL surface representing the
  697. * locked area
  698. * \returns 0 on success or a negative error code on failure; call
  699. * SDL_GetError() for more information.
  700. *
  701. * \since This function is available since SDL 3.0.0.
  702. *
  703. * \sa SDL_LockTexture
  704. * \sa SDL_UnlockTexture
  705. */
  706. extern DECLSPEC int SDLCALL SDL_LockTextureToSurface(SDL_Texture *texture,
  707. const SDL_Rect *rect,
  708. SDL_Surface **surface);
  709. /**
  710. * Unlock a texture, uploading the changes to video memory, if needed.
  711. *
  712. * **Warning**: Please note that SDL_LockTexture() is intended to be
  713. * write-only; it will not guarantee the previous contents of the texture will
  714. * be provided. You must fully initialize any area of a texture that you lock
  715. * before unlocking it, as the pixels might otherwise be uninitialized memory.
  716. *
  717. * Which is to say: locking and immediately unlocking a texture can result in
  718. * corrupted textures, depending on the renderer in use.
  719. *
  720. * \param texture a texture locked by SDL_LockTexture()
  721. *
  722. * \since This function is available since SDL 3.0.0.
  723. *
  724. * \sa SDL_LockTexture
  725. */
  726. extern DECLSPEC void SDLCALL SDL_UnlockTexture(SDL_Texture *texture);
  727. /**
  728. * Set a texture as the current rendering target.
  729. *
  730. * The default render target is the window for which the renderer was created.
  731. * To stop rendering to a texture and render to the window again, call this
  732. * function with a NULL `texture`.
  733. *
  734. * \param renderer the rendering context
  735. * \param texture the targeted texture, which must be created with the
  736. * `SDL_TEXTUREACCESS_TARGET` flag, or NULL to render to the
  737. * window instead of a texture.
  738. * \returns 0 on success or a negative error code on failure; call
  739. * SDL_GetError() for more information.
  740. *
  741. * \since This function is available since SDL 3.0.0.
  742. *
  743. * \sa SDL_GetRenderTarget
  744. */
  745. extern DECLSPEC int SDLCALL SDL_SetRenderTarget(SDL_Renderer *renderer, SDL_Texture *texture);
  746. /**
  747. * Get the current render target.
  748. *
  749. * The default render target is the window for which the renderer was created,
  750. * and is reported a NULL here.
  751. *
  752. * \param renderer the rendering context
  753. * \returns the current render target or NULL for the default render target.
  754. *
  755. * \since This function is available since SDL 3.0.0.
  756. *
  757. * \sa SDL_SetRenderTarget
  758. */
  759. extern DECLSPEC SDL_Texture *SDLCALL SDL_GetRenderTarget(SDL_Renderer *renderer);
  760. /**
  761. * Set a device independent resolution and presentation mode for rendering.
  762. *
  763. * This function sets the width and height of the logical rendering output. A
  764. * render target is created at the specified size and used for rendering and
  765. * then copied to the output during presentation.
  766. *
  767. * You can disable logical coordinates by setting the mode to
  768. * SDL_LOGICAL_PRESENTATION_DISABLED, and in that case you get the full pixel
  769. * resolution of the output window.
  770. *
  771. * You can convert coordinates in an event into rendering coordinates using
  772. * SDL_ConvertEventToRenderCoordinates().
  773. *
  774. * \param renderer the rendering context
  775. * \param w the width of the logical resolution
  776. * \param h the height of the logical resolution
  777. * \param mode the presentation mode used
  778. * \param scale_mode the scale mode used
  779. * \returns 0 on success or a negative error code on failure; call
  780. * SDL_GetError() for more information.
  781. *
  782. * \since This function is available since SDL 3.0.0.
  783. *
  784. * \sa SDL_ConvertEventToRenderCoordinates
  785. * \sa SDL_GetRenderLogicalPresentation
  786. */
  787. extern DECLSPEC int SDLCALL SDL_SetRenderLogicalPresentation(SDL_Renderer *renderer, int w, int h, SDL_RendererLogicalPresentation mode, SDL_ScaleMode scale_mode);
  788. /**
  789. * Get device independent resolution and presentation mode for rendering.
  790. *
  791. * This function gets the width and height of the logical rendering output, or
  792. * the output size in pixels if a logical resolution is not enabled.
  793. *
  794. * \param renderer the rendering context
  795. * \param w an int to be filled with the width
  796. * \param h an int to be filled with the height
  797. * \param mode a pointer filled in with the presentation mode
  798. * \param scale_mode a pointer filled in with the scale mode
  799. * \returns 0 on success or a negative error code on failure; call
  800. * SDL_GetError() for more information.
  801. *
  802. * \since This function is available since SDL 3.0.0.
  803. *
  804. * \sa SDL_SetRenderLogicalPresentation
  805. */
  806. extern DECLSPEC int SDLCALL SDL_GetRenderLogicalPresentation(SDL_Renderer *renderer, int *w, int *h, SDL_RendererLogicalPresentation *mode, SDL_ScaleMode *scale_mode);
  807. /**
  808. * Get a point in render coordinates when given a point in window coordinates.
  809. *
  810. * \param renderer the rendering context
  811. * \param window_x the x coordinate in window coordinates
  812. * \param window_y the y coordinate in window coordinates
  813. * \param x a pointer filled with the x coordinate in render coordinates
  814. * \param y a pointer filled with the y coordinate in render coordinates
  815. * \returns 0 on success or a negative error code on failure; call
  816. * SDL_GetError() for more information.
  817. *
  818. * \since This function is available since SDL 3.0.0.
  819. *
  820. * \sa SDL_SetRenderLogicalPresentation
  821. * \sa SDL_SetRenderScale
  822. */
  823. extern DECLSPEC int SDLCALL SDL_RenderCoordinatesFromWindow(SDL_Renderer *renderer, float window_x, float window_y, float *x, float *y);
  824. /**
  825. * Get a point in window coordinates when given a point in render coordinates.
  826. *
  827. * \param renderer the rendering context
  828. * \param x the x coordinate in render coordinates
  829. * \param y the y coordinate in render coordinates
  830. * \param window_x a pointer filled with the x coordinate in window
  831. * coordinates
  832. * \param window_y a pointer filled with the y coordinate in window
  833. * coordinates
  834. * \returns 0 on success or a negative error code on failure; call
  835. * SDL_GetError() for more information.
  836. *
  837. * \since This function is available since SDL 3.0.0.
  838. *
  839. * \sa SDL_SetRenderLogicalPresentation
  840. * \sa SDL_SetRenderScale
  841. */
  842. extern DECLSPEC int SDLCALL SDL_RenderCoordinatesToWindow(SDL_Renderer *renderer, float x, float y, float *window_x, float *window_y);
  843. /**
  844. * Convert the coordinates in an event to render coordinates.
  845. *
  846. * Touch coordinates are converted from normalized coordinates in the window
  847. * to non-normalized rendering coordinates.
  848. *
  849. * Once converted, the coordinates may be outside the rendering area.
  850. *
  851. * \param renderer the rendering context
  852. * \param event the event to modify
  853. * \returns 0 on success or a negative error code on failure; call
  854. * SDL_GetError() for more information.
  855. *
  856. * \since This function is available since SDL 3.0.0.
  857. *
  858. * \sa SDL_GetRenderCoordinatesFromWindowCoordinates
  859. */
  860. extern DECLSPEC int SDLCALL SDL_ConvertEventToRenderCoordinates(SDL_Renderer *renderer, SDL_Event *event);
  861. /**
  862. * Set the drawing area for rendering on the current target.
  863. *
  864. * \param renderer the rendering context
  865. * \param rect the SDL_Rect structure representing the drawing area, or NULL
  866. * to set the viewport to the entire target
  867. * \returns 0 on success or a negative error code on failure; call
  868. * SDL_GetError() for more information.
  869. *
  870. * \since This function is available since SDL 3.0.0.
  871. *
  872. * \sa SDL_GetRenderViewport
  873. */
  874. extern DECLSPEC int SDLCALL SDL_SetRenderViewport(SDL_Renderer *renderer, const SDL_Rect *rect);
  875. /**
  876. * Get the drawing area for the current target.
  877. *
  878. * \param renderer the rendering context
  879. * \param rect an SDL_Rect structure filled in with the current drawing area
  880. * \returns 0 on success or a negative error code on failure; call
  881. * SDL_GetError() for more information.
  882. *
  883. * \since This function is available since SDL 3.0.0.
  884. *
  885. * \sa SDL_SetRenderViewport
  886. */
  887. extern DECLSPEC int SDLCALL SDL_GetRenderViewport(SDL_Renderer *renderer, SDL_Rect *rect);
  888. /**
  889. * Set the clip rectangle for rendering on the specified target.
  890. *
  891. * \param renderer the rendering context
  892. * \param rect an SDL_Rect structure representing the clip area, relative to
  893. * the viewport, or NULL to disable clipping
  894. * \returns 0 on success or a negative error code on failure; call
  895. * SDL_GetError() for more information.
  896. *
  897. * \since This function is available since SDL 3.0.0.
  898. *
  899. * \sa SDL_GetRenderClipRect
  900. * \sa SDL_RenderClipEnabled
  901. */
  902. extern DECLSPEC int SDLCALL SDL_SetRenderClipRect(SDL_Renderer *renderer, const SDL_Rect *rect);
  903. /**
  904. * Get the clip rectangle for the current target.
  905. *
  906. * \param renderer the rendering context
  907. * \param rect an SDL_Rect structure filled in with the current clipping area
  908. * or an empty rectangle if clipping is disabled
  909. * \returns 0 on success or a negative error code on failure; call
  910. * SDL_GetError() for more information.
  911. *
  912. * \since This function is available since SDL 3.0.0.
  913. *
  914. * \sa SDL_RenderClipEnabled
  915. * \sa SDL_SetRenderClipRect
  916. */
  917. extern DECLSPEC int SDLCALL SDL_GetRenderClipRect(SDL_Renderer *renderer, SDL_Rect *rect);
  918. /**
  919. * Get whether clipping is enabled on the given renderer.
  920. *
  921. * \param renderer the rendering context
  922. * \returns SDL_TRUE if clipping is enabled or SDL_FALSE if not; call
  923. * SDL_GetError() for more information.
  924. *
  925. * \since This function is available since SDL 3.0.0.
  926. *
  927. * \sa SDL_GetRenderClipRect
  928. * \sa SDL_SetRenderClipRect
  929. */
  930. extern DECLSPEC SDL_bool SDLCALL SDL_RenderClipEnabled(SDL_Renderer *renderer);
  931. /**
  932. * Set the drawing scale for rendering on the current target.
  933. *
  934. * The drawing coordinates are scaled by the x/y scaling factors before they
  935. * are used by the renderer. This allows resolution independent drawing with a
  936. * single coordinate system.
  937. *
  938. * If this results in scaling or subpixel drawing by the rendering backend, it
  939. * will be handled using the appropriate quality hints. For best results use
  940. * integer scaling factors.
  941. *
  942. * \param renderer the rendering context
  943. * \param scaleX the horizontal scaling factor
  944. * \param scaleY the vertical scaling factor
  945. * \returns 0 on success or a negative error code on failure; call
  946. * SDL_GetError() for more information.
  947. *
  948. * \since This function is available since SDL 3.0.0.
  949. *
  950. * \sa SDL_GetRenderScale
  951. */
  952. extern DECLSPEC int SDLCALL SDL_SetRenderScale(SDL_Renderer *renderer, float scaleX, float scaleY);
  953. /**
  954. * Get the drawing scale for the current target.
  955. *
  956. * \param renderer the rendering context
  957. * \param scaleX a pointer filled in with the horizontal scaling factor
  958. * \param scaleY a pointer filled in with the vertical scaling factor
  959. * \returns 0 on success or a negative error code on failure; call
  960. * SDL_GetError() for more information.
  961. *
  962. * \since This function is available since SDL 3.0.0.
  963. *
  964. * \sa SDL_SetRenderScale
  965. */
  966. extern DECLSPEC int SDLCALL SDL_GetRenderScale(SDL_Renderer *renderer, float *scaleX, float *scaleY);
  967. /**
  968. * Set the color used for drawing operations (Rect, Line and Clear).
  969. *
  970. * Set the color for drawing or filling rectangles, lines, and points, and for
  971. * SDL_RenderClear().
  972. *
  973. * \param renderer the rendering context
  974. * \param r the red value used to draw on the rendering target
  975. * \param g the green value used to draw on the rendering target
  976. * \param b the blue value used to draw on the rendering target
  977. * \param a the alpha value used to draw on the rendering target; usually
  978. * `SDL_ALPHA_OPAQUE` (255). Use SDL_SetRenderDrawBlendMode to
  979. * specify how the alpha channel is used
  980. * \returns 0 on success or a negative error code on failure; call
  981. * SDL_GetError() for more information.
  982. *
  983. * \since This function is available since SDL 3.0.0.
  984. *
  985. * \sa SDL_GetRenderDrawColor
  986. * \sa SDL_RenderClear
  987. * \sa SDL_RenderLine
  988. * \sa SDL_RenderLines
  989. * \sa SDL_RenderPoint
  990. * \sa SDL_RenderPoints
  991. * \sa SDL_RenderRect
  992. * \sa SDL_RenderRects
  993. * \sa SDL_RenderFillRect
  994. * \sa SDL_RenderFillRects
  995. */
  996. extern DECLSPEC int SDLCALL SDL_SetRenderDrawColor(SDL_Renderer *renderer, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
  997. /**
  998. * Get the color used for drawing operations (Rect, Line and Clear).
  999. *
  1000. * \param renderer the rendering context
  1001. * \param r a pointer filled in with the red value used to draw on the
  1002. * rendering target
  1003. * \param g a pointer filled in with the green value used to draw on the
  1004. * rendering target
  1005. * \param b a pointer filled in with the blue value used to draw on the
  1006. * rendering target
  1007. * \param a a pointer filled in with the alpha value used to draw on the
  1008. * rendering target; usually `SDL_ALPHA_OPAQUE` (255)
  1009. * \returns 0 on success or a negative error code on failure; call
  1010. * SDL_GetError() for more information.
  1011. *
  1012. * \since This function is available since SDL 3.0.0.
  1013. *
  1014. * \sa SDL_SetRenderDrawColor
  1015. */
  1016. extern DECLSPEC int SDLCALL SDL_GetRenderDrawColor(SDL_Renderer *renderer, Uint8 *r, Uint8 *g, Uint8 *b, Uint8 *a);
  1017. /**
  1018. * Set the blend mode used for drawing operations (Fill and Line).
  1019. *
  1020. * If the blend mode is not supported, the closest supported mode is chosen.
  1021. *
  1022. * \param renderer the rendering context
  1023. * \param blendMode the SDL_BlendMode to use for blending
  1024. * \returns 0 on success or a negative error code on failure; call
  1025. * SDL_GetError() for more information.
  1026. *
  1027. * \since This function is available since SDL 3.0.0.
  1028. *
  1029. * \sa SDL_GetRenderDrawBlendMode
  1030. * \sa SDL_RenderLine
  1031. * \sa SDL_RenderLines
  1032. * \sa SDL_RenderPoint
  1033. * \sa SDL_RenderPoints
  1034. * \sa SDL_RenderRect
  1035. * \sa SDL_RenderRects
  1036. * \sa SDL_RenderFillRect
  1037. * \sa SDL_RenderFillRects
  1038. */
  1039. extern DECLSPEC int SDLCALL SDL_SetRenderDrawBlendMode(SDL_Renderer *renderer, SDL_BlendMode blendMode);
  1040. /**
  1041. * Get the blend mode used for drawing operations.
  1042. *
  1043. * \param renderer the rendering context
  1044. * \param blendMode a pointer filled in with the current SDL_BlendMode
  1045. * \returns 0 on success or a negative error code on failure; call
  1046. * SDL_GetError() for more information.
  1047. *
  1048. * \since This function is available since SDL 3.0.0.
  1049. *
  1050. * \sa SDL_SetRenderDrawBlendMode
  1051. */
  1052. extern DECLSPEC int SDLCALL SDL_GetRenderDrawBlendMode(SDL_Renderer *renderer, SDL_BlendMode *blendMode);
  1053. /**
  1054. * Clear the current rendering target with the drawing color.
  1055. *
  1056. * This function clears the entire rendering target, ignoring the viewport and
  1057. * the clip rectangle.
  1058. *
  1059. * \param renderer the rendering context
  1060. * \returns 0 on success or a negative error code on failure; call
  1061. * SDL_GetError() for more information.
  1062. *
  1063. * \since This function is available since SDL 3.0.0.
  1064. *
  1065. * \sa SDL_SetRenderDrawColor
  1066. */
  1067. extern DECLSPEC int SDLCALL SDL_RenderClear(SDL_Renderer *renderer);
  1068. /**
  1069. * Draw a point on the current rendering target at subpixel precision.
  1070. *
  1071. * \param renderer The renderer which should draw a point.
  1072. * \param x The x coordinate of the point.
  1073. * \param y The y coordinate of the point.
  1074. * \returns 0 on success, or -1 on error
  1075. *
  1076. * \since This function is available since SDL 3.0.0.
  1077. */
  1078. extern DECLSPEC int SDLCALL SDL_RenderPoint(SDL_Renderer *renderer, float x, float y);
  1079. /**
  1080. * Draw multiple points on the current rendering target at subpixel precision.
  1081. *
  1082. * \param renderer The renderer which should draw multiple points.
  1083. * \param points The points to draw
  1084. * \param count The number of points to draw
  1085. * \returns 0 on success or a negative error code on failure; call
  1086. * SDL_GetError() for more information.
  1087. *
  1088. * \since This function is available since SDL 3.0.0.
  1089. */
  1090. extern DECLSPEC int SDLCALL SDL_RenderPoints(SDL_Renderer *renderer, const SDL_FPoint *points, int count);
  1091. /**
  1092. * Draw a line on the current rendering target at subpixel precision.
  1093. *
  1094. * \param renderer The renderer which should draw a line.
  1095. * \param x1 The x coordinate of the start point.
  1096. * \param y1 The y coordinate of the start point.
  1097. * \param x2 The x coordinate of the end point.
  1098. * \param y2 The y coordinate of the end point.
  1099. * \returns 0 on success, or -1 on error
  1100. *
  1101. * \since This function is available since SDL 3.0.0.
  1102. */
  1103. extern DECLSPEC int SDLCALL SDL_RenderLine(SDL_Renderer *renderer, float x1, float y1, float x2, float y2);
  1104. /**
  1105. * Draw a series of connected lines on the current rendering target at
  1106. * subpixel precision.
  1107. *
  1108. * \param renderer The renderer which should draw multiple lines.
  1109. * \param points The points along the lines
  1110. * \param count The number of points, drawing count-1 lines
  1111. * \returns 0 on success or a negative error code on failure; call
  1112. * SDL_GetError() for more information.
  1113. *
  1114. * \since This function is available since SDL 3.0.0.
  1115. */
  1116. extern DECLSPEC int SDLCALL SDL_RenderLines(SDL_Renderer *renderer, const SDL_FPoint *points, int count);
  1117. /**
  1118. * Draw a rectangle on the current rendering target at subpixel precision.
  1119. *
  1120. * \param renderer The renderer which should draw a rectangle.
  1121. * \param rect A pointer to the destination rectangle, or NULL to outline the
  1122. * entire rendering target.
  1123. * \returns 0 on success, or -1 on error
  1124. *
  1125. * \since This function is available since SDL 3.0.0.
  1126. */
  1127. extern DECLSPEC int SDLCALL SDL_RenderRect(SDL_Renderer *renderer, const SDL_FRect *rect);
  1128. /**
  1129. * Draw some number of rectangles on the current rendering target at subpixel
  1130. * precision.
  1131. *
  1132. * \param renderer The renderer which should draw multiple rectangles.
  1133. * \param rects A pointer to an array of destination rectangles.
  1134. * \param count The number of rectangles.
  1135. * \returns 0 on success or a negative error code on failure; call
  1136. * SDL_GetError() for more information.
  1137. *
  1138. * \since This function is available since SDL 3.0.0.
  1139. */
  1140. extern DECLSPEC int SDLCALL SDL_RenderRects(SDL_Renderer *renderer, const SDL_FRect *rects, int count);
  1141. /**
  1142. * Fill a rectangle on the current rendering target with the drawing color at
  1143. * subpixel precision.
  1144. *
  1145. * \param renderer The renderer which should fill a rectangle.
  1146. * \param rect A pointer to the destination rectangle, or NULL for the entire
  1147. * rendering target.
  1148. * \returns 0 on success, or -1 on error
  1149. *
  1150. * \since This function is available since SDL 3.0.0.
  1151. */
  1152. extern DECLSPEC int SDLCALL SDL_RenderFillRect(SDL_Renderer *renderer, const SDL_FRect *rect);
  1153. /**
  1154. * Fill some number of rectangles on the current rendering target with the
  1155. * drawing color at subpixel precision.
  1156. *
  1157. * \param renderer The renderer which should fill multiple rectangles.
  1158. * \param rects A pointer to an array of destination rectangles.
  1159. * \param count The number of rectangles.
  1160. * \returns 0 on success or a negative error code on failure; call
  1161. * SDL_GetError() for more information.
  1162. *
  1163. * \since This function is available since SDL 3.0.0.
  1164. */
  1165. extern DECLSPEC int SDLCALL SDL_RenderFillRects(SDL_Renderer *renderer, const SDL_FRect *rects, int count);
  1166. /**
  1167. * Copy a portion of the texture to the current rendering target at subpixel
  1168. * precision.
  1169. *
  1170. * \param renderer The renderer which should copy parts of a texture.
  1171. * \param texture The source texture.
  1172. * \param srcrect A pointer to the source rectangle, or NULL for the entire
  1173. * texture.
  1174. * \param dstrect A pointer to the destination rectangle, or NULL for the
  1175. * entire rendering target.
  1176. * \returns 0 on success, or -1 on error
  1177. *
  1178. * \since This function is available since SDL 3.0.0.
  1179. */
  1180. extern DECLSPEC int SDLCALL SDL_RenderTexture(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_FRect *srcrect, const SDL_FRect *dstrect);
  1181. /**
  1182. * Copy a portion of the source texture to the current rendering target, with
  1183. * rotation and flipping, at subpixel precision.
  1184. *
  1185. * \param renderer The renderer which should copy parts of a texture.
  1186. * \param texture The source texture.
  1187. * \param srcrect A pointer to the source rectangle, or NULL for the entire
  1188. * texture.
  1189. * \param dstrect A pointer to the destination rectangle, or NULL for the
  1190. * entire rendering target.
  1191. * \param angle An angle in degrees that indicates the rotation that will be
  1192. * applied to dstrect, rotating it in a clockwise direction
  1193. * \param center A pointer to a point indicating the point around which
  1194. * dstrect will be rotated (if NULL, rotation will be done
  1195. * around dstrect.w/2, dstrect.h/2).
  1196. * \param flip An SDL_RendererFlip value stating which flipping actions should
  1197. * be performed on the texture
  1198. * \returns 0 on success or a negative error code on failure; call
  1199. * SDL_GetError() for more information.
  1200. *
  1201. * \since This function is available since SDL 3.0.0.
  1202. */
  1203. extern DECLSPEC int SDLCALL SDL_RenderTextureRotated(SDL_Renderer *renderer, SDL_Texture *texture,
  1204. const SDL_FRect *srcrect, const SDL_FRect *dstrect,
  1205. const double angle, const SDL_FPoint *center,
  1206. const SDL_RendererFlip flip);
  1207. /**
  1208. * Render a list of triangles, optionally using a texture and indices into the
  1209. * vertex array Color and alpha modulation is done per vertex
  1210. * (SDL_SetTextureColorMod and SDL_SetTextureAlphaMod are ignored).
  1211. *
  1212. * \param renderer The rendering context.
  1213. * \param texture (optional) The SDL texture to use.
  1214. * \param vertices Vertices.
  1215. * \param num_vertices Number of vertices.
  1216. * \param indices (optional) An array of integer indices into the 'vertices'
  1217. * array, if NULL all vertices will be rendered in sequential
  1218. * order.
  1219. * \param num_indices Number of indices.
  1220. * \returns 0 on success, or -1 if the operation is not supported
  1221. *
  1222. * \since This function is available since SDL 3.0.0.
  1223. *
  1224. * \sa SDL_RenderGeometryRaw
  1225. * \sa SDL_Vertex
  1226. */
  1227. extern DECLSPEC int SDLCALL SDL_RenderGeometry(SDL_Renderer *renderer,
  1228. SDL_Texture *texture,
  1229. const SDL_Vertex *vertices, int num_vertices,
  1230. const int *indices, int num_indices);
  1231. /**
  1232. * Render a list of triangles, optionally using a texture and indices into the
  1233. * vertex arrays Color and alpha modulation is done per vertex
  1234. * (SDL_SetTextureColorMod and SDL_SetTextureAlphaMod are ignored).
  1235. *
  1236. * \param renderer The rendering context.
  1237. * \param texture (optional) The SDL texture to use.
  1238. * \param xy Vertex positions
  1239. * \param xy_stride Byte size to move from one element to the next element
  1240. * \param color Vertex colors (as SDL_Color)
  1241. * \param color_stride Byte size to move from one element to the next element
  1242. * \param uv Vertex normalized texture coordinates
  1243. * \param uv_stride Byte size to move from one element to the next element
  1244. * \param num_vertices Number of vertices.
  1245. * \param indices (optional) An array of indices into the 'vertices' arrays,
  1246. * if NULL all vertices will be rendered in sequential order.
  1247. * \param num_indices Number of indices.
  1248. * \param size_indices Index size: 1 (byte), 2 (short), 4 (int)
  1249. * \returns 0 on success or a negative error code on failure; call
  1250. * SDL_GetError() for more information.
  1251. *
  1252. * \since This function is available since SDL 3.0.0.
  1253. *
  1254. * \sa SDL_RenderGeometry
  1255. * \sa SDL_Vertex
  1256. */
  1257. extern DECLSPEC int SDLCALL SDL_RenderGeometryRaw(SDL_Renderer *renderer,
  1258. SDL_Texture *texture,
  1259. const float *xy, int xy_stride,
  1260. const SDL_Color *color, int color_stride,
  1261. const float *uv, int uv_stride,
  1262. int num_vertices,
  1263. const void *indices, int num_indices, int size_indices);
  1264. /**
  1265. * Read pixels from the current rendering target to an array of pixels.
  1266. *
  1267. * **WARNING**: This is a very slow operation, and should not be used
  1268. * frequently. If you're using this on the main rendering target, it should be
  1269. * called after rendering and before SDL_RenderPresent().
  1270. *
  1271. * `pitch` specifies the number of bytes between rows in the destination
  1272. * `pixels` data. This allows you to write to a subrectangle or have padded
  1273. * rows in the destination. Generally, `pitch` should equal the number of
  1274. * pixels per row in the `pixels` data times the number of bytes per pixel,
  1275. * but it might contain additional padding (for example, 24bit RGB Windows
  1276. * Bitmap data pads all rows to multiples of 4 bytes).
  1277. *
  1278. * \param renderer the rendering context
  1279. * \param rect an SDL_Rect structure representing the area in pixels relative
  1280. * to the to current viewport, or NULL for the entire viewport
  1281. * \param format an SDL_PixelFormatEnum value of the desired format of the
  1282. * pixel data, or 0 to use the format of the rendering target
  1283. * \param pixels a pointer to the pixel data to copy into
  1284. * \param pitch the pitch of the `pixels` parameter
  1285. * \returns 0 on success or a negative error code on failure; call
  1286. * SDL_GetError() for more information.
  1287. *
  1288. * \since This function is available since SDL 3.0.0.
  1289. */
  1290. extern DECLSPEC int SDLCALL SDL_RenderReadPixels(SDL_Renderer *renderer,
  1291. const SDL_Rect *rect,
  1292. Uint32 format,
  1293. void *pixels, int pitch);
  1294. /**
  1295. * Update the screen with any rendering performed since the previous call.
  1296. *
  1297. * SDL's rendering functions operate on a backbuffer; that is, calling a
  1298. * rendering function such as SDL_RenderLine() does not directly put a line on
  1299. * the screen, but rather updates the backbuffer. As such, you compose your
  1300. * entire scene and *present* the composed backbuffer to the screen as a
  1301. * complete picture.
  1302. *
  1303. * Therefore, when using SDL's rendering API, one does all drawing intended
  1304. * for the frame, and then calls this function once per frame to present the
  1305. * final drawing to the user.
  1306. *
  1307. * The backbuffer should be considered invalidated after each present; do not
  1308. * assume that previous contents will exist between frames. You are strongly
  1309. * encouraged to call SDL_RenderClear() to initialize the backbuffer before
  1310. * starting each new frame's drawing, even if you plan to overwrite every
  1311. * pixel.
  1312. *
  1313. * \param renderer the rendering context
  1314. * \returns 0 on success or a negative error code on failure; call
  1315. * SDL_GetError() for more information.
  1316. *
  1317. * \threadsafety You may only call this function on the main thread.
  1318. *
  1319. * \since This function is available since SDL 3.0.0.
  1320. *
  1321. * \sa SDL_RenderClear
  1322. * \sa SDL_RenderLine
  1323. * \sa SDL_RenderLines
  1324. * \sa SDL_RenderPoint
  1325. * \sa SDL_RenderPoints
  1326. * \sa SDL_RenderRect
  1327. * \sa SDL_RenderRects
  1328. * \sa SDL_RenderFillRect
  1329. * \sa SDL_RenderFillRects
  1330. * \sa SDL_SetRenderDrawBlendMode
  1331. * \sa SDL_SetRenderDrawColor
  1332. */
  1333. extern DECLSPEC int SDLCALL SDL_RenderPresent(SDL_Renderer *renderer);
  1334. /**
  1335. * Destroy the specified texture.
  1336. *
  1337. * Passing NULL or an otherwise invalid texture will set the SDL error message
  1338. * to "Invalid texture".
  1339. *
  1340. * \param texture the texture to destroy
  1341. *
  1342. * \since This function is available since SDL 3.0.0.
  1343. *
  1344. * \sa SDL_CreateTexture
  1345. * \sa SDL_CreateTextureFromSurface
  1346. */
  1347. extern DECLSPEC void SDLCALL SDL_DestroyTexture(SDL_Texture *texture);
  1348. /**
  1349. * Destroy the rendering context for a window and free associated textures.
  1350. *
  1351. * If `renderer` is NULL, this function will return immediately after setting
  1352. * the SDL error message to "Invalid renderer". See SDL_GetError().
  1353. *
  1354. * \param renderer the rendering context
  1355. *
  1356. * \since This function is available since SDL 3.0.0.
  1357. *
  1358. * \sa SDL_CreateRenderer
  1359. */
  1360. extern DECLSPEC void SDLCALL SDL_DestroyRenderer(SDL_Renderer *renderer);
  1361. /**
  1362. * Force the rendering context to flush any pending commands to the underlying
  1363. * rendering API.
  1364. *
  1365. * You do not need to (and in fact, shouldn't) call this function unless you
  1366. * are planning to call into OpenGL/Direct3D/Metal/whatever directly in
  1367. * addition to using an SDL_Renderer.
  1368. *
  1369. * This is for a very-specific case: if you are using SDL's render API, you
  1370. * asked for a specific renderer backend (OpenGL, Direct3D, etc), you set
  1371. * SDL_HINT_RENDER_BATCHING to "1", and you plan to make OpenGL/D3D/whatever
  1372. * calls in addition to SDL render API calls. If all of this applies, you
  1373. * should call SDL_RenderFlush() between calls to SDL's render API and the
  1374. * low-level API you're using in cooperation.
  1375. *
  1376. * In all other cases, you can ignore this function. This is only here to get
  1377. * maximum performance out of a specific situation. In all other cases, SDL
  1378. * will do the right thing, perhaps at a performance loss.
  1379. *
  1380. * This function is first available in SDL 2.0.10, and is not needed in 2.0.9
  1381. * and earlier, as earlier versions did not queue rendering commands at all,
  1382. * instead flushing them to the OS immediately.
  1383. *
  1384. * \param renderer the rendering context
  1385. * \returns 0 on success or a negative error code on failure; call
  1386. * SDL_GetError() for more information.
  1387. *
  1388. * \since This function is available since SDL 3.0.0.
  1389. */
  1390. extern DECLSPEC int SDLCALL SDL_RenderFlush(SDL_Renderer *renderer);
  1391. /**
  1392. * Bind an OpenGL/ES/ES2 texture to the current context.
  1393. *
  1394. * This is for use with OpenGL instructions when rendering OpenGL primitives
  1395. * directly.
  1396. *
  1397. * If not NULL, `texw` and `texh` will be filled with the width and height
  1398. * values suitable for the provided texture. In most cases, both will be 1.0,
  1399. * however, on systems that support the GL_ARB_texture_rectangle extension,
  1400. * these values will actually be the pixel width and height used to create the
  1401. * texture, so this factor needs to be taken into account when providing
  1402. * texture coordinates to OpenGL.
  1403. *
  1404. * You need a renderer to create an SDL_Texture, therefore you can only use
  1405. * this function with an implicit OpenGL context from SDL_CreateRenderer(),
  1406. * not with your own OpenGL context. If you need control over your OpenGL
  1407. * context, you need to write your own texture-loading methods.
  1408. *
  1409. * Also note that SDL may upload RGB textures as BGR (or vice-versa), and
  1410. * re-order the color channels in the shaders phase, so the uploaded texture
  1411. * may have swapped color channels.
  1412. *
  1413. * \param texture the texture to bind to the current OpenGL/ES/ES2 context
  1414. * \param texw a pointer to a float value which will be filled with the
  1415. * texture width or NULL if you don't need that value
  1416. * \param texh a pointer to a float value which will be filled with the
  1417. * texture height or NULL if you don't need that value
  1418. * \returns 0 on success or a negative error code on failure; call
  1419. * SDL_GetError() for more information.
  1420. *
  1421. * \since This function is available since SDL 3.0.0.
  1422. *
  1423. * \sa SDL_GL_MakeCurrent
  1424. * \sa SDL_GL_UnbindTexture
  1425. */
  1426. extern DECLSPEC int SDLCALL SDL_GL_BindTexture(SDL_Texture *texture, float *texw, float *texh);
  1427. /**
  1428. * Unbind an OpenGL/ES/ES2 texture from the current context.
  1429. *
  1430. * See SDL_GL_BindTexture() for examples on how to use these functions
  1431. *
  1432. * \param texture the texture to unbind from the current OpenGL/ES/ES2 context
  1433. * \returns 0 on success or a negative error code on failure; call
  1434. * SDL_GetError() for more information.
  1435. *
  1436. * \since This function is available since SDL 3.0.0.
  1437. *
  1438. * \sa SDL_GL_BindTexture
  1439. * \sa SDL_GL_MakeCurrent
  1440. */
  1441. extern DECLSPEC int SDLCALL SDL_GL_UnbindTexture(SDL_Texture *texture);
  1442. /**
  1443. * Get the CAMetalLayer associated with the given Metal renderer.
  1444. *
  1445. * This function returns `void *`, so SDL doesn't have to include Metal's
  1446. * headers, but it can be safely cast to a `CAMetalLayer *`.
  1447. *
  1448. * \param renderer The renderer to query
  1449. * \returns a `CAMetalLayer *` on success, or NULL if the renderer isn't a
  1450. * Metal renderer
  1451. *
  1452. * \since This function is available since SDL 3.0.0.
  1453. *
  1454. * \sa SDL_GetRenderMetalCommandEncoder
  1455. */
  1456. extern DECLSPEC void *SDLCALL SDL_GetRenderMetalLayer(SDL_Renderer *renderer);
  1457. /**
  1458. * Get the Metal command encoder for the current frame
  1459. *
  1460. * This function returns `void *`, so SDL doesn't have to include Metal's
  1461. * headers, but it can be safely cast to an `id<MTLRenderCommandEncoder>`.
  1462. *
  1463. * Note that as of SDL 2.0.18, this will return NULL if Metal refuses to give
  1464. * SDL a drawable to render to, which might happen if the window is
  1465. * hidden/minimized/offscreen. This doesn't apply to command encoders for
  1466. * render targets, just the window's backbuffer. Check your return values!
  1467. *
  1468. * \param renderer The renderer to query
  1469. * \returns an `id<MTLRenderCommandEncoder>` on success, or NULL if the
  1470. * renderer isn't a Metal renderer or there was an error.
  1471. *
  1472. * \since This function is available since SDL 3.0.0.
  1473. *
  1474. * \sa SDL_GetRenderMetalLayer
  1475. */
  1476. extern DECLSPEC void *SDLCALL SDL_GetRenderMetalCommandEncoder(SDL_Renderer *renderer);
  1477. /**
  1478. * Toggle VSync of the given renderer.
  1479. *
  1480. * \param renderer The renderer to toggle
  1481. * \param vsync 1 for on, 0 for off. All other values are reserved
  1482. * \returns 0 on success or a negative error code on failure; call
  1483. * SDL_GetError() for more information.
  1484. *
  1485. * \since This function is available since SDL 3.0.0.
  1486. */
  1487. extern DECLSPEC int SDLCALL SDL_SetRenderVSync(SDL_Renderer *renderer, int vsync);
  1488. /**
  1489. * Get VSync of the given renderer.
  1490. *
  1491. * \param renderer The renderer to toggle
  1492. * \param vsync an int filled with 1 for on, 0 for off. All other values are
  1493. * reserved
  1494. * \returns 0 on success or a negative error code on failure; call
  1495. * SDL_GetError() for more information.
  1496. *
  1497. * \since This function is available since SDL 3.0.0.
  1498. */
  1499. extern DECLSPEC int SDLCALL SDL_GetRenderVSync(SDL_Renderer *renderer, int *vsync);
  1500. /* Ends C function definitions when using C++ */
  1501. #ifdef __cplusplus
  1502. }
  1503. #endif
  1504. #include <SDL3/SDL_close_code.h>
  1505. #endif /* SDL_render_h_ */