SDL_render.h 62 KB

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