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