SDL_render.h 62 KB

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