SDL_render.h 62 KB

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