SDL_render.h 60 KB

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