SDL_render.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609
  1. /*
  2. SDL - Simple DirectMedia Layer
  3. Copyright (C) 1997-2011 Sam Lantinga
  4. This library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. This library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with this library; if not, write to the Free Software
  14. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  15. Sam Lantinga
  16. [email protected]
  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 rotation 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. #ifndef _SDL_render_h
  41. #define _SDL_render_h
  42. #include "SDL_stdinc.h"
  43. #include "SDL_rect.h"
  44. #include "SDL_video.h"
  45. #include "begin_code.h"
  46. /* Set up for C function definitions, even when using C++ */
  47. #ifdef __cplusplus
  48. /* *INDENT-OFF* */
  49. extern "C" {
  50. /* *INDENT-ON* */
  51. #endif
  52. /**
  53. * \brief Flags used when creating a rendering context
  54. */
  55. typedef enum
  56. {
  57. SDL_RENDERER_ACCELERATED = 0x00000001, /**< The renderer uses hardware
  58. acceleration */
  59. SDL_RENDERER_PRESENTVSYNC = 0x00000002 /**< Present is synchronized
  60. with the refresh rate */
  61. } SDL_RendererFlags;
  62. /**
  63. * \brief Information on the capabilities of a render driver or context.
  64. */
  65. typedef struct SDL_RendererInfo
  66. {
  67. const char *name; /**< The name of the renderer */
  68. Uint32 flags; /**< Supported ::SDL_RendererFlags */
  69. Uint32 num_texture_formats; /**< The number of available texture formats */
  70. Uint32 texture_formats[16]; /**< The available texture formats */
  71. int max_texture_width; /**< The maximimum texture width */
  72. int max_texture_height; /**< The maximimum texture height */
  73. } SDL_RendererInfo;
  74. /**
  75. * \brief The access pattern allowed for a texture.
  76. */
  77. typedef enum
  78. {
  79. SDL_TEXTUREACCESS_STATIC, /**< Changes rarely, not lockable */
  80. SDL_TEXTUREACCESS_STREAMING /**< Changes frequently, lockable */
  81. } SDL_TextureAccess;
  82. /**
  83. * \brief The texture channel modulation used in SDL_RenderCopy().
  84. */
  85. typedef enum
  86. {
  87. SDL_TEXTUREMODULATE_NONE = 0x00000000, /**< No modulation */
  88. SDL_TEXTUREMODULATE_COLOR = 0x00000001, /**< srcC = srcC * color */
  89. SDL_TEXTUREMODULATE_ALPHA = 0x00000002 /**< srcA = srcA * alpha */
  90. } SDL_TextureModulate;
  91. /**
  92. * \brief A structure representing rendering state
  93. */
  94. struct SDL_Renderer;
  95. typedef struct SDL_Renderer SDL_Renderer;
  96. /**
  97. * \brief An efficient driver-specific representation of pixel data
  98. */
  99. struct SDL_Texture;
  100. typedef struct SDL_Texture SDL_Texture;
  101. /* Function prototypes */
  102. /**
  103. * \brief Get the number of 2D rendering drivers available for the current
  104. * display.
  105. *
  106. * A render driver is a set of code that handles rendering and texture
  107. * management on a particular display. Normally there is only one, but
  108. * some drivers may have several available with different capabilities.
  109. *
  110. * \sa SDL_GetRenderDriverInfo()
  111. * \sa SDL_CreateRenderer()
  112. */
  113. extern DECLSPEC int SDLCALL SDL_GetNumRenderDrivers(void);
  114. /**
  115. * \brief Get information about a specific 2D rendering driver for the current
  116. * display.
  117. *
  118. * \param index The index of the driver to query information about.
  119. * \param info A pointer to an SDL_RendererInfo struct to be filled with
  120. * information on the rendering driver.
  121. *
  122. * \return 0 on success, -1 if the index was out of range.
  123. *
  124. * \sa SDL_CreateRenderer()
  125. */
  126. extern DECLSPEC int SDLCALL SDL_GetRenderDriverInfo(int index,
  127. SDL_RendererInfo * info);
  128. /**
  129. * \brief Create a 2D rendering context for a window.
  130. *
  131. * \param window The window where rendering is displayed.
  132. * \param index The index of the rendering driver to initialize, or -1 to
  133. * initialize the first one supporting the requested flags.
  134. * \param flags ::SDL_RendererFlags.
  135. *
  136. * \return A valid rendering context or NULL if there was an error.
  137. *
  138. * \sa SDL_CreateSoftwareRenderer()
  139. * \sa SDL_GetRendererInfo()
  140. * \sa SDL_DestroyRenderer()
  141. */
  142. extern DECLSPEC SDL_Renderer * SDLCALL SDL_CreateRenderer(SDL_Window * window,
  143. int index, Uint32 flags);
  144. /**
  145. * \brief Create a 2D software rendering context for a surface.
  146. *
  147. * \param surface The surface where rendering is done.
  148. *
  149. * \return A valid rendering context or NULL if there was an error.
  150. *
  151. * \sa SDL_CreateRenderer()
  152. * \sa SDL_DestroyRenderer()
  153. */
  154. extern DECLSPEC SDL_Renderer * SDLCALL SDL_CreateSoftwareRenderer(SDL_Surface * surface);
  155. /**
  156. * \brief Get information about a rendering context.
  157. */
  158. extern DECLSPEC int SDLCALL SDL_GetRendererInfo(SDL_Renderer * renderer,
  159. SDL_RendererInfo * info);
  160. /**
  161. * \brief Create a texture for a rendering context.
  162. *
  163. * \param format The format of the texture.
  164. * \param access One of the enumerated values in ::SDL_TextureAccess.
  165. * \param w The width of the texture in pixels.
  166. * \param h The height of the texture in pixels.
  167. *
  168. * \return The created texture is returned, or 0 if no rendering context was
  169. * active, the format was unsupported, or the width or height were out
  170. * of range.
  171. *
  172. * \sa SDL_QueryTexture()
  173. * \sa SDL_UpdateTexture()
  174. * \sa SDL_DestroyTexture()
  175. */
  176. extern DECLSPEC SDL_Texture * SDLCALL SDL_CreateTexture(SDL_Renderer * renderer, Uint32 format,
  177. int access, int w,
  178. int h);
  179. /**
  180. * \brief Create a texture from an existing surface.
  181. *
  182. * \param surface The surface containing pixel data used to fill the texture.
  183. *
  184. * \return The created texture is returned, or 0 on error.
  185. *
  186. * \note The surface is not modified or freed by this function.
  187. *
  188. * \sa SDL_QueryTexture()
  189. * \sa SDL_DestroyTexture()
  190. */
  191. extern DECLSPEC SDL_Texture * SDLCALL SDL_CreateTextureFromSurface(SDL_Renderer * renderer, SDL_Surface * surface);
  192. /**
  193. * \brief Query the attributes of a texture
  194. *
  195. * \param texture A texture to be queried.
  196. * \param format A pointer filled in with the raw format of the texture. The
  197. * actual format may differ, but pixel transfers will use this
  198. * format.
  199. * \param access A pointer filled in with the actual access to the texture.
  200. * \param w A pointer filled in with the width of the texture in pixels.
  201. * \param h A pointer filled in with the height of the texture in pixels.
  202. *
  203. * \return 0 on success, or -1 if the texture is not valid.
  204. */
  205. extern DECLSPEC int SDLCALL SDL_QueryTexture(SDL_Texture * texture,
  206. Uint32 * format, int *access,
  207. int *w, int *h);
  208. /**
  209. * \brief Set an additional color value used in render copy operations.
  210. *
  211. * \param texture The texture to update.
  212. * \param r The red color value multiplied into copy operations.
  213. * \param g The green color value multiplied into copy operations.
  214. * \param b The blue color value multiplied into copy operations.
  215. *
  216. * \return 0 on success, or -1 if the texture is not valid or color modulation
  217. * is not supported.
  218. *
  219. * \sa SDL_GetTextureColorMod()
  220. */
  221. extern DECLSPEC int SDLCALL SDL_SetTextureColorMod(SDL_Texture * texture,
  222. Uint8 r, Uint8 g, Uint8 b);
  223. /**
  224. * \brief Get the additional color value used in render copy operations.
  225. *
  226. * \param texture The texture to query.
  227. * \param r A pointer filled in with the current red color value.
  228. * \param g A pointer filled in with the current green color value.
  229. * \param b A pointer filled in with the current blue color value.
  230. *
  231. * \return 0 on success, or -1 if the texture is not valid.
  232. *
  233. * \sa SDL_SetTextureColorMod()
  234. */
  235. extern DECLSPEC int SDLCALL SDL_GetTextureColorMod(SDL_Texture * texture,
  236. Uint8 * r, Uint8 * g,
  237. Uint8 * b);
  238. /**
  239. * \brief Set an additional alpha value used in render copy operations.
  240. *
  241. * \param texture The texture to update.
  242. * \param alpha The alpha value multiplied into copy operations.
  243. *
  244. * \return 0 on success, or -1 if the texture is not valid or alpha modulation
  245. * is not supported.
  246. *
  247. * \sa SDL_GetTextureAlphaMod()
  248. */
  249. extern DECLSPEC int SDLCALL SDL_SetTextureAlphaMod(SDL_Texture * texture,
  250. Uint8 alpha);
  251. /**
  252. * \brief Get the additional alpha value used in render copy operations.
  253. *
  254. * \param texture The texture to query.
  255. * \param alpha A pointer filled in with the current alpha value.
  256. *
  257. * \return 0 on success, or -1 if the texture is not valid.
  258. *
  259. * \sa SDL_SetTextureAlphaMod()
  260. */
  261. extern DECLSPEC int SDLCALL SDL_GetTextureAlphaMod(SDL_Texture * texture,
  262. Uint8 * alpha);
  263. /**
  264. * \brief Set the blend mode used for texture copy operations.
  265. *
  266. * \param texture The texture to update.
  267. * \param blendMode ::SDL_BlendMode to use for texture blending.
  268. *
  269. * \return 0 on success, or -1 if the texture is not valid or the blend mode is
  270. * not supported.
  271. *
  272. * \note If the blend mode is not supported, the closest supported mode is
  273. * chosen.
  274. *
  275. * \sa SDL_GetTextureBlendMode()
  276. */
  277. extern DECLSPEC int SDLCALL SDL_SetTextureBlendMode(SDL_Texture * texture,
  278. SDL_BlendMode blendMode);
  279. /**
  280. * \brief Get the blend mode used for texture copy operations.
  281. *
  282. * \param texture The texture to query.
  283. * \param blendMode A pointer filled in with the current blend mode.
  284. *
  285. * \return 0 on success, or -1 if the texture is not valid.
  286. *
  287. * \sa SDL_SetTextureBlendMode()
  288. */
  289. extern DECLSPEC int SDLCALL SDL_GetTextureBlendMode(SDL_Texture * texture,
  290. SDL_BlendMode *blendMode);
  291. /**
  292. * \brief Update the given texture rectangle with new pixel data.
  293. *
  294. * \param texture The texture to update
  295. * \param rect A pointer to the rectangle of pixels to update, or NULL to
  296. * update the entire texture.
  297. * \param pixels The raw pixel data.
  298. * \param pitch The number of bytes between rows of pixel data.
  299. *
  300. * \return 0 on success, or -1 if the texture is not valid.
  301. *
  302. * \note This is a fairly slow function.
  303. */
  304. extern DECLSPEC int SDLCALL SDL_UpdateTexture(SDL_Texture * texture,
  305. const SDL_Rect * rect,
  306. const void *pixels, int pitch);
  307. /**
  308. * \brief Lock a portion of the texture for pixel access.
  309. *
  310. * \param texture The texture to lock for access, which was created with
  311. * ::SDL_TEXTUREACCESS_STREAMING.
  312. * \param rect A pointer to the rectangle to lock for access. If the rect
  313. * is NULL, the entire texture will be locked.
  314. * \param pixels This is filled in with a pointer to the locked pixels,
  315. * appropriately offset by the locked area.
  316. * \param pitch This is filled in with the pitch of the locked pixels.
  317. *
  318. * \return 0 on success, or -1 if the texture is not valid or was not created with ::SDL_TEXTUREACCESS_STREAMING.
  319. *
  320. * \sa SDL_UnlockTexture()
  321. */
  322. extern DECLSPEC int SDLCALL SDL_LockTexture(SDL_Texture * texture,
  323. const SDL_Rect * rect,
  324. void **pixels, int *pitch);
  325. /**
  326. * \brief Unlock a texture, uploading the changes to video memory, if needed.
  327. *
  328. * \sa SDL_LockTexture()
  329. */
  330. extern DECLSPEC void SDLCALL SDL_UnlockTexture(SDL_Texture * texture);
  331. /**
  332. * \brief Set the drawing area for rendering on the current target.
  333. *
  334. * \param rect The rectangle representing the drawing area, or NULL to set the viewport to the entire target.
  335. *
  336. * The x,y of the viewport rect represents the origin for rendering.
  337. *
  338. * \note When the window is resized, the current viewport is automatically
  339. * centered within the new window size.
  340. */
  341. extern DECLSPEC int SDLCALL SDL_RenderSetViewport(SDL_Renderer * renderer,
  342. const SDL_Rect * rect);
  343. /**
  344. * \brief Get the drawing area for the current target.
  345. */
  346. extern DECLSPEC void SDLCALL SDL_RenderGetViewport(SDL_Renderer * renderer,
  347. SDL_Rect * rect);
  348. /**
  349. * \brief Set the color used for drawing operations (Fill and Line).
  350. *
  351. * \param r The red value used to draw on the rendering target.
  352. * \param g The green value used to draw on the rendering target.
  353. * \param b The blue value used to draw on the rendering target.
  354. * \param a The alpha value used to draw on the rendering target, usually
  355. * ::SDL_ALPHA_OPAQUE (255).
  356. *
  357. * \return 0 on success, or -1 on error
  358. */
  359. extern DECLSPEC int SDL_SetRenderDrawColor(SDL_Renderer * renderer,
  360. Uint8 r, Uint8 g, Uint8 b,
  361. Uint8 a);
  362. /**
  363. * \brief Get the color used for drawing operations (Fill and Line).
  364. *
  365. * \param r A pointer to the red value used to draw on the rendering target.
  366. * \param g A pointer to the green value used to draw on the rendering target.
  367. * \param b A pointer to the blue value used to draw on the rendering target.
  368. * \param a A pointer to the alpha value used to draw on the rendering target,
  369. * usually ::SDL_ALPHA_OPAQUE (255).
  370. *
  371. * \return 0 on success, or -1 on error
  372. */
  373. extern DECLSPEC int SDL_GetRenderDrawColor(SDL_Renderer * renderer,
  374. Uint8 * r, Uint8 * g, Uint8 * b,
  375. Uint8 * a);
  376. /**
  377. * \brief Set the blend mode used for drawing operations (Fill and Line).
  378. *
  379. * \param blendMode ::SDL_BlendMode to use for blending.
  380. *
  381. * \return 0 on success, or -1 on error
  382. *
  383. * \note If the blend mode is not supported, the closest supported mode is
  384. * chosen.
  385. *
  386. * \sa SDL_GetRenderDrawBlendMode()
  387. */
  388. extern DECLSPEC int SDLCALL SDL_SetRenderDrawBlendMode(SDL_Renderer * renderer,
  389. SDL_BlendMode blendMode);
  390. /**
  391. * \brief Get the blend mode used for drawing operations.
  392. *
  393. * \param blendMode A pointer filled in with the current blend mode.
  394. *
  395. * \return 0 on success, or -1 on error
  396. *
  397. * \sa SDL_SetRenderDrawBlendMode()
  398. */
  399. extern DECLSPEC int SDLCALL SDL_GetRenderDrawBlendMode(SDL_Renderer * renderer,
  400. SDL_BlendMode *blendMode);
  401. /**
  402. * \brief Clear the current rendering target with the drawing color
  403. *
  404. * This function clears the entire rendering target, ignoring the viewport.
  405. */
  406. extern DECLSPEC int SDLCALL SDL_RenderClear(SDL_Renderer * renderer);
  407. /**
  408. * \brief Draw a point on the current rendering target.
  409. *
  410. * \param x The x coordinate of the point.
  411. * \param y The y coordinate of the point.
  412. *
  413. * \return 0 on success, or -1 on error
  414. */
  415. extern DECLSPEC int SDLCALL SDL_RenderDrawPoint(SDL_Renderer * renderer,
  416. int x, int y);
  417. /**
  418. * \brief Draw multiple points on the current rendering target.
  419. *
  420. * \param points The points to draw
  421. * \param count The number of points to draw
  422. *
  423. * \return 0 on success, or -1 on error
  424. */
  425. extern DECLSPEC int SDLCALL SDL_RenderDrawPoints(SDL_Renderer * renderer,
  426. const SDL_Point * points,
  427. int count);
  428. /**
  429. * \brief Draw a line on the current rendering target.
  430. *
  431. * \param x1 The x coordinate of the start point.
  432. * \param y1 The y coordinate of the start point.
  433. * \param x2 The x coordinate of the end point.
  434. * \param y2 The y coordinate of the end point.
  435. *
  436. * \return 0 on success, or -1 on error
  437. */
  438. extern DECLSPEC int SDLCALL SDL_RenderDrawLine(SDL_Renderer * renderer,
  439. int x1, int y1, int x2, int y2);
  440. /**
  441. * \brief Draw a series of connected lines on the current rendering target.
  442. *
  443. * \param points The points along the lines
  444. * \param count The number of points, drawing count-1 lines
  445. *
  446. * \return 0 on success, or -1 on error
  447. */
  448. extern DECLSPEC int SDLCALL SDL_RenderDrawLines(SDL_Renderer * renderer,
  449. const SDL_Point * points,
  450. int count);
  451. /**
  452. * \brief Draw a rectangle on the current rendering target.
  453. *
  454. * \param rect A pointer to the destination rectangle, or NULL to outline the entire rendering target.
  455. *
  456. * \return 0 on success, or -1 on error
  457. */
  458. extern DECLSPEC int SDLCALL SDL_RenderDrawRect(SDL_Renderer * renderer,
  459. const SDL_Rect * rect);
  460. /**
  461. * \brief Draw some number of rectangles on the current rendering target.
  462. *
  463. * \param rects A pointer to an array of destination rectangles.
  464. * \param count The number of rectangles.
  465. *
  466. * \return 0 on success, or -1 on error
  467. */
  468. extern DECLSPEC int SDLCALL SDL_RenderDrawRects(SDL_Renderer * renderer,
  469. const SDL_Rect * rects,
  470. int count);
  471. /**
  472. * \brief Fill a rectangle on the current rendering target with the drawing color.
  473. *
  474. * \param rect A pointer to the destination rectangle, or NULL for the entire
  475. * rendering target.
  476. *
  477. * \return 0 on success, or -1 on error
  478. */
  479. extern DECLSPEC int SDLCALL SDL_RenderFillRect(SDL_Renderer * renderer,
  480. const SDL_Rect * rect);
  481. /**
  482. * \brief Fill some number of rectangles on the current rendering target with the drawing color.
  483. *
  484. * \param rects A pointer to an array of destination rectangles.
  485. * \param count The number of rectangles.
  486. *
  487. * \return 0 on success, or -1 on error
  488. */
  489. extern DECLSPEC int SDLCALL SDL_RenderFillRects(SDL_Renderer * renderer,
  490. const SDL_Rect * rect,
  491. int count);
  492. /**
  493. * \brief Copy a portion of the texture to the current rendering target.
  494. *
  495. * \param texture The source texture.
  496. * \param srcrect A pointer to the source rectangle, or NULL for the entire
  497. * texture.
  498. * \param dstrect A pointer to the destination rectangle, or NULL for the
  499. * entire rendering target.
  500. *
  501. * \return 0 on success, or -1 on error
  502. */
  503. extern DECLSPEC int SDLCALL SDL_RenderCopy(SDL_Renderer * renderer,
  504. SDL_Texture * texture,
  505. const SDL_Rect * srcrect,
  506. const SDL_Rect * dstrect);
  507. /**
  508. * \brief Read pixels from the current rendering target.
  509. *
  510. * \param rect A pointer to the rectangle to read, or NULL for the entire
  511. * render target.
  512. * \param format The desired format of the pixel data, or 0 to use the format
  513. * of the rendering target
  514. * \param pixels A pointer to be filled in with the pixel data
  515. * \param pitch The pitch of the pixels parameter.
  516. *
  517. * \return 0 on success, or -1 if pixel reading is not supported.
  518. *
  519. * \warning This is a very slow operation, and should not be used frequently.
  520. */
  521. extern DECLSPEC int SDLCALL SDL_RenderReadPixels(SDL_Renderer * renderer,
  522. const SDL_Rect * rect,
  523. Uint32 format,
  524. void *pixels, int pitch);
  525. /**
  526. * \brief Update the screen with rendering performed.
  527. */
  528. extern DECLSPEC void SDLCALL SDL_RenderPresent(SDL_Renderer * renderer);
  529. /**
  530. * \brief Destroy the specified texture.
  531. *
  532. * \sa SDL_CreateTexture()
  533. * \sa SDL_CreateTextureFromSurface()
  534. */
  535. extern DECLSPEC void SDLCALL SDL_DestroyTexture(SDL_Texture * texture);
  536. /**
  537. * \brief Destroy the rendering context for a window and free associated
  538. * textures.
  539. *
  540. * \sa SDL_CreateRenderer()
  541. */
  542. extern DECLSPEC void SDLCALL SDL_DestroyRenderer(SDL_Renderer * renderer);
  543. /* Ends C function definitions when using C++ */
  544. #ifdef __cplusplus
  545. /* *INDENT-OFF* */
  546. }
  547. /* *INDENT-ON* */
  548. #endif
  549. #include "close_code.h"
  550. #endif /* _SDL_render_h */
  551. /* vi: set ts=4 sw=4 expandtab: */