SDL_ExitProcess() was ignoring exit code parameter.
2 Simple DirectMedia Layer
3 Copyright (C) 1997-2012 Sam Lantinga <slouken@libsdl.org>
5 This software is provided 'as-is', without any express or implied
6 warranty. In no event will the authors be held liable for any damages
7 arising from the use of this software.
9 Permission is granted to anyone to use this software for any purpose,
10 including commercial applications, and to alter it and redistribute it
11 freely, subject to the following restrictions:
13 1. The origin of this software must not be misrepresented; you must not
14 claim that you wrote the original software. If you use this software
15 in a product, an acknowledgment in the product documentation would be
16 appreciated but is not required.
17 2. Altered source versions must be plainly marked as such, and must not be
18 misrepresented as being the original software.
19 3. This notice may not be removed or altered from any source distribution.
25 * Header file for SDL 2D rendering functions.
27 * This API supports the following features:
28 * * single pixel points
29 * * single pixel lines
33 * The primitives may be drawn in opaque, blended, or additive modes.
35 * The texture images may be drawn in opaque, blended, or additive modes.
36 * They can have an additional color tint or alpha modulation applied to
37 * them, and may also be stretched with linear interpolation.
39 * This API is designed to accelerate simple 2D operations. You may
40 * want more functionality such as rotation and particle effects and
41 * in that case you should use SDL's OpenGL/Direct3D support or one
42 * of the many good 3D engines.
48 #include "SDL_stdinc.h"
50 #include "SDL_video.h"
52 #include "begin_code.h"
53 /* Set up for C function definitions, even when using C++ */
61 * \brief Flags used when creating a rendering context
65 SDL_RENDERER_SOFTWARE = 0x00000001, /**< The renderer is a software fallback */
66 SDL_RENDERER_ACCELERATED = 0x00000002, /**< The renderer uses hardware
68 SDL_RENDERER_PRESENTVSYNC = 0x00000004, /**< Present is synchronized
69 with the refresh rate */
70 SDL_RENDERER_TARGETTEXTURE = 0x00000008 /**< The renderer supports
71 rendering to texture */
75 * \brief Information on the capabilities of a render driver or context.
77 typedef struct SDL_RendererInfo
79 const char *name; /**< The name of the renderer */
80 Uint32 flags; /**< Supported ::SDL_RendererFlags */
81 Uint32 num_texture_formats; /**< The number of available texture formats */
82 Uint32 texture_formats[16]; /**< The available texture formats */
83 int max_texture_width; /**< The maximimum texture width */
84 int max_texture_height; /**< The maximimum texture height */
88 * \brief The access pattern allowed for a texture.
92 SDL_TEXTUREACCESS_STATIC, /**< Changes rarely, not lockable */
93 SDL_TEXTUREACCESS_STREAMING, /**< Changes frequently, lockable */
94 SDL_TEXTUREACCESS_TARGET /**< Texture can be used as a render target */
98 * \brief The texture channel modulation used in SDL_RenderCopy().
102 SDL_TEXTUREMODULATE_NONE = 0x00000000, /**< No modulation */
103 SDL_TEXTUREMODULATE_COLOR = 0x00000001, /**< srcC = srcC * color */
104 SDL_TEXTUREMODULATE_ALPHA = 0x00000002 /**< srcA = srcA * alpha */
105 } SDL_TextureModulate;
108 * \brief A structure representing rendering state
111 typedef struct SDL_Renderer SDL_Renderer;
114 * \brief An efficient driver-specific representation of pixel data
117 typedef struct SDL_Texture SDL_Texture;
120 /* Function prototypes */
123 * \brief Get the number of 2D rendering drivers available for the current
126 * A render driver is a set of code that handles rendering and texture
127 * management on a particular display. Normally there is only one, but
128 * some drivers may have several available with different capabilities.
130 * \sa SDL_GetRenderDriverInfo()
131 * \sa SDL_CreateRenderer()
133 extern DECLSPEC int SDLCALL SDL_GetNumRenderDrivers(void);
136 * \brief Get information about a specific 2D rendering driver for the current
139 * \param index The index of the driver to query information about.
140 * \param info A pointer to an SDL_RendererInfo struct to be filled with
141 * information on the rendering driver.
143 * \return 0 on success, -1 if the index was out of range.
145 * \sa SDL_CreateRenderer()
147 extern DECLSPEC int SDLCALL SDL_GetRenderDriverInfo(int index,
148 SDL_RendererInfo * info);
151 * \brief Create a window and default renderer
153 * \param width The width of the window
154 * \param height The height of the window
155 * \param window_flags The flags used to create the window
156 * \param window A pointer filled with the window, or NULL on error
157 * \param renderer A pointer filled with the renderer, or NULL on error
159 * \return 0 on success, or -1 on error
161 extern DECLSPEC int SDLCALL SDL_CreateWindowAndRenderer(
162 int width, int height, Uint32 window_flags,
163 SDL_Window **window, SDL_Renderer **renderer);
167 * \brief Create a 2D rendering context for a window.
169 * \param window The window where rendering is displayed.
170 * \param index The index of the rendering driver to initialize, or -1 to
171 * initialize the first one supporting the requested flags.
172 * \param flags ::SDL_RendererFlags.
174 * \return A valid rendering context or NULL if there was an error.
176 * \sa SDL_CreateSoftwareRenderer()
177 * \sa SDL_GetRendererInfo()
178 * \sa SDL_DestroyRenderer()
180 extern DECLSPEC SDL_Renderer * SDLCALL SDL_CreateRenderer(SDL_Window * window,
181 int index, Uint32 flags);
184 * \brief Create a 2D software rendering context for a surface.
186 * \param surface The surface where rendering is done.
188 * \return A valid rendering context or NULL if there was an error.
190 * \sa SDL_CreateRenderer()
191 * \sa SDL_DestroyRenderer()
193 extern DECLSPEC SDL_Renderer * SDLCALL SDL_CreateSoftwareRenderer(SDL_Surface * surface);
196 * \brief Get the renderer associated with a window.
198 extern DECLSPEC SDL_Renderer * SDLCALL SDL_GetRenderer(SDL_Window * window);
201 * \brief Get information about a rendering context.
203 extern DECLSPEC int SDLCALL SDL_GetRendererInfo(SDL_Renderer * renderer,
204 SDL_RendererInfo * info);
207 * \brief Create a texture for a rendering context.
209 * \param format The format of the texture.
210 * \param access One of the enumerated values in ::SDL_TextureAccess.
211 * \param w The width of the texture in pixels.
212 * \param h The height of the texture in pixels.
214 * \return The created texture is returned, or 0 if no rendering context was
215 * active, the format was unsupported, or the width or height were out
218 * \sa SDL_QueryTexture()
219 * \sa SDL_UpdateTexture()
220 * \sa SDL_DestroyTexture()
222 extern DECLSPEC SDL_Texture * SDLCALL SDL_CreateTexture(SDL_Renderer * renderer,
228 * \brief Create a texture from an existing surface.
230 * \param surface The surface containing pixel data used to fill the texture.
232 * \return The created texture is returned, or 0 on error.
234 * \note The surface is not modified or freed by this function.
236 * \sa SDL_QueryTexture()
237 * \sa SDL_DestroyTexture()
239 extern DECLSPEC SDL_Texture * SDLCALL SDL_CreateTextureFromSurface(SDL_Renderer * renderer, SDL_Surface * surface);
242 * \brief Query the attributes of a texture
244 * \param texture A texture to be queried.
245 * \param format A pointer filled in with the raw format of the texture. The
246 * actual format may differ, but pixel transfers will use this
248 * \param access A pointer filled in with the actual access to the texture.
249 * \param w A pointer filled in with the width of the texture in pixels.
250 * \param h A pointer filled in with the height of the texture in pixels.
252 * \return 0 on success, or -1 if the texture is not valid.
254 extern DECLSPEC int SDLCALL SDL_QueryTexture(SDL_Texture * texture,
255 Uint32 * format, int *access,
259 * \brief Set an additional color value used in render copy operations.
261 * \param texture The texture to update.
262 * \param r The red color value multiplied into copy operations.
263 * \param g The green color value multiplied into copy operations.
264 * \param b The blue color value multiplied into copy operations.
266 * \return 0 on success, or -1 if the texture is not valid or color modulation
269 * \sa SDL_GetTextureColorMod()
271 extern DECLSPEC int SDLCALL SDL_SetTextureColorMod(SDL_Texture * texture,
272 Uint8 r, Uint8 g, Uint8 b);
276 * \brief Get the additional color value used in render copy operations.
278 * \param texture The texture to query.
279 * \param r A pointer filled in with the current red color value.
280 * \param g A pointer filled in with the current green color value.
281 * \param b A pointer filled in with the current blue color value.
283 * \return 0 on success, or -1 if the texture is not valid.
285 * \sa SDL_SetTextureColorMod()
287 extern DECLSPEC int SDLCALL SDL_GetTextureColorMod(SDL_Texture * texture,
288 Uint8 * r, Uint8 * g,
292 * \brief Set an additional alpha value used in render copy operations.
294 * \param texture The texture to update.
295 * \param alpha The alpha value multiplied into copy operations.
297 * \return 0 on success, or -1 if the texture is not valid or alpha modulation
300 * \sa SDL_GetTextureAlphaMod()
302 extern DECLSPEC int SDLCALL SDL_SetTextureAlphaMod(SDL_Texture * texture,
306 * \brief Get the additional alpha value used in render copy operations.
308 * \param texture The texture to query.
309 * \param alpha A pointer filled in with the current alpha value.
311 * \return 0 on success, or -1 if the texture is not valid.
313 * \sa SDL_SetTextureAlphaMod()
315 extern DECLSPEC int SDLCALL SDL_GetTextureAlphaMod(SDL_Texture * texture,
319 * \brief Set the blend mode used for texture copy operations.
321 * \param texture The texture to update.
322 * \param blendMode ::SDL_BlendMode to use for texture blending.
324 * \return 0 on success, or -1 if the texture is not valid or the blend mode is
327 * \note If the blend mode is not supported, the closest supported mode is
330 * \sa SDL_GetTextureBlendMode()
332 extern DECLSPEC int SDLCALL SDL_SetTextureBlendMode(SDL_Texture * texture,
333 SDL_BlendMode blendMode);
336 * \brief Get the blend mode used for texture copy operations.
338 * \param texture The texture to query.
339 * \param blendMode A pointer filled in with the current blend mode.
341 * \return 0 on success, or -1 if the texture is not valid.
343 * \sa SDL_SetTextureBlendMode()
345 extern DECLSPEC int SDLCALL SDL_GetTextureBlendMode(SDL_Texture * texture,
346 SDL_BlendMode *blendMode);
349 * \brief Update the given texture rectangle with new pixel data.
351 * \param texture The texture to update
352 * \param rect A pointer to the rectangle of pixels to update, or NULL to
353 * update the entire texture.
354 * \param pixels The raw pixel data.
355 * \param pitch The number of bytes between rows of pixel data.
357 * \return 0 on success, or -1 if the texture is not valid.
359 * \note This is a fairly slow function.
361 extern DECLSPEC int SDLCALL SDL_UpdateTexture(SDL_Texture * texture,
362 const SDL_Rect * rect,
363 const void *pixels, int pitch);
366 * \brief Lock a portion of the texture for pixel access.
368 * \param texture The texture to lock for access, which was created with
369 * ::SDL_TEXTUREACCESS_STREAMING.
370 * \param rect A pointer to the rectangle to lock for access. If the rect
371 * is NULL, the entire texture will be locked.
372 * \param pixels This is filled in with a pointer to the locked pixels,
373 * appropriately offset by the locked area.
374 * \param pitch This is filled in with the pitch of the locked pixels.
376 * \return 0 on success, or -1 if the texture is not valid or was not created with ::SDL_TEXTUREACCESS_STREAMING.
378 * \sa SDL_UnlockTexture()
380 extern DECLSPEC int SDLCALL SDL_LockTexture(SDL_Texture * texture,
381 const SDL_Rect * rect,
382 void **pixels, int *pitch);
385 * \brief Unlock a texture, uploading the changes to video memory, if needed.
387 * \sa SDL_LockTexture()
389 extern DECLSPEC void SDLCALL SDL_UnlockTexture(SDL_Texture * texture);
392 * \brief Determines whether a window supports the use of render targets
394 * \param renderer The renderer that will be checked
396 * \return SDL_TRUE if supported, SDL_FALSE if not.
398 extern DECLSPEC SDL_bool SDLCALL SDL_RenderTargetSupported(SDL_Renderer *renderer);
401 * \brief Set a texture as the current rendering target.
403 * \param texture The targeted texture, which must be created with the SDL_TEXTUREACCESS_TARGET flag, or NULL for the default render target
405 * \return 0 on success, or -1 on error
407 extern DECLSPEC int SDLCALL SDL_SetRenderTarget(SDL_Renderer *renderer,
408 SDL_Texture *texture);
411 * \brief Set the drawing area for rendering on the current target.
413 * \param rect The rectangle representing the drawing area, or NULL to set the viewport to the entire target.
415 * The x,y of the viewport rect represents the origin for rendering.
417 * \note When the window is resized, the current viewport is automatically
418 * centered within the new window size.
420 extern DECLSPEC int SDLCALL SDL_RenderSetViewport(SDL_Renderer * renderer,
421 const SDL_Rect * rect);
424 * \brief Get the drawing area for the current target.
426 extern DECLSPEC void SDLCALL SDL_RenderGetViewport(SDL_Renderer * renderer,
430 * \brief Set the color used for drawing operations (Rect, Line and Clear).
432 * \param r The red value used to draw on the rendering target.
433 * \param g The green value used to draw on the rendering target.
434 * \param b The blue value used to draw on the rendering target.
435 * \param a The alpha value used to draw on the rendering target, usually
436 * ::SDL_ALPHA_OPAQUE (255).
438 * \return 0 on success, or -1 on error
440 extern DECLSPEC int SDL_SetRenderDrawColor(SDL_Renderer * renderer,
441 Uint8 r, Uint8 g, Uint8 b,
445 * \brief Get the color used for drawing operations (Rect, Line and Clear).
447 * \param r A pointer to the red value used to draw on the rendering target.
448 * \param g A pointer to the green value used to draw on the rendering target.
449 * \param b A pointer to the blue value used to draw on the rendering target.
450 * \param a A pointer to the alpha value used to draw on the rendering target,
451 * usually ::SDL_ALPHA_OPAQUE (255).
453 * \return 0 on success, or -1 on error
455 extern DECLSPEC int SDL_GetRenderDrawColor(SDL_Renderer * renderer,
456 Uint8 * r, Uint8 * g, Uint8 * b,
460 * \brief Set the blend mode used for drawing operations (Fill and Line).
462 * \param blendMode ::SDL_BlendMode to use for blending.
464 * \return 0 on success, or -1 on error
466 * \note If the blend mode is not supported, the closest supported mode is
469 * \sa SDL_GetRenderDrawBlendMode()
471 extern DECLSPEC int SDLCALL SDL_SetRenderDrawBlendMode(SDL_Renderer * renderer,
472 SDL_BlendMode blendMode);
475 * \brief Get the blend mode used for drawing operations.
477 * \param blendMode A pointer filled in with the current blend mode.
479 * \return 0 on success, or -1 on error
481 * \sa SDL_SetRenderDrawBlendMode()
483 extern DECLSPEC int SDLCALL SDL_GetRenderDrawBlendMode(SDL_Renderer * renderer,
484 SDL_BlendMode *blendMode);
487 * \brief Clear the current rendering target with the drawing color
489 * This function clears the entire rendering target, ignoring the viewport.
491 extern DECLSPEC int SDLCALL SDL_RenderClear(SDL_Renderer * renderer);
494 * \brief Draw a point on the current rendering target.
496 * \param x The x coordinate of the point.
497 * \param y The y coordinate of the point.
499 * \return 0 on success, or -1 on error
501 extern DECLSPEC int SDLCALL SDL_RenderDrawPoint(SDL_Renderer * renderer,
505 * \brief Draw multiple points on the current rendering target.
507 * \param points The points to draw
508 * \param count The number of points to draw
510 * \return 0 on success, or -1 on error
512 extern DECLSPEC int SDLCALL SDL_RenderDrawPoints(SDL_Renderer * renderer,
513 const SDL_Point * points,
517 * \brief Draw a line on the current rendering target.
519 * \param x1 The x coordinate of the start point.
520 * \param y1 The y coordinate of the start point.
521 * \param x2 The x coordinate of the end point.
522 * \param y2 The y coordinate of the end point.
524 * \return 0 on success, or -1 on error
526 extern DECLSPEC int SDLCALL SDL_RenderDrawLine(SDL_Renderer * renderer,
527 int x1, int y1, int x2, int y2);
530 * \brief Draw a series of connected lines on the current rendering target.
532 * \param points The points along the lines
533 * \param count The number of points, drawing count-1 lines
535 * \return 0 on success, or -1 on error
537 extern DECLSPEC int SDLCALL SDL_RenderDrawLines(SDL_Renderer * renderer,
538 const SDL_Point * points,
542 * \brief Draw a rectangle on the current rendering target.
544 * \param rect A pointer to the destination rectangle, or NULL to outline the entire rendering target.
546 * \return 0 on success, or -1 on error
548 extern DECLSPEC int SDLCALL SDL_RenderDrawRect(SDL_Renderer * renderer,
549 const SDL_Rect * rect);
552 * \brief Draw some number of rectangles on the current rendering target.
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_RenderDrawRects(SDL_Renderer * renderer,
560 const SDL_Rect * rects,
564 * \brief Fill a rectangle on the current rendering target with the drawing color.
566 * \param rect A pointer to the destination rectangle, or NULL for the entire
569 * \return 0 on success, or -1 on error
571 extern DECLSPEC int SDLCALL SDL_RenderFillRect(SDL_Renderer * renderer,
572 const SDL_Rect * rect);
575 * \brief Fill some number of rectangles on the current rendering target with the drawing color.
577 * \param rects A pointer to an array of destination rectangles.
578 * \param count The number of rectangles.
580 * \return 0 on success, or -1 on error
582 extern DECLSPEC int SDLCALL SDL_RenderFillRects(SDL_Renderer * renderer,
583 const SDL_Rect * rects,
587 * \brief Copy a portion of the texture to the current rendering target.
589 * \param texture The source texture.
590 * \param srcrect A pointer to the source rectangle, or NULL for the entire
592 * \param dstrect A pointer to the destination rectangle, or NULL for the
593 * entire rendering target.
595 * \return 0 on success, or -1 on error
597 extern DECLSPEC int SDLCALL SDL_RenderCopy(SDL_Renderer * renderer,
598 SDL_Texture * texture,
599 const SDL_Rect * srcrect,
600 const SDL_Rect * dstrect);
604 * \brief Read pixels from the current rendering target.
606 * \param rect A pointer to the rectangle to read, or NULL for the entire
608 * \param format The desired format of the pixel data, or 0 to use the format
609 * of the rendering target
610 * \param pixels A pointer to be filled in with the pixel data
611 * \param pitch The pitch of the pixels parameter.
613 * \return 0 on success, or -1 if pixel reading is not supported.
615 * \warning This is a very slow operation, and should not be used frequently.
617 extern DECLSPEC int SDLCALL SDL_RenderReadPixels(SDL_Renderer * renderer,
618 const SDL_Rect * rect,
620 void *pixels, int pitch);
623 * \brief Update the screen with rendering performed.
625 extern DECLSPEC void SDLCALL SDL_RenderPresent(SDL_Renderer * renderer);
628 * \brief Destroy the specified texture.
630 * \sa SDL_CreateTexture()
631 * \sa SDL_CreateTextureFromSurface()
633 extern DECLSPEC void SDLCALL SDL_DestroyTexture(SDL_Texture * texture);
636 * \brief Destroy the rendering context for a window and free associated
639 * \sa SDL_CreateRenderer()
641 extern DECLSPEC void SDLCALL SDL_DestroyRenderer(SDL_Renderer * renderer);
644 /* Ends C function definitions when using C++ */
650 #include "close_code.h"
652 #endif /* _SDL_render_h */
654 /* vi: set ts=4 sw=4 expandtab: */