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 information about a rendering context.
180 extern DECLSPEC int SDLCALL SDL_GetRendererInfo(SDL_Renderer * renderer,
181 SDL_RendererInfo * info);
184 * \brief Create a texture for a rendering context.
186 * \param format The format of the texture.
187 * \param access One of the enumerated values in ::SDL_TextureAccess.
188 * \param w The width of the texture in pixels.
189 * \param h The height of the texture in pixels.
191 * \return The created texture is returned, or 0 if no rendering context was
192 * active, the format was unsupported, or the width or height were out
195 * \sa SDL_QueryTexture()
196 * \sa SDL_UpdateTexture()
197 * \sa SDL_DestroyTexture()
199 extern DECLSPEC SDL_Texture * SDLCALL SDL_CreateTexture(SDL_Renderer * renderer,
205 * \brief Create a texture from an existing surface.
207 * \param surface The surface containing pixel data used to fill the texture.
209 * \return The created texture is returned, or 0 on error.
211 * \note The surface is not modified or freed by this function.
213 * \sa SDL_QueryTexture()
214 * \sa SDL_DestroyTexture()
216 extern DECLSPEC SDL_Texture * SDLCALL SDL_CreateTextureFromSurface(SDL_Renderer * renderer, SDL_Surface * surface);
219 * \brief Query the attributes of a texture
221 * \param texture A texture to be queried.
222 * \param format A pointer filled in with the raw format of the texture. The
223 * actual format may differ, but pixel transfers will use this
225 * \param access A pointer filled in with the actual access to the texture.
226 * \param w A pointer filled in with the width of the texture in pixels.
227 * \param h A pointer filled in with the height of the texture in pixels.
229 * \return 0 on success, or -1 if the texture is not valid.
231 extern DECLSPEC int SDLCALL SDL_QueryTexture(SDL_Texture * texture,
232 Uint32 * format, int *access,
236 * \brief Set an additional color value used in render copy operations.
238 * \param texture The texture to update.
239 * \param r The red color value multiplied into copy operations.
240 * \param g The green color value multiplied into copy operations.
241 * \param b The blue color value multiplied into copy operations.
243 * \return 0 on success, or -1 if the texture is not valid or color modulation
246 * \sa SDL_GetTextureColorMod()
248 extern DECLSPEC int SDLCALL SDL_SetTextureColorMod(SDL_Texture * texture,
249 Uint8 r, Uint8 g, Uint8 b);
253 * \brief Get the additional color value used in render copy operations.
255 * \param texture The texture to query.
256 * \param r A pointer filled in with the current red color value.
257 * \param g A pointer filled in with the current green color value.
258 * \param b A pointer filled in with the current blue color value.
260 * \return 0 on success, or -1 if the texture is not valid.
262 * \sa SDL_SetTextureColorMod()
264 extern DECLSPEC int SDLCALL SDL_GetTextureColorMod(SDL_Texture * texture,
265 Uint8 * r, Uint8 * g,
269 * \brief Set an additional alpha value used in render copy operations.
271 * \param texture The texture to update.
272 * \param alpha The alpha value multiplied into copy operations.
274 * \return 0 on success, or -1 if the texture is not valid or alpha modulation
277 * \sa SDL_GetTextureAlphaMod()
279 extern DECLSPEC int SDLCALL SDL_SetTextureAlphaMod(SDL_Texture * texture,
283 * \brief Get the additional alpha value used in render copy operations.
285 * \param texture The texture to query.
286 * \param alpha A pointer filled in with the current alpha value.
288 * \return 0 on success, or -1 if the texture is not valid.
290 * \sa SDL_SetTextureAlphaMod()
292 extern DECLSPEC int SDLCALL SDL_GetTextureAlphaMod(SDL_Texture * texture,
296 * \brief Set the blend mode used for texture copy operations.
298 * \param texture The texture to update.
299 * \param blendMode ::SDL_BlendMode to use for texture blending.
301 * \return 0 on success, or -1 if the texture is not valid or the blend mode is
304 * \note If the blend mode is not supported, the closest supported mode is
307 * \sa SDL_GetTextureBlendMode()
309 extern DECLSPEC int SDLCALL SDL_SetTextureBlendMode(SDL_Texture * texture,
310 SDL_BlendMode blendMode);
313 * \brief Get the blend mode used for texture copy operations.
315 * \param texture The texture to query.
316 * \param blendMode A pointer filled in with the current blend mode.
318 * \return 0 on success, or -1 if the texture is not valid.
320 * \sa SDL_SetTextureBlendMode()
322 extern DECLSPEC int SDLCALL SDL_GetTextureBlendMode(SDL_Texture * texture,
323 SDL_BlendMode *blendMode);
326 * \brief Update the given texture rectangle with new pixel data.
328 * \param texture The texture to update
329 * \param rect A pointer to the rectangle of pixels to update, or NULL to
330 * update the entire texture.
331 * \param pixels The raw pixel data.
332 * \param pitch The number of bytes between rows of pixel data.
334 * \return 0 on success, or -1 if the texture is not valid.
336 * \note This is a fairly slow function.
338 extern DECLSPEC int SDLCALL SDL_UpdateTexture(SDL_Texture * texture,
339 const SDL_Rect * rect,
340 const void *pixels, int pitch);
343 * \brief Lock a portion of the texture for pixel access.
345 * \param texture The texture to lock for access, which was created with
346 * ::SDL_TEXTUREACCESS_STREAMING.
347 * \param rect A pointer to the rectangle to lock for access. If the rect
348 * is NULL, the entire texture will be locked.
349 * \param pixels This is filled in with a pointer to the locked pixels,
350 * appropriately offset by the locked area.
351 * \param pitch This is filled in with the pitch of the locked pixels.
353 * \return 0 on success, or -1 if the texture is not valid or was not created with ::SDL_TEXTUREACCESS_STREAMING.
355 * \sa SDL_UnlockTexture()
357 extern DECLSPEC int SDLCALL SDL_LockTexture(SDL_Texture * texture,
358 const SDL_Rect * rect,
359 void **pixels, int *pitch);
362 * \brief Unlock a texture, uploading the changes to video memory, if needed.
364 * \sa SDL_LockTexture()
366 extern DECLSPEC void SDLCALL SDL_UnlockTexture(SDL_Texture * texture);
369 * \brief Set the drawing area for rendering on the current target.
371 * \param rect The rectangle representing the drawing area, or NULL to set the viewport to the entire target.
373 * The x,y of the viewport rect represents the origin for rendering.
375 * \note When the window is resized, the current viewport is automatically
376 * centered within the new window size.
378 extern DECLSPEC int SDLCALL SDL_RenderSetViewport(SDL_Renderer * renderer,
379 const SDL_Rect * rect);
382 * \brief Get the drawing area for the current target.
384 extern DECLSPEC void SDLCALL SDL_RenderGetViewport(SDL_Renderer * renderer,
388 * \brief Set the color used for drawing operations (Fill and Line).
390 * \param r The red value used to draw on the rendering target.
391 * \param g The green value used to draw on the rendering target.
392 * \param b The blue value used to draw on the rendering target.
393 * \param a The alpha value used to draw on the rendering target, usually
394 * ::SDL_ALPHA_OPAQUE (255).
396 * \return 0 on success, or -1 on error
398 extern DECLSPEC int SDL_SetRenderDrawColor(SDL_Renderer * renderer,
399 Uint8 r, Uint8 g, Uint8 b,
403 * \brief Get the color used for drawing operations (Fill and Line).
405 * \param r A pointer to the red value used to draw on the rendering target.
406 * \param g A pointer to the green value used to draw on the rendering target.
407 * \param b A pointer to the blue value used to draw on the rendering target.
408 * \param a A pointer to the alpha value used to draw on the rendering target,
409 * usually ::SDL_ALPHA_OPAQUE (255).
411 * \return 0 on success, or -1 on error
413 extern DECLSPEC int SDL_GetRenderDrawColor(SDL_Renderer * renderer,
414 Uint8 * r, Uint8 * g, Uint8 * b,
418 * \brief Set the blend mode used for drawing operations (Fill and Line).
420 * \param blendMode ::SDL_BlendMode to use for blending.
422 * \return 0 on success, or -1 on error
424 * \note If the blend mode is not supported, the closest supported mode is
427 * \sa SDL_GetRenderDrawBlendMode()
429 extern DECLSPEC int SDLCALL SDL_SetRenderDrawBlendMode(SDL_Renderer * renderer,
430 SDL_BlendMode blendMode);
433 * \brief Get the blend mode used for drawing operations.
435 * \param blendMode A pointer filled in with the current blend mode.
437 * \return 0 on success, or -1 on error
439 * \sa SDL_SetRenderDrawBlendMode()
441 extern DECLSPEC int SDLCALL SDL_GetRenderDrawBlendMode(SDL_Renderer * renderer,
442 SDL_BlendMode *blendMode);
445 * \brief Clear the current rendering target with the drawing color
447 * This function clears the entire rendering target, ignoring the viewport.
449 extern DECLSPEC int SDLCALL SDL_RenderClear(SDL_Renderer * renderer);
452 * \brief Draw a point on the current rendering target.
454 * \param x The x coordinate of the point.
455 * \param y The y coordinate of the point.
457 * \return 0 on success, or -1 on error
459 extern DECLSPEC int SDLCALL SDL_RenderDrawPoint(SDL_Renderer * renderer,
463 * \brief Draw multiple points on the current rendering target.
465 * \param points The points to draw
466 * \param count The number of points to draw
468 * \return 0 on success, or -1 on error
470 extern DECLSPEC int SDLCALL SDL_RenderDrawPoints(SDL_Renderer * renderer,
471 const SDL_Point * points,
475 * \brief Draw a line on the current rendering target.
477 * \param x1 The x coordinate of the start point.
478 * \param y1 The y coordinate of the start point.
479 * \param x2 The x coordinate of the end point.
480 * \param y2 The y coordinate of the end point.
482 * \return 0 on success, or -1 on error
484 extern DECLSPEC int SDLCALL SDL_RenderDrawLine(SDL_Renderer * renderer,
485 int x1, int y1, int x2, int y2);
488 * \brief Draw a series of connected lines on the current rendering target.
490 * \param points The points along the lines
491 * \param count The number of points, drawing count-1 lines
493 * \return 0 on success, or -1 on error
495 extern DECLSPEC int SDLCALL SDL_RenderDrawLines(SDL_Renderer * renderer,
496 const SDL_Point * points,
500 * \brief Draw a rectangle on the current rendering target.
502 * \param rect A pointer to the destination rectangle, or NULL to outline the entire rendering target.
504 * \return 0 on success, or -1 on error
506 extern DECLSPEC int SDLCALL SDL_RenderDrawRect(SDL_Renderer * renderer,
507 const SDL_Rect * rect);
510 * \brief Draw some number of rectangles on the current rendering target.
512 * \param rects A pointer to an array of destination rectangles.
513 * \param count The number of rectangles.
515 * \return 0 on success, or -1 on error
517 extern DECLSPEC int SDLCALL SDL_RenderDrawRects(SDL_Renderer * renderer,
518 const SDL_Rect * rects,
522 * \brief Fill a rectangle on the current rendering target with the drawing color.
524 * \param rect A pointer to the destination rectangle, or NULL for the entire
527 * \return 0 on success, or -1 on error
529 extern DECLSPEC int SDLCALL SDL_RenderFillRect(SDL_Renderer * renderer,
530 const SDL_Rect * rect);
533 * \brief Fill some number of rectangles on the current rendering target with the drawing color.
535 * \param rects A pointer to an array of destination rectangles.
536 * \param count The number of rectangles.
538 * \return 0 on success, or -1 on error
540 extern DECLSPEC int SDLCALL SDL_RenderFillRects(SDL_Renderer * renderer,
541 const SDL_Rect * rects,
545 * \brief Copy a portion of the texture to the current rendering target.
547 * \param texture The source texture.
548 * \param srcrect A pointer to the source rectangle, or NULL for the entire
550 * \param dstrect A pointer to the destination rectangle, or NULL for the
551 * entire rendering target.
553 * \return 0 on success, or -1 on error
555 extern DECLSPEC int SDLCALL SDL_RenderCopy(SDL_Renderer * renderer,
556 SDL_Texture * texture,
557 const SDL_Rect * srcrect,
558 const SDL_Rect * dstrect);
561 * \brief Read pixels from the current rendering target.
563 * \param rect A pointer to the rectangle to read, or NULL for the entire
565 * \param format The desired format of the pixel data, or 0 to use the format
566 * of the rendering target
567 * \param pixels A pointer to be filled in with the pixel data
568 * \param pitch The pitch of the pixels parameter.
570 * \return 0 on success, or -1 if pixel reading is not supported.
572 * \warning This is a very slow operation, and should not be used frequently.
574 extern DECLSPEC int SDLCALL SDL_RenderReadPixels(SDL_Renderer * renderer,
575 const SDL_Rect * rect,
577 void *pixels, int pitch);
580 * \brief Update the screen with rendering performed.
582 extern DECLSPEC void SDLCALL SDL_RenderPresent(SDL_Renderer * renderer);
585 * \brief Destroy the specified texture.
587 * \sa SDL_CreateTexture()
588 * \sa SDL_CreateTextureFromSurface()
590 extern DECLSPEC void SDLCALL SDL_DestroyTexture(SDL_Texture * texture);
593 * \brief Destroy the rendering context for a window and free associated
596 * \sa SDL_CreateRenderer()
598 extern DECLSPEC void SDLCALL SDL_DestroyRenderer(SDL_Renderer * renderer);
601 /* Ends C function definitions when using C++ */
607 #include "close_code.h"
609 #endif /* _SDL_render_h */
611 /* vi: set ts=4 sw=4 expandtab: */