SDL_render.h 61 KB

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