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_ACCELERATED = 0x00000001, /**< The renderer uses hardware
68 SDL_RENDERER_PRESENTVSYNC = 0x00000002 /**< Present is synchronized
69 with the refresh rate */
73 * \brief Information on the capabilities of a render driver or context.
75 typedef struct SDL_RendererInfo
77 const char *name; /**< The name of the renderer */
78 Uint32 flags; /**< Supported ::SDL_RendererFlags */
79 Uint32 num_texture_formats; /**< The number of available texture formats */
80 Uint32 texture_formats[16]; /**< The available texture formats */
81 int max_texture_width; /**< The maximimum texture width */
82 int max_texture_height; /**< The maximimum texture height */
86 * \brief The access pattern allowed for a texture.
90 SDL_TEXTUREACCESS_STATIC, /**< Changes rarely, not lockable */
91 SDL_TEXTUREACCESS_STREAMING /**< Changes frequently, lockable */
95 * \brief The texture channel modulation used in SDL_RenderCopy().
99 SDL_TEXTUREMODULATE_NONE = 0x00000000, /**< No modulation */
100 SDL_TEXTUREMODULATE_COLOR = 0x00000001, /**< srcC = srcC * color */
101 SDL_TEXTUREMODULATE_ALPHA = 0x00000002 /**< srcA = srcA * alpha */
102 } SDL_TextureModulate;
105 * \brief A structure representing rendering state
108 typedef struct SDL_Renderer SDL_Renderer;
111 * \brief An efficient driver-specific representation of pixel data
114 typedef struct SDL_Texture SDL_Texture;
117 /* Function prototypes */
120 * \brief Get the number of 2D rendering drivers available for the current
123 * A render driver is a set of code that handles rendering and texture
124 * management on a particular display. Normally there is only one, but
125 * some drivers may have several available with different capabilities.
127 * \sa SDL_GetRenderDriverInfo()
128 * \sa SDL_CreateRenderer()
130 extern DECLSPEC int SDLCALL SDL_GetNumRenderDrivers(void);
133 * \brief Get information about a specific 2D rendering driver for the current
136 * \param index The index of the driver to query information about.
137 * \param info A pointer to an SDL_RendererInfo struct to be filled with
138 * information on the rendering driver.
140 * \return 0 on success, -1 if the index was out of range.
142 * \sa SDL_CreateRenderer()
144 extern DECLSPEC int SDLCALL SDL_GetRenderDriverInfo(int index,
145 SDL_RendererInfo * info);
148 * \brief Create a 2D rendering context for a window.
150 * \param window The window where rendering is displayed.
151 * \param index The index of the rendering driver to initialize, or -1 to
152 * initialize the first one supporting the requested flags.
153 * \param flags ::SDL_RendererFlags.
155 * \return A valid rendering context or NULL if there was an error.
157 * \sa SDL_CreateSoftwareRenderer()
158 * \sa SDL_GetRendererInfo()
159 * \sa SDL_DestroyRenderer()
161 extern DECLSPEC SDL_Renderer * SDLCALL SDL_CreateRenderer(SDL_Window * window,
162 int index, Uint32 flags);
165 * \brief Create a 2D software rendering context for a surface.
167 * \param surface The surface where rendering is done.
169 * \return A valid rendering context or NULL if there was an error.
171 * \sa SDL_CreateRenderer()
172 * \sa SDL_DestroyRenderer()
174 extern DECLSPEC SDL_Renderer * SDLCALL SDL_CreateSoftwareRenderer(SDL_Surface * surface);
177 * \brief Get information about a rendering context.
179 extern DECLSPEC int SDLCALL SDL_GetRendererInfo(SDL_Renderer * renderer,
180 SDL_RendererInfo * info);
183 * \brief Create a texture for a rendering context.
185 * \param format The format of the texture.
186 * \param access One of the enumerated values in ::SDL_TextureAccess.
187 * \param w The width of the texture in pixels.
188 * \param h The height of the texture in pixels.
190 * \return The created texture is returned, or 0 if no rendering context was
191 * active, the format was unsupported, or the width or height were out
194 * \sa SDL_QueryTexture()
195 * \sa SDL_UpdateTexture()
196 * \sa SDL_DestroyTexture()
198 extern DECLSPEC SDL_Texture * SDLCALL SDL_CreateTexture(SDL_Renderer * renderer, Uint32 format,
203 * \brief Create a texture from an existing surface.
205 * \param surface The surface containing pixel data used to fill the texture.
207 * \return The created texture is returned, or 0 on error.
209 * \note The surface is not modified or freed by this function.
211 * \sa SDL_QueryTexture()
212 * \sa SDL_DestroyTexture()
214 extern DECLSPEC SDL_Texture * SDLCALL SDL_CreateTextureFromSurface(SDL_Renderer * renderer, SDL_Surface * surface);
217 * \brief Query the attributes of a texture
219 * \param texture A texture to be queried.
220 * \param format A pointer filled in with the raw format of the texture. The
221 * actual format may differ, but pixel transfers will use this
223 * \param access A pointer filled in with the actual access to the texture.
224 * \param w A pointer filled in with the width of the texture in pixels.
225 * \param h A pointer filled in with the height of the texture in pixels.
227 * \return 0 on success, or -1 if the texture is not valid.
229 extern DECLSPEC int SDLCALL SDL_QueryTexture(SDL_Texture * texture,
230 Uint32 * format, int *access,
234 * \brief Set an additional color value used in render copy operations.
236 * \param texture The texture to update.
237 * \param r The red color value multiplied into copy operations.
238 * \param g The green color value multiplied into copy operations.
239 * \param b The blue color value multiplied into copy operations.
241 * \return 0 on success, or -1 if the texture is not valid or color modulation
244 * \sa SDL_GetTextureColorMod()
246 extern DECLSPEC int SDLCALL SDL_SetTextureColorMod(SDL_Texture * texture,
247 Uint8 r, Uint8 g, Uint8 b);
251 * \brief Get the additional color value used in render copy operations.
253 * \param texture The texture to query.
254 * \param r A pointer filled in with the current red color value.
255 * \param g A pointer filled in with the current green color value.
256 * \param b A pointer filled in with the current blue color value.
258 * \return 0 on success, or -1 if the texture is not valid.
260 * \sa SDL_SetTextureColorMod()
262 extern DECLSPEC int SDLCALL SDL_GetTextureColorMod(SDL_Texture * texture,
263 Uint8 * r, Uint8 * g,
267 * \brief Set an additional alpha value used in render copy operations.
269 * \param texture The texture to update.
270 * \param alpha The alpha value multiplied into copy operations.
272 * \return 0 on success, or -1 if the texture is not valid or alpha modulation
275 * \sa SDL_GetTextureAlphaMod()
277 extern DECLSPEC int SDLCALL SDL_SetTextureAlphaMod(SDL_Texture * texture,
281 * \brief Get the additional alpha value used in render copy operations.
283 * \param texture The texture to query.
284 * \param alpha A pointer filled in with the current alpha value.
286 * \return 0 on success, or -1 if the texture is not valid.
288 * \sa SDL_SetTextureAlphaMod()
290 extern DECLSPEC int SDLCALL SDL_GetTextureAlphaMod(SDL_Texture * texture,
294 * \brief Set the blend mode used for texture copy operations.
296 * \param texture The texture to update.
297 * \param blendMode ::SDL_BlendMode to use for texture blending.
299 * \return 0 on success, or -1 if the texture is not valid or the blend mode is
302 * \note If the blend mode is not supported, the closest supported mode is
305 * \sa SDL_GetTextureBlendMode()
307 extern DECLSPEC int SDLCALL SDL_SetTextureBlendMode(SDL_Texture * texture,
308 SDL_BlendMode blendMode);
311 * \brief Get the blend mode used for texture copy operations.
313 * \param texture The texture to query.
314 * \param blendMode A pointer filled in with the current blend mode.
316 * \return 0 on success, or -1 if the texture is not valid.
318 * \sa SDL_SetTextureBlendMode()
320 extern DECLSPEC int SDLCALL SDL_GetTextureBlendMode(SDL_Texture * texture,
321 SDL_BlendMode *blendMode);
324 * \brief Update the given texture rectangle with new pixel data.
326 * \param texture The texture to update
327 * \param rect A pointer to the rectangle of pixels to update, or NULL to
328 * update the entire texture.
329 * \param pixels The raw pixel data.
330 * \param pitch The number of bytes between rows of pixel data.
332 * \return 0 on success, or -1 if the texture is not valid.
334 * \note This is a fairly slow function.
336 extern DECLSPEC int SDLCALL SDL_UpdateTexture(SDL_Texture * texture,
337 const SDL_Rect * rect,
338 const void *pixels, int pitch);
341 * \brief Lock a portion of the texture for pixel access.
343 * \param texture The texture to lock for access, which was created with
344 * ::SDL_TEXTUREACCESS_STREAMING.
345 * \param rect A pointer to the rectangle to lock for access. If the rect
346 * is NULL, the entire texture will be locked.
347 * \param pixels This is filled in with a pointer to the locked pixels,
348 * appropriately offset by the locked area.
349 * \param pitch This is filled in with the pitch of the locked pixels.
351 * \return 0 on success, or -1 if the texture is not valid or was not created with ::SDL_TEXTUREACCESS_STREAMING.
353 * \sa SDL_UnlockTexture()
355 extern DECLSPEC int SDLCALL SDL_LockTexture(SDL_Texture * texture,
356 const SDL_Rect * rect,
357 void **pixels, int *pitch);
360 * \brief Unlock a texture, uploading the changes to video memory, if needed.
362 * \sa SDL_LockTexture()
364 extern DECLSPEC void SDLCALL SDL_UnlockTexture(SDL_Texture * texture);
367 * \brief Set the clipping rectangle for rendering on the current target
369 * \param rect The rectangle to clip rendering to, or NULL to disable clipping.
371 * The contents of the window are not defined after calling
372 * SDL_RenderPresent(), so you should clear the clip rectangle and draw
373 * over the entire window each frame.
375 extern DECLSPEC void SDLCALL SDL_RenderSetClipRect(SDL_Renderer * renderer,
376 const SDL_Rect * rect);
379 * \brief Set the color used for drawing operations (Fill and Line).
381 * \param r The red value used to draw on the rendering target.
382 * \param g The green value used to draw on the rendering target.
383 * \param b The blue value used to draw on the rendering target.
384 * \param a The alpha value used to draw on the rendering target, usually
385 * ::SDL_ALPHA_OPAQUE (255).
387 * \return 0 on success, or -1 on error
389 extern DECLSPEC int SDL_SetRenderDrawColor(SDL_Renderer * renderer,
390 Uint8 r, Uint8 g, Uint8 b,
394 * \brief Get the color used for drawing operations (Fill and Line).
396 * \param r A pointer to the red value used to draw on the rendering target.
397 * \param g A pointer to the green value used to draw on the rendering target.
398 * \param b A pointer to the blue value used to draw on the rendering target.
399 * \param a A pointer to the alpha value used to draw on the rendering target,
400 * usually ::SDL_ALPHA_OPAQUE (255).
402 * \return 0 on success, or -1 on error
404 extern DECLSPEC int SDL_GetRenderDrawColor(SDL_Renderer * renderer,
405 Uint8 * r, Uint8 * g, Uint8 * b,
409 * \brief Set the blend mode used for drawing operations (Fill and Line).
411 * \param blendMode ::SDL_BlendMode to use for blending.
413 * \return 0 on success, or -1 on error
415 * \note If the blend mode is not supported, the closest supported mode is
418 * \sa SDL_GetRenderDrawBlendMode()
420 extern DECLSPEC int SDLCALL SDL_SetRenderDrawBlendMode(SDL_Renderer * renderer,
421 SDL_BlendMode blendMode);
424 * \brief Get the blend mode used for drawing operations.
426 * \param blendMode A pointer filled in with the current blend mode.
428 * \return 0 on success, or -1 on error
430 * \sa SDL_SetRenderDrawBlendMode()
432 extern DECLSPEC int SDLCALL SDL_GetRenderDrawBlendMode(SDL_Renderer * renderer,
433 SDL_BlendMode *blendMode);
436 * \brief Clear the current rendering target with the drawing color
438 extern DECLSPEC int SDLCALL SDL_RenderClear(SDL_Renderer * renderer);
441 * \brief Draw a point on the current rendering target.
443 * \param x The x coordinate of the point.
444 * \param y The y coordinate of the point.
446 * \return 0 on success, or -1 on error
448 extern DECLSPEC int SDLCALL SDL_RenderDrawPoint(SDL_Renderer * renderer,
452 * \brief Draw multiple points on the current rendering target.
454 * \param points The points to draw
455 * \param count The number of points to draw
457 * \return 0 on success, or -1 on error
459 extern DECLSPEC int SDLCALL SDL_RenderDrawPoints(SDL_Renderer * renderer,
460 const SDL_Point * points,
464 * \brief Draw a line on the current rendering target.
466 * \param x1 The x coordinate of the start point.
467 * \param y1 The y coordinate of the start point.
468 * \param x2 The x coordinate of the end point.
469 * \param y2 The y coordinate of the end point.
471 * \return 0 on success, or -1 on error
473 extern DECLSPEC int SDLCALL SDL_RenderDrawLine(SDL_Renderer * renderer,
474 int x1, int y1, int x2, int y2);
477 * \brief Draw a series of connected lines on the current rendering target.
479 * \param points The points along the lines
480 * \param count The number of points, drawing count-1 lines
482 * \return 0 on success, or -1 on error
484 extern DECLSPEC int SDLCALL SDL_RenderDrawLines(SDL_Renderer * renderer,
485 const SDL_Point * points,
489 * \brief Draw a rectangle on the current rendering target.
491 * \param rect A pointer to the destination rectangle, or NULL to outline the entire rendering target.
493 * \return 0 on success, or -1 on error
495 extern DECLSPEC int SDLCALL SDL_RenderDrawRect(SDL_Renderer * renderer,
496 const SDL_Rect * rect);
499 * \brief Draw some number of rectangles on the current rendering target.
501 * \param rects A pointer to an array of destination rectangles.
502 * \param count The number of rectangles.
504 * \return 0 on success, or -1 on error
506 extern DECLSPEC int SDLCALL SDL_RenderDrawRects(SDL_Renderer * renderer,
507 const SDL_Rect ** rects,
511 * \brief Fill a rectangle on the current rendering target with the drawing color.
513 * \param rect A pointer to the destination rectangle, or NULL for the entire
516 * \return 0 on success, or -1 on error
518 extern DECLSPEC int SDLCALL SDL_RenderFillRect(SDL_Renderer * renderer,
519 const SDL_Rect * rect);
522 * \brief Fill some number of rectangles on the current rendering target with the drawing color.
524 * \param rects A pointer to an array of destination rectangles.
525 * \param count The number of rectangles.
527 * \return 0 on success, or -1 on error
529 extern DECLSPEC int SDLCALL SDL_RenderFillRects(SDL_Renderer * renderer,
530 const SDL_Rect ** rect,
534 * \brief Copy a portion of the texture to the current rendering target.
536 * \param texture The source texture.
537 * \param srcrect A pointer to the source rectangle, or NULL for the entire
539 * \param dstrect A pointer to the destination rectangle, or NULL for the
540 * entire rendering target.
542 * \return 0 on success, or -1 on error
544 extern DECLSPEC int SDLCALL SDL_RenderCopy(SDL_Renderer * renderer,
545 SDL_Texture * texture,
546 const SDL_Rect * srcrect,
547 const SDL_Rect * dstrect);
550 * \brief Read pixels from the current rendering target.
552 * \param rect A pointer to the rectangle to read, or NULL for the entire
554 * \param format The desired format of the pixel data, or 0 to use the format
555 * of the rendering target
556 * \param pixels A pointer to be filled in with the pixel data
557 * \param pitch The pitch of the pixels parameter.
559 * \return 0 on success, or -1 if pixel reading is not supported.
561 * \warning This is a very slow operation, and should not be used frequently.
563 extern DECLSPEC int SDLCALL SDL_RenderReadPixels(SDL_Renderer * renderer,
564 const SDL_Rect * rect,
566 void *pixels, int pitch);
569 * \brief Update the screen with rendering performed.
571 extern DECLSPEC void SDLCALL SDL_RenderPresent(SDL_Renderer * renderer);
574 * \brief Destroy the specified texture.
576 * \sa SDL_CreateTexture()
577 * \sa SDL_CreateTextureFromSurface()
579 extern DECLSPEC void SDLCALL SDL_DestroyTexture(SDL_Texture * texture);
582 * \brief Destroy the rendering context for a window and free associated
585 * \sa SDL_CreateRenderer()
587 extern DECLSPEC void SDLCALL SDL_DestroyRenderer(SDL_Renderer * renderer);
590 /* Ends C function definitions when using C++ */
596 #include "close_code.h"
598 #endif /* _SDL_render_h */
600 /* vi: set ts=4 sw=4 expandtab: */