2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997-2011 Sam Lantinga
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26 * Header file for SDL 2D rendering functions.
28 * This API supports the following features:
29 * * single pixel points
30 * * single pixel lines
34 * The primitives may be drawn in opaque, blended, or additive modes.
36 * The texture images may be drawn in opaque, blended, or additive modes.
37 * They can have an additional color tint or alpha modulation applied to
38 * them, and may also be stretched with linear interpolation.
40 * This API is designed to accelerate simple 2D operations. You may
41 * want more functionality such as rotation and particle effects and
42 * in that case you should use SDL's OpenGL/Direct3D support or one
43 * of the many good 3D engines.
49 #include "SDL_stdinc.h"
51 #include "SDL_video.h"
53 #include "begin_code.h"
54 /* Set up for C function definitions, even when using C++ */
62 * \brief Flags used when creating a rendering context
66 SDL_RENDERER_SOFTWARE = 0x00000001, /**< The renderer is a software fallback */
67 SDL_RENDERER_ACCELERATED = 0x00000002, /**< The renderer uses hardware
69 SDL_RENDERER_PRESENTVSYNC = 0x00000004 /**< Present is synchronized
70 with the refresh rate */
74 * \brief Information on the capabilities of a render driver or context.
76 typedef struct SDL_RendererInfo
78 const char *name; /**< The name of the renderer */
79 Uint32 flags; /**< Supported ::SDL_RendererFlags */
80 Uint32 num_texture_formats; /**< The number of available texture formats */
81 Uint32 texture_formats[16]; /**< The available texture formats */
82 int max_texture_width; /**< The maximimum texture width */
83 int max_texture_height; /**< The maximimum texture height */
87 * \brief The access pattern allowed for a texture.
91 SDL_TEXTUREACCESS_STATIC, /**< Changes rarely, not lockable */
92 SDL_TEXTUREACCESS_STREAMING /**< Changes frequently, lockable */
96 * \brief The texture channel modulation used in SDL_RenderCopy().
100 SDL_TEXTUREMODULATE_NONE = 0x00000000, /**< No modulation */
101 SDL_TEXTUREMODULATE_COLOR = 0x00000001, /**< srcC = srcC * color */
102 SDL_TEXTUREMODULATE_ALPHA = 0x00000002 /**< srcA = srcA * alpha */
103 } SDL_TextureModulate;
106 * \brief A structure representing rendering state
109 typedef struct SDL_Renderer SDL_Renderer;
112 * \brief An efficient driver-specific representation of pixel data
115 typedef struct SDL_Texture SDL_Texture;
118 /* Function prototypes */
121 * \brief Get the number of 2D rendering drivers available for the current
124 * A render driver is a set of code that handles rendering and texture
125 * management on a particular display. Normally there is only one, but
126 * some drivers may have several available with different capabilities.
128 * \sa SDL_GetRenderDriverInfo()
129 * \sa SDL_CreateRenderer()
131 extern DECLSPEC int SDLCALL SDL_GetNumRenderDrivers(void);
134 * \brief Get information about a specific 2D rendering driver for the current
137 * \param index The index of the driver to query information about.
138 * \param info A pointer to an SDL_RendererInfo struct to be filled with
139 * information on the rendering driver.
141 * \return 0 on success, -1 if the index was out of range.
143 * \sa SDL_CreateRenderer()
145 extern DECLSPEC int SDLCALL SDL_GetRenderDriverInfo(int index,
146 SDL_RendererInfo * info);
149 * \brief Create a 2D rendering context for a window.
151 * \param window The window where rendering is displayed.
152 * \param index The index of the rendering driver to initialize, or -1 to
153 * initialize the first one supporting the requested flags.
154 * \param flags ::SDL_RendererFlags.
156 * \return A valid rendering context or NULL if there was an error.
158 * \sa SDL_CreateSoftwareRenderer()
159 * \sa SDL_GetRendererInfo()
160 * \sa SDL_DestroyRenderer()
162 extern DECLSPEC SDL_Renderer * SDLCALL SDL_CreateRenderer(SDL_Window * window,
163 int index, Uint32 flags);
166 * \brief Create a 2D software rendering context for a surface.
168 * \param surface The surface where rendering is done.
170 * \return A valid rendering context or NULL if there was an error.
172 * \sa SDL_CreateRenderer()
173 * \sa SDL_DestroyRenderer()
175 extern DECLSPEC SDL_Renderer * SDLCALL SDL_CreateSoftwareRenderer(SDL_Surface * surface);
178 * \brief Get the renderer associated with a window.
180 extern DECLSPEC SDL_Renderer * SDLCALL SDL_GetRenderer(SDL_Window * window);
183 * \brief Get information about a rendering context.
185 extern DECLSPEC int SDLCALL SDL_GetRendererInfo(SDL_Renderer * renderer,
186 SDL_RendererInfo * info);
189 * \brief Create a texture for a rendering context.
191 * \param format The format of the texture.
192 * \param access One of the enumerated values in ::SDL_TextureAccess.
193 * \param w The width of the texture in pixels.
194 * \param h The height of the texture in pixels.
196 * \return The created texture is returned, or 0 if no rendering context was
197 * active, the format was unsupported, or the width or height were out
200 * \sa SDL_QueryTexture()
201 * \sa SDL_UpdateTexture()
202 * \sa SDL_DestroyTexture()
204 extern DECLSPEC SDL_Texture * SDLCALL SDL_CreateTexture(SDL_Renderer * renderer,
210 * \brief Create a texture from an existing surface.
212 * \param surface The surface containing pixel data used to fill the texture.
214 * \return The created texture is returned, or 0 on error.
216 * \note The surface is not modified or freed by this function.
218 * \sa SDL_QueryTexture()
219 * \sa SDL_DestroyTexture()
221 extern DECLSPEC SDL_Texture * SDLCALL SDL_CreateTextureFromSurface(SDL_Renderer * renderer, SDL_Surface * surface);
224 * \brief Query the attributes of a texture
226 * \param texture A texture to be queried.
227 * \param format A pointer filled in with the raw format of the texture. The
228 * actual format may differ, but pixel transfers will use this
230 * \param access A pointer filled in with the actual access to the texture.
231 * \param w A pointer filled in with the width of the texture in pixels.
232 * \param h A pointer filled in with the height of the texture in pixels.
234 * \return 0 on success, or -1 if the texture is not valid.
236 extern DECLSPEC int SDLCALL SDL_QueryTexture(SDL_Texture * texture,
237 Uint32 * format, int *access,
241 * \brief Set an additional color value used in render copy operations.
243 * \param texture The texture to update.
244 * \param r The red color value multiplied into copy operations.
245 * \param g The green color value multiplied into copy operations.
246 * \param b The blue color value multiplied into copy operations.
248 * \return 0 on success, or -1 if the texture is not valid or color modulation
251 * \sa SDL_GetTextureColorMod()
253 extern DECLSPEC int SDLCALL SDL_SetTextureColorMod(SDL_Texture * texture,
254 Uint8 r, Uint8 g, Uint8 b);
258 * \brief Get the additional color value used in render copy operations.
260 * \param texture The texture to query.
261 * \param r A pointer filled in with the current red color value.
262 * \param g A pointer filled in with the current green color value.
263 * \param b A pointer filled in with the current blue color value.
265 * \return 0 on success, or -1 if the texture is not valid.
267 * \sa SDL_SetTextureColorMod()
269 extern DECLSPEC int SDLCALL SDL_GetTextureColorMod(SDL_Texture * texture,
270 Uint8 * r, Uint8 * g,
274 * \brief Set an additional alpha value used in render copy operations.
276 * \param texture The texture to update.
277 * \param alpha The alpha value multiplied into copy operations.
279 * \return 0 on success, or -1 if the texture is not valid or alpha modulation
282 * \sa SDL_GetTextureAlphaMod()
284 extern DECLSPEC int SDLCALL SDL_SetTextureAlphaMod(SDL_Texture * texture,
288 * \brief Get the additional alpha value used in render copy operations.
290 * \param texture The texture to query.
291 * \param alpha A pointer filled in with the current alpha value.
293 * \return 0 on success, or -1 if the texture is not valid.
295 * \sa SDL_SetTextureAlphaMod()
297 extern DECLSPEC int SDLCALL SDL_GetTextureAlphaMod(SDL_Texture * texture,
301 * \brief Set the blend mode used for texture copy operations.
303 * \param texture The texture to update.
304 * \param blendMode ::SDL_BlendMode to use for texture blending.
306 * \return 0 on success, or -1 if the texture is not valid or the blend mode is
309 * \note If the blend mode is not supported, the closest supported mode is
312 * \sa SDL_GetTextureBlendMode()
314 extern DECLSPEC int SDLCALL SDL_SetTextureBlendMode(SDL_Texture * texture,
315 SDL_BlendMode blendMode);
318 * \brief Get the blend mode used for texture copy operations.
320 * \param texture The texture to query.
321 * \param blendMode A pointer filled in with the current blend mode.
323 * \return 0 on success, or -1 if the texture is not valid.
325 * \sa SDL_SetTextureBlendMode()
327 extern DECLSPEC int SDLCALL SDL_GetTextureBlendMode(SDL_Texture * texture,
328 SDL_BlendMode *blendMode);
331 * \brief Update the given texture rectangle with new pixel data.
333 * \param texture The texture to update
334 * \param rect A pointer to the rectangle of pixels to update, or NULL to
335 * update the entire texture.
336 * \param pixels The raw pixel data.
337 * \param pitch The number of bytes between rows of pixel data.
339 * \return 0 on success, or -1 if the texture is not valid.
341 * \note This is a fairly slow function.
343 extern DECLSPEC int SDLCALL SDL_UpdateTexture(SDL_Texture * texture,
344 const SDL_Rect * rect,
345 const void *pixels, int pitch);
348 * \brief Lock a portion of the texture for pixel access.
350 * \param texture The texture to lock for access, which was created with
351 * ::SDL_TEXTUREACCESS_STREAMING.
352 * \param rect A pointer to the rectangle to lock for access. If the rect
353 * is NULL, the entire texture will be locked.
354 * \param pixels This is filled in with a pointer to the locked pixels,
355 * appropriately offset by the locked area.
356 * \param pitch This is filled in with the pitch of the locked pixels.
358 * \return 0 on success, or -1 if the texture is not valid or was not created with ::SDL_TEXTUREACCESS_STREAMING.
360 * \sa SDL_UnlockTexture()
362 extern DECLSPEC int SDLCALL SDL_LockTexture(SDL_Texture * texture,
363 const SDL_Rect * rect,
364 void **pixels, int *pitch);
367 * \brief Unlock a texture, uploading the changes to video memory, if needed.
369 * \sa SDL_LockTexture()
371 extern DECLSPEC void SDLCALL SDL_UnlockTexture(SDL_Texture * texture);
374 * \brief Set the drawing area for rendering on the current target.
376 * \param rect The rectangle representing the drawing area, or NULL to set the viewport to the entire target.
378 * The x,y of the viewport rect represents the origin for rendering.
380 * \note When the window is resized, the current viewport is automatically
381 * centered within the new window size.
383 extern DECLSPEC int SDLCALL SDL_RenderSetViewport(SDL_Renderer * renderer,
384 const SDL_Rect * rect);
387 * \brief Get the drawing area for the current target.
389 extern DECLSPEC void SDLCALL SDL_RenderGetViewport(SDL_Renderer * renderer,
393 * \brief Set the color used for drawing operations (Fill and Line).
395 * \param r The red value used to draw on the rendering target.
396 * \param g The green value used to draw on the rendering target.
397 * \param b The blue value used to draw on the rendering target.
398 * \param a The alpha value used to draw on the rendering target, usually
399 * ::SDL_ALPHA_OPAQUE (255).
401 * \return 0 on success, or -1 on error
403 extern DECLSPEC int SDL_SetRenderDrawColor(SDL_Renderer * renderer,
404 Uint8 r, Uint8 g, Uint8 b,
408 * \brief Get the color used for drawing operations (Fill and Line).
410 * \param r A pointer to the red value used to draw on the rendering target.
411 * \param g A pointer to the green value used to draw on the rendering target.
412 * \param b A pointer to the blue value used to draw on the rendering target.
413 * \param a A pointer to the alpha value used to draw on the rendering target,
414 * usually ::SDL_ALPHA_OPAQUE (255).
416 * \return 0 on success, or -1 on error
418 extern DECLSPEC int SDL_GetRenderDrawColor(SDL_Renderer * renderer,
419 Uint8 * r, Uint8 * g, Uint8 * b,
423 * \brief Set the blend mode used for drawing operations (Fill and Line).
425 * \param blendMode ::SDL_BlendMode to use for blending.
427 * \return 0 on success, or -1 on error
429 * \note If the blend mode is not supported, the closest supported mode is
432 * \sa SDL_GetRenderDrawBlendMode()
434 extern DECLSPEC int SDLCALL SDL_SetRenderDrawBlendMode(SDL_Renderer * renderer,
435 SDL_BlendMode blendMode);
438 * \brief Get the blend mode used for drawing operations.
440 * \param blendMode A pointer filled in with the current blend mode.
442 * \return 0 on success, or -1 on error
444 * \sa SDL_SetRenderDrawBlendMode()
446 extern DECLSPEC int SDLCALL SDL_GetRenderDrawBlendMode(SDL_Renderer * renderer,
447 SDL_BlendMode *blendMode);
450 * \brief Clear the current rendering target with the drawing color
452 * This function clears the entire rendering target, ignoring the viewport.
454 extern DECLSPEC int SDLCALL SDL_RenderClear(SDL_Renderer * renderer);
457 * \brief Draw a point on the current rendering target.
459 * \param x The x coordinate of the point.
460 * \param y The y coordinate of the point.
462 * \return 0 on success, or -1 on error
464 extern DECLSPEC int SDLCALL SDL_RenderDrawPoint(SDL_Renderer * renderer,
468 * \brief Draw multiple points on the current rendering target.
470 * \param points The points to draw
471 * \param count The number of points to draw
473 * \return 0 on success, or -1 on error
475 extern DECLSPEC int SDLCALL SDL_RenderDrawPoints(SDL_Renderer * renderer,
476 const SDL_Point * points,
480 * \brief Draw a line on the current rendering target.
482 * \param x1 The x coordinate of the start point.
483 * \param y1 The y coordinate of the start point.
484 * \param x2 The x coordinate of the end point.
485 * \param y2 The y coordinate of the end point.
487 * \return 0 on success, or -1 on error
489 extern DECLSPEC int SDLCALL SDL_RenderDrawLine(SDL_Renderer * renderer,
490 int x1, int y1, int x2, int y2);
493 * \brief Draw a series of connected lines on the current rendering target.
495 * \param points The points along the lines
496 * \param count The number of points, drawing count-1 lines
498 * \return 0 on success, or -1 on error
500 extern DECLSPEC int SDLCALL SDL_RenderDrawLines(SDL_Renderer * renderer,
501 const SDL_Point * points,
505 * \brief Draw a rectangle on the current rendering target.
507 * \param rect A pointer to the destination rectangle, or NULL to outline the entire rendering target.
509 * \return 0 on success, or -1 on error
511 extern DECLSPEC int SDLCALL SDL_RenderDrawRect(SDL_Renderer * renderer,
512 const SDL_Rect * rect);
515 * \brief Draw some number of rectangles on the current rendering target.
517 * \param rects A pointer to an array of destination rectangles.
518 * \param count The number of rectangles.
520 * \return 0 on success, or -1 on error
522 extern DECLSPEC int SDLCALL SDL_RenderDrawRects(SDL_Renderer * renderer,
523 const SDL_Rect * rects,
527 * \brief Fill a rectangle on the current rendering target with the drawing color.
529 * \param rect A pointer to the destination rectangle, or NULL for the entire
532 * \return 0 on success, or -1 on error
534 extern DECLSPEC int SDLCALL SDL_RenderFillRect(SDL_Renderer * renderer,
535 const SDL_Rect * rect);
538 * \brief Fill some number of rectangles on the current rendering target with the drawing color.
540 * \param rects A pointer to an array of destination rectangles.
541 * \param count The number of rectangles.
543 * \return 0 on success, or -1 on error
545 extern DECLSPEC int SDLCALL SDL_RenderFillRects(SDL_Renderer * renderer,
546 const SDL_Rect * rects,
550 * \brief Copy a portion of the texture to the current rendering target.
552 * \param texture The source texture.
553 * \param srcrect A pointer to the source rectangle, or NULL for the entire
555 * \param dstrect A pointer to the destination rectangle, or NULL for the
556 * entire rendering target.
558 * \return 0 on success, or -1 on error
560 extern DECLSPEC int SDLCALL SDL_RenderCopy(SDL_Renderer * renderer,
561 SDL_Texture * texture,
562 const SDL_Rect * srcrect,
563 const SDL_Rect * dstrect);
566 * \brief Read pixels from the current rendering target.
568 * \param rect A pointer to the rectangle to read, or NULL for the entire
570 * \param format The desired format of the pixel data, or 0 to use the format
571 * of the rendering target
572 * \param pixels A pointer to be filled in with the pixel data
573 * \param pitch The pitch of the pixels parameter.
575 * \return 0 on success, or -1 if pixel reading is not supported.
577 * \warning This is a very slow operation, and should not be used frequently.
579 extern DECLSPEC int SDLCALL SDL_RenderReadPixels(SDL_Renderer * renderer,
580 const SDL_Rect * rect,
582 void *pixels, int pitch);
585 * \brief Update the screen with rendering performed.
587 extern DECLSPEC void SDLCALL SDL_RenderPresent(SDL_Renderer * renderer);
590 * \brief Destroy the specified texture.
592 * \sa SDL_CreateTexture()
593 * \sa SDL_CreateTextureFromSurface()
595 extern DECLSPEC void SDLCALL SDL_DestroyTexture(SDL_Texture * texture);
598 * \brief Destroy the rendering context for a window and free associated
601 * \sa SDL_CreateRenderer()
603 extern DECLSPEC void SDLCALL SDL_DestroyRenderer(SDL_Renderer * renderer);
606 /* Ends C function definitions when using C++ */
612 #include "close_code.h"
614 #endif /* _SDL_render_h */
616 /* vi: set ts=4 sw=4 expandtab: */