The rendering functions take a context so it's clear what window they're drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
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.
32 #include "SDL_stdinc.h"
33 //#include "SDL_pixels.h"
35 #include "SDL_video.h"
37 #include "begin_code.h"
38 /* Set up for C function definitions, even when using C++ */
46 * \brief Flags used when creating a rendering context
50 SDL_RENDERER_ACCELERATED = 0x00000001, /**< The renderer uses hardware
52 SDL_RENDERER_PRESENTVSYNC = 0x00000002 /**< Present is synchronized
53 with the refresh rate */
57 * \brief Information on the capabilities of a render driver or context.
59 typedef struct SDL_RendererInfo
61 const char *name; /**< The name of the renderer */
62 Uint32 flags; /**< Supported ::SDL_RendererFlags */
63 Uint32 num_texture_formats; /**< The number of available texture formats */
64 Uint32 texture_formats[50]; /**< The available texture formats */
65 int max_texture_width; /**< The maximimum texture width */
66 int max_texture_height; /**< The maximimum texture height */
70 * \brief The access pattern allowed for a texture.
74 SDL_TEXTUREACCESS_STATIC, /**< Changes rarely, not lockable */
75 SDL_TEXTUREACCESS_STREAMING /**< Changes frequently, lockable */
79 * \brief The texture channel modulation used in SDL_RenderCopy().
83 SDL_TEXTUREMODULATE_NONE = 0x00000000, /**< No modulation */
84 SDL_TEXTUREMODULATE_COLOR = 0x00000001, /**< srcC = srcC * color */
85 SDL_TEXTUREMODULATE_ALPHA = 0x00000002 /**< srcA = srcA * alpha */
86 } SDL_TextureModulate;
89 * \brief A structure representing rendering state
92 typedef struct SDL_Renderer SDL_Renderer;
95 * \brief An efficient driver-specific representation of pixel data
98 typedef struct SDL_Texture SDL_Texture;
101 /* Function prototypes */
104 * \brief Get the number of 2D rendering drivers available for the current
107 * A render driver is a set of code that handles rendering and texture
108 * management on a particular display. Normally there is only one, but
109 * some drivers may have several available with different capabilities.
111 * \sa SDL_GetRenderDriverInfo()
112 * \sa SDL_CreateRenderer()
114 extern DECLSPEC int SDLCALL SDL_GetNumRenderDrivers(void);
117 * \brief Get information about a specific 2D rendering driver for the current
120 * \param index The index of the driver to query information about.
121 * \param info A pointer to an SDL_RendererInfo struct to be filled with
122 * information on the rendering driver.
124 * \return 0 on success, -1 if the index was out of range.
126 * \sa SDL_CreateRenderer()
128 extern DECLSPEC int SDLCALL SDL_GetRenderDriverInfo(int index,
129 SDL_RendererInfo * info);
132 * \brief Create a 2D rendering context for a window.
134 * \param window The window where rendering is displayed.
135 * \param index The index of the rendering driver to initialize, or -1 to
136 * initialize the first one supporting the requested flags.
137 * \param flags ::SDL_RendererFlags.
139 * \return A valid rendering context or NULL if there was an error.
141 * \sa SDL_GetRendererInfo()
142 * \sa SDL_DestroyRenderer()
144 extern DECLSPEC SDL_Renderer * SDLCALL SDL_CreateRenderer(SDL_Window * window,
145 int index, Uint32 flags);
148 * \brief Get information about a rendering context.
150 extern DECLSPEC int SDLCALL SDL_GetRendererInfo(SDL_Renderer * renderer,
151 SDL_RendererInfo * info);
154 * \brief Create a texture for a rendering context.
156 * \param format The format of the texture.
157 * \param access One of the enumerated values in ::SDL_TextureAccess.
158 * \param w The width of the texture in pixels.
159 * \param h The height of the texture in pixels.
161 * \return The created texture is returned, or 0 if no rendering context was
162 * active, the format was unsupported, or the width or height were out
165 * \sa SDL_QueryTexture()
166 * \sa SDL_DestroyTexture()
168 extern DECLSPEC SDL_Texture * SDLCALL SDL_CreateTexture(SDL_Renderer * renderer, Uint32 format,
173 * \brief Create a texture from an existing surface.
175 * \param format The format of the texture, or 0 to pick an appropriate format.
176 * \param surface The surface containing pixel data used to fill the texture.
178 * \return The created texture is returned, or 0 if no rendering context was
179 * active, the format was unsupported, or the surface width or height
182 * \note The surface is not modified or freed by this function.
184 * \sa SDL_QueryTexture()
185 * \sa SDL_DestroyTexture()
187 extern DECLSPEC SDL_Texture * SDLCALL SDL_CreateTextureFromSurface(SDL_Renderer * renderer, Uint32 format, SDL_Surface * surface);
190 * \brief Query the attributes of a texture
192 * \param texture A texture to be queried.
193 * \param format A pointer filled in with the raw format of the texture. The
194 * actual format may differ, but pixel transfers will use this
196 * \param access A pointer filled in with the actual access to the texture.
197 * \param w A pointer filled in with the width of the texture in pixels.
198 * \param h A pointer filled in with the height of the texture in pixels.
200 * \return 0 on success, or -1 if the texture is not valid.
202 extern DECLSPEC int SDLCALL SDL_QueryTexture(SDL_Texture * texture,
203 Uint32 * format, int *access,
207 * \brief Query the pixels of a texture, if the texture does not need to be
208 * locked for pixel access.
210 * \param texture A texture to be queried, which was created with
211 * ::SDL_TEXTUREACCESS_STREAMING.
212 * \param pixels A pointer filled with a pointer to the pixels for the
214 * \param pitch A pointer filled in with the pitch of the pixel data.
216 * \return 0 on success, or -1 if the texture is not valid, or must be locked
219 extern DECLSPEC int SDLCALL SDL_QueryTexturePixels(SDL_Texture * texture,
220 void **pixels, int *pitch);
223 * \brief Set the color palette of an indexed texture.
225 * \param texture The texture to update.
226 * \param colors The array of RGB color data.
227 * \param firstcolor The first index to update.
228 * \param ncolors The number of palette entries to fill with the color data.
230 * \return 0 on success, or -1 if the texture is not valid or not an indexed
233 extern DECLSPEC int SDLCALL SDL_SetTexturePalette(SDL_Texture * texture,
234 const SDL_Color * colors,
239 * \brief Get the color palette from an indexed texture if it has one.
241 * \param texture The texture to update.
242 * \param colors The array to fill with RGB color data.
243 * \param firstcolor The first index to retrieve.
244 * \param ncolors The number of palette entries to retrieve.
246 * \return 0 on success, or -1 if the texture is not valid or not an indexed
249 extern DECLSPEC int SDLCALL SDL_GetTexturePalette(SDL_Texture * texture,
255 * \brief Set an additional color value used in render copy operations.
257 * \param texture The texture to update.
258 * \param r The red color value multiplied into copy operations.
259 * \param g The green color value multiplied into copy operations.
260 * \param b The blue color value multiplied into copy operations.
262 * \return 0 on success, or -1 if the texture is not valid or color modulation
265 * \sa SDL_GetTextureColorMod()
267 extern DECLSPEC int SDLCALL SDL_SetTextureColorMod(SDL_Texture * texture,
268 Uint8 r, Uint8 g, Uint8 b);
272 * \brief Get the additional color value used in render copy operations.
274 * \param texture The texture to query.
275 * \param r A pointer filled in with the current red color value.
276 * \param g A pointer filled in with the current green color value.
277 * \param b A pointer filled in with the current blue color value.
279 * \return 0 on success, or -1 if the texture is not valid.
281 * \sa SDL_SetTextureColorMod()
283 extern DECLSPEC int SDLCALL SDL_GetTextureColorMod(SDL_Texture * texture,
284 Uint8 * r, Uint8 * g,
288 * \brief Set an additional alpha value used in render copy operations.
290 * \param texture The texture to update.
291 * \param alpha The alpha value multiplied into copy operations.
293 * \return 0 on success, or -1 if the texture is not valid or alpha modulation
296 * \sa SDL_GetTextureAlphaMod()
298 extern DECLSPEC int SDLCALL SDL_SetTextureAlphaMod(SDL_Texture * texture,
302 * \brief Get the additional alpha value used in render copy operations.
304 * \param texture The texture to query.
305 * \param alpha A pointer filled in with the current alpha value.
307 * \return 0 on success, or -1 if the texture is not valid.
309 * \sa SDL_SetTextureAlphaMod()
311 extern DECLSPEC int SDLCALL SDL_GetTextureAlphaMod(SDL_Texture * texture,
315 * \brief Set the blend mode used for texture copy operations.
317 * \param texture The texture to update.
318 * \param blendMode ::SDL_BlendMode to use for texture blending.
320 * \return 0 on success, or -1 if the texture is not valid or the blend mode is
323 * \note If the blend mode is not supported, the closest supported mode is
326 * \sa SDL_GetTextureBlendMode()
328 extern DECLSPEC int SDLCALL SDL_SetTextureBlendMode(SDL_Texture * texture,
329 SDL_BlendMode blendMode);
332 * \brief Get the blend mode used for texture copy operations.
334 * \param texture The texture to query.
335 * \param blendMode A pointer filled in with the current blend mode.
337 * \return 0 on success, or -1 if the texture is not valid.
339 * \sa SDL_SetTextureBlendMode()
341 extern DECLSPEC int SDLCALL SDL_GetTextureBlendMode(SDL_Texture * texture,
342 SDL_BlendMode *blendMode);
345 * \brief Update the given texture rectangle with new pixel data.
347 * \param texture The texture to update
348 * \param rect A pointer to the rectangle of pixels to update, or NULL to
349 * update the entire texture.
350 * \param pixels The raw pixel data.
351 * \param pitch The number of bytes between rows of pixel data.
353 * \return 0 on success, or -1 if the texture is not valid.
355 * \note This is a fairly slow function.
357 extern DECLSPEC int SDLCALL SDL_UpdateTexture(SDL_Texture * texture,
358 const SDL_Rect * rect,
359 const void *pixels, int pitch);
362 * \brief Lock a portion of the texture for pixel access.
364 * \param texture The texture to lock for access, which was created with
365 * ::SDL_TEXTUREACCESS_STREAMING.
366 * \param rect A pointer to the rectangle to lock for access. If the rect
367 * is NULL, the entire texture will be locked.
368 * \param markDirty If this is nonzero, the locked area will be marked dirty
369 * when the texture is unlocked.
370 * \param pixels This is filled in with a pointer to the locked pixels,
371 * appropriately offset by the locked area.
372 * \param pitch This is filled in with the pitch of the locked pixels.
374 * \return 0 on success, or -1 if the texture is not valid or was created with
375 * ::SDL_TEXTUREACCESS_STATIC.
377 * \sa SDL_DirtyTexture()
378 * \sa SDL_UnlockTexture()
380 extern DECLSPEC int SDLCALL SDL_LockTexture(SDL_Texture * texture,
381 const SDL_Rect * rect,
382 int markDirty, void **pixels,
386 * \brief Unlock a texture, uploading the changes to renderer memory, if needed.
388 * \sa SDL_LockTexture()
389 * \sa SDL_DirtyTexture()
391 extern DECLSPEC void SDLCALL SDL_UnlockTexture(SDL_Texture * texture);
394 * \brief Mark the specified rectangles of the texture as dirty.
396 * \param texture The texture to mark dirty, which was created with
397 * ::SDL_TEXTUREACCESS_STREAMING.
398 * \param numrects The number of rectangles pointed to by rects.
399 * \param rects The pointer to an array of dirty rectangles.
401 * \sa SDL_LockTexture()
402 * \sa SDL_UnlockTexture()
404 extern DECLSPEC void SDLCALL SDL_DirtyTexture(SDL_Texture * texture,
406 const SDL_Rect * rects);
409 * \brief Set the color used for drawing operations (Fill and Line).
411 * \param r The red value used to draw on the rendering target.
412 * \param g The green value used to draw on the rendering target.
413 * \param b The blue value used to draw on the rendering target.
414 * \param a The alpha value used to draw on the rendering target, usually
415 * ::SDL_ALPHA_OPAQUE (255).
417 * \return 0 on success, or -1 on error
419 extern DECLSPEC int SDL_SetRenderDrawColor(SDL_Renderer * renderer,
420 Uint8 r, Uint8 g, Uint8 b,
424 * \brief Get the color used for drawing operations (Fill and Line).
426 * \param r A pointer to the red value used to draw on the rendering target.
427 * \param g A pointer to the green value used to draw on the rendering target.
428 * \param b A pointer to the blue value used to draw on the rendering target.
429 * \param a A pointer to the alpha value used to draw on the rendering target,
430 * usually ::SDL_ALPHA_OPAQUE (255).
432 * \return 0 on success, or -1 on error
434 extern DECLSPEC int SDL_GetRenderDrawColor(SDL_Renderer * renderer,
435 Uint8 * r, Uint8 * g, Uint8 * b,
439 * \brief Set the blend mode used for drawing operations (Fill and Line).
441 * \param blendMode ::SDL_BlendMode to use for blending.
443 * \return 0 on success, or -1 on error
445 * \note If the blend mode is not supported, the closest supported mode is
448 * \sa SDL_GetRenderDrawBlendMode()
450 extern DECLSPEC int SDLCALL SDL_SetRenderDrawBlendMode(SDL_Renderer * renderer,
451 SDL_BlendMode blendMode);
454 * \brief Get the blend mode used for drawing operations.
456 * \param blendMode A pointer filled in with the current blend mode.
458 * \return 0 on success, or -1 on error
460 * \sa SDL_SetRenderDrawBlendMode()
462 extern DECLSPEC int SDLCALL SDL_GetRenderDrawBlendMode(SDL_Renderer * renderer,
463 SDL_BlendMode *blendMode);
466 * \brief Clear the current rendering target with the drawing color
468 extern DECLSPEC int SDLCALL SDL_RenderClear(SDL_Renderer * renderer);
471 * \brief Draw a point on the current rendering target.
473 * \param x The x coordinate of the point.
474 * \param y The y coordinate of the point.
476 * \return 0 on success, or -1 on error
478 extern DECLSPEC int SDLCALL SDL_RenderDrawPoint(SDL_Renderer * renderer,
482 * \brief Draw multiple points on the current rendering target.
484 * \param points The points to draw
485 * \param count The number of points to draw
487 * \return 0 on success, or -1 on error
489 extern DECLSPEC int SDLCALL SDL_RenderDrawPoints(SDL_Renderer * renderer,
490 const SDL_Point * points,
494 * \brief Draw a line on the current rendering target.
496 * \param x1 The x coordinate of the start point.
497 * \param y1 The y coordinate of the start point.
498 * \param x2 The x coordinate of the end point.
499 * \param y2 The y coordinate of the end point.
501 * \return 0 on success, or -1 on error
503 extern DECLSPEC int SDLCALL SDL_RenderDrawLine(SDL_Renderer * renderer,
504 int x1, int y1, int x2, int y2);
507 * \brief Draw a series of connected lines on the current rendering target.
509 * \param points The points along the lines
510 * \param count The number of points, drawing count-1 lines
512 * \return 0 on success, or -1 on error
514 extern DECLSPEC int SDLCALL SDL_RenderDrawLines(SDL_Renderer * renderer,
515 const SDL_Point * points,
519 * \brief Draw a rectangle on the current rendering target.
521 * \param rect A pointer to the destination rectangle, or NULL to outline the entire rendering target.
523 * \return 0 on success, or -1 on error
525 extern DECLSPEC int SDLCALL SDL_RenderDrawRect(SDL_Renderer * renderer,
526 const SDL_Rect * rect);
529 * \brief Draw some number of rectangles on the current rendering target.
531 * \param rects A pointer to an array of destination rectangles.
532 * \param count The number of rectangles.
534 * \return 0 on success, or -1 on error
536 extern DECLSPEC int SDLCALL SDL_RenderDrawRects(SDL_Renderer * renderer,
537 const SDL_Rect ** rects,
541 * \brief Fill a rectangle on the current rendering target with the drawing color.
543 * \param rect A pointer to the destination rectangle, or NULL for the entire
546 * \return 0 on success, or -1 on error
548 extern DECLSPEC int SDLCALL SDL_RenderFillRect(SDL_Renderer * renderer,
549 const SDL_Rect * rect);
552 * \brief Fill some number of rectangles on the current rendering target with the drawing color.
554 * \param rects A pointer to an array of destination rectangles.
555 * \param count The number of rectangles.
557 * \return 0 on success, or -1 on error
559 extern DECLSPEC int SDLCALL SDL_RenderFillRects(SDL_Renderer * renderer,
560 const SDL_Rect ** rect,
564 * \brief Copy a portion of the texture to the current rendering target.
566 * \param texture The source texture.
567 * \param srcrect A pointer to the source rectangle, or NULL for the entire
569 * \param dstrect A pointer to the destination rectangle, or NULL for the
570 * entire rendering target.
572 * \return 0 on success, or -1 on error
574 extern DECLSPEC int SDLCALL SDL_RenderCopy(SDL_Renderer * renderer,
575 SDL_Texture * texture,
576 const SDL_Rect * srcrect,
577 const SDL_Rect * dstrect);
580 * \brief Read pixels from the current rendering target.
582 * \param rect A pointer to the rectangle to read, or NULL for the entire
584 * \param format The desired format of the pixel data, or 0 to use the format
585 * of the rendering target
586 * \param pixels A pointer to be filled in with the pixel data
587 * \param pitch The pitch of the pixels parameter.
589 * \return 0 on success, or -1 if pixel reading is not supported.
591 * \warning This is a very slow operation, and should not be used frequently.
593 extern DECLSPEC int SDLCALL SDL_RenderReadPixels(SDL_Renderer * renderer,
594 const SDL_Rect * rect,
596 void *pixels, int pitch);
599 * \brief Write pixels to the current rendering target.
601 * \param rect A pointer to the rectangle to write, or NULL for the entire
603 * \param format The format of the pixel data, or 0 to use the format
604 * of the rendering target
605 * \param pixels A pointer to the pixel data to write.
606 * \param pitch The pitch of the pixels parameter.
608 * \return 0 on success, or -1 if pixel writing is not supported.
610 * \warning This is a very slow operation, and should not be used frequently.
612 extern DECLSPEC int SDLCALL SDL_RenderWritePixels(SDL_Renderer * renderer,
613 const SDL_Rect * rect,
619 * \brief Update the screen with rendering performed.
621 extern DECLSPEC void SDLCALL SDL_RenderPresent(SDL_Renderer * renderer);
624 * \brief Destroy the specified texture.
626 * \sa SDL_CreateTexture()
627 * \sa SDL_CreateTextureFromSurface()
629 extern DECLSPEC void SDLCALL SDL_DestroyTexture(SDL_Texture * texture);
632 * \brief Destroy the rendering context for a window and free associated
635 * \sa SDL_CreateRenderer()
637 extern DECLSPEC void SDLCALL SDL_DestroyRenderer(SDL_Renderer * renderer);
640 /* Ends C function definitions when using C++ */
646 #include "close_code.h"
648 #endif /* _SDL_render_h */
650 /* vi: set ts=4 sw=4 expandtab: */