Added a way to get a framebuffer interface for a window, and also a way to create a software renderer for an arbitrary surface.
The software renderer has been re-routed to use the framebuffer interface, which makes it possible to have software rendering available even on simple ports.
2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997-2010 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_DestroyTexture()
197 extern DECLSPEC SDL_Texture * SDLCALL SDL_CreateTexture(SDL_Renderer * renderer, Uint32 format,
202 * \brief Create a texture from an existing surface.
204 * \param surface The surface containing pixel data used to fill the texture.
206 * \return The created texture is returned, or 0 on error.
208 * \note The surface is not modified or freed by this function.
210 * \sa SDL_QueryTexture()
211 * \sa SDL_DestroyTexture()
213 extern DECLSPEC SDL_Texture * SDLCALL SDL_CreateTextureFromSurface(SDL_Renderer * renderer, SDL_Surface * surface);
216 * \brief Query the attributes of a texture
218 * \param texture A texture to be queried.
219 * \param format A pointer filled in with the raw format of the texture. The
220 * actual format may differ, but pixel transfers will use this
222 * \param access A pointer filled in with the actual access to the texture.
223 * \param w A pointer filled in with the width of the texture in pixels.
224 * \param h A pointer filled in with the height of the texture in pixels.
226 * \return 0 on success, or -1 if the texture is not valid.
228 extern DECLSPEC int SDLCALL SDL_QueryTexture(SDL_Texture * texture,
229 Uint32 * format, int *access,
233 * \brief Set an additional color value used in render copy operations.
235 * \param texture The texture to update.
236 * \param r The red color value multiplied into copy operations.
237 * \param g The green color value multiplied into copy operations.
238 * \param b The blue color value multiplied into copy operations.
240 * \return 0 on success, or -1 if the texture is not valid or color modulation
243 * \sa SDL_GetTextureColorMod()
245 extern DECLSPEC int SDLCALL SDL_SetTextureColorMod(SDL_Texture * texture,
246 Uint8 r, Uint8 g, Uint8 b);
250 * \brief Get the additional color value used in render copy operations.
252 * \param texture The texture to query.
253 * \param r A pointer filled in with the current red color value.
254 * \param g A pointer filled in with the current green color value.
255 * \param b A pointer filled in with the current blue color value.
257 * \return 0 on success, or -1 if the texture is not valid.
259 * \sa SDL_SetTextureColorMod()
261 extern DECLSPEC int SDLCALL SDL_GetTextureColorMod(SDL_Texture * texture,
262 Uint8 * r, Uint8 * g,
266 * \brief Set an additional alpha value used in render copy operations.
268 * \param texture The texture to update.
269 * \param alpha The alpha value multiplied into copy operations.
271 * \return 0 on success, or -1 if the texture is not valid or alpha modulation
274 * \sa SDL_GetTextureAlphaMod()
276 extern DECLSPEC int SDLCALL SDL_SetTextureAlphaMod(SDL_Texture * texture,
280 * \brief Get the additional alpha value used in render copy operations.
282 * \param texture The texture to query.
283 * \param alpha A pointer filled in with the current alpha value.
285 * \return 0 on success, or -1 if the texture is not valid.
287 * \sa SDL_SetTextureAlphaMod()
289 extern DECLSPEC int SDLCALL SDL_GetTextureAlphaMod(SDL_Texture * texture,
293 * \brief Set the blend mode used for texture copy operations.
295 * \param texture The texture to update.
296 * \param blendMode ::SDL_BlendMode to use for texture blending.
298 * \return 0 on success, or -1 if the texture is not valid or the blend mode is
301 * \note If the blend mode is not supported, the closest supported mode is
304 * \sa SDL_GetTextureBlendMode()
306 extern DECLSPEC int SDLCALL SDL_SetTextureBlendMode(SDL_Texture * texture,
307 SDL_BlendMode blendMode);
310 * \brief Get the blend mode used for texture copy operations.
312 * \param texture The texture to query.
313 * \param blendMode A pointer filled in with the current blend mode.
315 * \return 0 on success, or -1 if the texture is not valid.
317 * \sa SDL_SetTextureBlendMode()
319 extern DECLSPEC int SDLCALL SDL_GetTextureBlendMode(SDL_Texture * texture,
320 SDL_BlendMode *blendMode);
323 * \brief Update the given texture rectangle with new pixel data.
325 * \param texture The texture to update
326 * \param rect A pointer to the rectangle of pixels to update, or NULL to
327 * update the entire texture.
328 * \param pixels The raw pixel data.
329 * \param pitch The number of bytes between rows of pixel data.
331 * \return 0 on success, or -1 if the texture is not valid.
333 * \note This is a fairly slow function.
335 extern DECLSPEC int SDLCALL SDL_UpdateTexture(SDL_Texture * texture,
336 const SDL_Rect * rect,
337 const void *pixels, int pitch);
340 * \brief Lock a portion of the texture for pixel access.
342 * \param texture The texture to lock for access, which was created with
343 * ::SDL_TEXTUREACCESS_STREAMING.
344 * \param rect A pointer to the rectangle to lock for access. If the rect
345 * is NULL, the entire texture will be locked.
346 * \param pixels This is filled in with a pointer to the locked pixels,
347 * appropriately offset by the locked area.
348 * \param pitch This is filled in with the pitch of the locked pixels.
350 * \return 0 on success, or -1 if the texture is not valid or was not created with ::SDL_TEXTUREACCESS_STREAMING.
352 * \sa SDL_UnlockTexture()
354 extern DECLSPEC int SDLCALL SDL_LockTexture(SDL_Texture * texture,
355 const SDL_Rect * rect,
356 void **pixels, int *pitch);
359 * \brief Unlock a texture, uploading the changes to video memory, if needed.
361 * \sa SDL_LockTexture()
363 extern DECLSPEC void SDLCALL SDL_UnlockTexture(SDL_Texture * texture);
366 * \brief Set the color used for drawing operations (Fill and Line).
368 * \param r The red value used to draw on the rendering target.
369 * \param g The green value used to draw on the rendering target.
370 * \param b The blue value used to draw on the rendering target.
371 * \param a The alpha value used to draw on the rendering target, usually
372 * ::SDL_ALPHA_OPAQUE (255).
374 * \return 0 on success, or -1 on error
376 extern DECLSPEC int SDL_SetRenderDrawColor(SDL_Renderer * renderer,
377 Uint8 r, Uint8 g, Uint8 b,
381 * \brief Get the color used for drawing operations (Fill and Line).
383 * \param r A pointer to the red value used to draw on the rendering target.
384 * \param g A pointer to the green value used to draw on the rendering target.
385 * \param b A pointer to the blue value used to draw on the rendering target.
386 * \param a A pointer to the alpha value used to draw on the rendering target,
387 * usually ::SDL_ALPHA_OPAQUE (255).
389 * \return 0 on success, or -1 on error
391 extern DECLSPEC int SDL_GetRenderDrawColor(SDL_Renderer * renderer,
392 Uint8 * r, Uint8 * g, Uint8 * b,
396 * \brief Set the blend mode used for drawing operations (Fill and Line).
398 * \param blendMode ::SDL_BlendMode to use for blending.
400 * \return 0 on success, or -1 on error
402 * \note If the blend mode is not supported, the closest supported mode is
405 * \sa SDL_GetRenderDrawBlendMode()
407 extern DECLSPEC int SDLCALL SDL_SetRenderDrawBlendMode(SDL_Renderer * renderer,
408 SDL_BlendMode blendMode);
411 * \brief Get the blend mode used for drawing operations.
413 * \param blendMode A pointer filled in with the current blend mode.
415 * \return 0 on success, or -1 on error
417 * \sa SDL_SetRenderDrawBlendMode()
419 extern DECLSPEC int SDLCALL SDL_GetRenderDrawBlendMode(SDL_Renderer * renderer,
420 SDL_BlendMode *blendMode);
423 * \brief Clear the current rendering target with the drawing color
425 extern DECLSPEC int SDLCALL SDL_RenderClear(SDL_Renderer * renderer);
428 * \brief Draw a point on the current rendering target.
430 * \param x The x coordinate of the point.
431 * \param y The y coordinate of the point.
433 * \return 0 on success, or -1 on error
435 extern DECLSPEC int SDLCALL SDL_RenderDrawPoint(SDL_Renderer * renderer,
439 * \brief Draw multiple points on the current rendering target.
441 * \param points The points to draw
442 * \param count The number of points to draw
444 * \return 0 on success, or -1 on error
446 extern DECLSPEC int SDLCALL SDL_RenderDrawPoints(SDL_Renderer * renderer,
447 const SDL_Point * points,
451 * \brief Draw a line on the current rendering target.
453 * \param x1 The x coordinate of the start point.
454 * \param y1 The y coordinate of the start point.
455 * \param x2 The x coordinate of the end point.
456 * \param y2 The y coordinate of the end point.
458 * \return 0 on success, or -1 on error
460 extern DECLSPEC int SDLCALL SDL_RenderDrawLine(SDL_Renderer * renderer,
461 int x1, int y1, int x2, int y2);
464 * \brief Draw a series of connected lines on the current rendering target.
466 * \param points The points along the lines
467 * \param count The number of points, drawing count-1 lines
469 * \return 0 on success, or -1 on error
471 extern DECLSPEC int SDLCALL SDL_RenderDrawLines(SDL_Renderer * renderer,
472 const SDL_Point * points,
476 * \brief Draw a rectangle on the current rendering target.
478 * \param rect A pointer to the destination rectangle, or NULL to outline the entire rendering target.
480 * \return 0 on success, or -1 on error
482 extern DECLSPEC int SDLCALL SDL_RenderDrawRect(SDL_Renderer * renderer,
483 const SDL_Rect * rect);
486 * \brief Draw some number of rectangles on the current rendering target.
488 * \param rects A pointer to an array of destination rectangles.
489 * \param count The number of rectangles.
491 * \return 0 on success, or -1 on error
493 extern DECLSPEC int SDLCALL SDL_RenderDrawRects(SDL_Renderer * renderer,
494 const SDL_Rect ** rects,
498 * \brief Fill a rectangle on the current rendering target with the drawing color.
500 * \param rect A pointer to the destination rectangle, or NULL for the entire
503 * \return 0 on success, or -1 on error
505 extern DECLSPEC int SDLCALL SDL_RenderFillRect(SDL_Renderer * renderer,
506 const SDL_Rect * rect);
509 * \brief Fill some number of rectangles on the current rendering target with the drawing color.
511 * \param rects A pointer to an array of destination rectangles.
512 * \param count The number of rectangles.
514 * \return 0 on success, or -1 on error
516 extern DECLSPEC int SDLCALL SDL_RenderFillRects(SDL_Renderer * renderer,
517 const SDL_Rect ** rect,
521 * \brief Copy a portion of the texture to the current rendering target.
523 * \param texture The source texture.
524 * \param srcrect A pointer to the source rectangle, or NULL for the entire
526 * \param dstrect A pointer to the destination rectangle, or NULL for the
527 * entire rendering target.
529 * \return 0 on success, or -1 on error
531 extern DECLSPEC int SDLCALL SDL_RenderCopy(SDL_Renderer * renderer,
532 SDL_Texture * texture,
533 const SDL_Rect * srcrect,
534 const SDL_Rect * dstrect);
537 * \brief Read pixels from the current rendering target.
539 * \param rect A pointer to the rectangle to read, or NULL for the entire
541 * \param format The desired format of the pixel data, or 0 to use the format
542 * of the rendering target
543 * \param pixels A pointer to be filled in with the pixel data
544 * \param pitch The pitch of the pixels parameter.
546 * \return 0 on success, or -1 if pixel reading is not supported.
548 * \warning This is a very slow operation, and should not be used frequently.
550 extern DECLSPEC int SDLCALL SDL_RenderReadPixels(SDL_Renderer * renderer,
551 const SDL_Rect * rect,
553 void *pixels, int pitch);
556 * \brief Update the screen with rendering performed.
558 extern DECLSPEC void SDLCALL SDL_RenderPresent(SDL_Renderer * renderer);
561 * \brief Destroy the specified texture.
563 * \sa SDL_CreateTexture()
564 * \sa SDL_CreateTextureFromSurface()
566 extern DECLSPEC void SDLCALL SDL_DestroyTexture(SDL_Texture * texture);
569 * \brief Destroy the rendering context for a window and free associated
572 * \sa SDL_CreateRenderer()
574 extern DECLSPEC void SDLCALL SDL_DestroyRenderer(SDL_Renderer * renderer);
577 /* Ends C function definitions when using C++ */
583 #include "close_code.h"
585 #endif /* _SDL_render_h */
587 /* vi: set ts=4 sw=4 expandtab: */