2
Simple DirectMedia Layer
3
Copyright (C) 1997-2011 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 */
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 the renderer associated with a window.
179
extern DECLSPEC SDL_Renderer * SDLCALL SDL_GetRenderer(SDL_Window * window);
182
* \brief Get information about a rendering context.
184
extern DECLSPEC int SDLCALL SDL_GetRendererInfo(SDL_Renderer * renderer,
185
SDL_RendererInfo * info);
188
* \brief Create a texture for a rendering context.
190
* \param format The format of the texture.
191
* \param access One of the enumerated values in ::SDL_TextureAccess.
192
* \param w The width of the texture in pixels.
193
* \param h The height of the texture in pixels.
195
* \return The created texture is returned, or 0 if no rendering context was
196
* active, the format was unsupported, or the width or height were out
199
* \sa SDL_QueryTexture()
200
* \sa SDL_UpdateTexture()
201
* \sa SDL_DestroyTexture()
203
extern DECLSPEC SDL_Texture * SDLCALL SDL_CreateTexture(SDL_Renderer * renderer,
209
* \brief Create a texture from an existing surface.
211
* \param surface The surface containing pixel data used to fill the texture.
213
* \return The created texture is returned, or 0 on error.
215
* \note The surface is not modified or freed by this function.
217
* \sa SDL_QueryTexture()
218
* \sa SDL_DestroyTexture()
220
extern DECLSPEC SDL_Texture * SDLCALL SDL_CreateTextureFromSurface(SDL_Renderer * renderer, SDL_Surface * surface);
223
* \brief Query the attributes of a texture
225
* \param texture A texture to be queried.
226
* \param format A pointer filled in with the raw format of the texture. The
227
* actual format may differ, but pixel transfers will use this
229
* \param access A pointer filled in with the actual access to the texture.
230
* \param w A pointer filled in with the width of the texture in pixels.
231
* \param h A pointer filled in with the height of the texture in pixels.
233
* \return 0 on success, or -1 if the texture is not valid.
235
extern DECLSPEC int SDLCALL SDL_QueryTexture(SDL_Texture * texture,
236
Uint32 * format, int *access,
240
* \brief Set an additional color value used in render copy operations.
242
* \param texture The texture to update.
243
* \param r The red color value multiplied into copy operations.
244
* \param g The green color value multiplied into copy operations.
245
* \param b The blue color value multiplied into copy operations.
247
* \return 0 on success, or -1 if the texture is not valid or color modulation
250
* \sa SDL_GetTextureColorMod()
252
extern DECLSPEC int SDLCALL SDL_SetTextureColorMod(SDL_Texture * texture,
253
Uint8 r, Uint8 g, Uint8 b);
257
* \brief Get the additional color value used in render copy operations.
259
* \param texture The texture to query.
260
* \param r A pointer filled in with the current red color value.
261
* \param g A pointer filled in with the current green color value.
262
* \param b A pointer filled in with the current blue color value.
264
* \return 0 on success, or -1 if the texture is not valid.
266
* \sa SDL_SetTextureColorMod()
268
extern DECLSPEC int SDLCALL SDL_GetTextureColorMod(SDL_Texture * texture,
269
Uint8 * r, Uint8 * g,
273
* \brief Set an additional alpha value used in render copy operations.
275
* \param texture The texture to update.
276
* \param alpha The alpha value multiplied into copy operations.
278
* \return 0 on success, or -1 if the texture is not valid or alpha modulation
281
* \sa SDL_GetTextureAlphaMod()
283
extern DECLSPEC int SDLCALL SDL_SetTextureAlphaMod(SDL_Texture * texture,
287
* \brief Get the additional alpha value used in render copy operations.
289
* \param texture The texture to query.
290
* \param alpha A pointer filled in with the current alpha value.
292
* \return 0 on success, or -1 if the texture is not valid.
294
* \sa SDL_SetTextureAlphaMod()
296
extern DECLSPEC int SDLCALL SDL_GetTextureAlphaMod(SDL_Texture * texture,
300
* \brief Set the blend mode used for texture copy operations.
302
* \param texture The texture to update.
303
* \param blendMode ::SDL_BlendMode to use for texture blending.
305
* \return 0 on success, or -1 if the texture is not valid or the blend mode is
308
* \note If the blend mode is not supported, the closest supported mode is
311
* \sa SDL_GetTextureBlendMode()
313
extern DECLSPEC int SDLCALL SDL_SetTextureBlendMode(SDL_Texture * texture,
314
SDL_BlendMode blendMode);
317
* \brief Get the blend mode used for texture copy operations.
319
* \param texture The texture to query.
320
* \param blendMode A pointer filled in with the current blend mode.
322
* \return 0 on success, or -1 if the texture is not valid.
324
* \sa SDL_SetTextureBlendMode()
326
extern DECLSPEC int SDLCALL SDL_GetTextureBlendMode(SDL_Texture * texture,
327
SDL_BlendMode *blendMode);
330
* \brief Update the given texture rectangle with new pixel data.
332
* \param texture The texture to update
333
* \param rect A pointer to the rectangle of pixels to update, or NULL to
334
* update the entire texture.
335
* \param pixels The raw pixel data.
336
* \param pitch The number of bytes between rows of pixel data.
338
* \return 0 on success, or -1 if the texture is not valid.
340
* \note This is a fairly slow function.
342
extern DECLSPEC int SDLCALL SDL_UpdateTexture(SDL_Texture * texture,
343
const SDL_Rect * rect,
344
const void *pixels, int pitch);
347
* \brief Lock a portion of the texture for pixel access.
349
* \param texture The texture to lock for access, which was created with
350
* ::SDL_TEXTUREACCESS_STREAMING.
351
* \param rect A pointer to the rectangle to lock for access. If the rect
352
* is NULL, the entire texture will be locked.
353
* \param pixels This is filled in with a pointer to the locked pixels,
354
* appropriately offset by the locked area.
355
* \param pitch This is filled in with the pitch of the locked pixels.
357
* \return 0 on success, or -1 if the texture is not valid or was not created with ::SDL_TEXTUREACCESS_STREAMING.
359
* \sa SDL_UnlockTexture()
361
extern DECLSPEC int SDLCALL SDL_LockTexture(SDL_Texture * texture,
362
const SDL_Rect * rect,
363
void **pixels, int *pitch);
366
* \brief Unlock a texture, uploading the changes to video memory, if needed.
368
* \sa SDL_LockTexture()
370
extern DECLSPEC void SDLCALL SDL_UnlockTexture(SDL_Texture * texture);
373
* \brief Set the drawing area for rendering on the current target.
375
* \param rect The rectangle representing the drawing area, or NULL to set the viewport to the entire target.
377
* The x,y of the viewport rect represents the origin for rendering.
379
* \note When the window is resized, the current viewport is automatically
380
* centered within the new window size.
382
extern DECLSPEC int SDLCALL SDL_RenderSetViewport(SDL_Renderer * renderer,
383
const SDL_Rect * rect);
386
* \brief Get the drawing area for the current target.
388
extern DECLSPEC void SDLCALL SDL_RenderGetViewport(SDL_Renderer * renderer,
392
* \brief Set the color used for drawing operations (Fill and Line).
394
* \param r The red value used to draw on the rendering target.
395
* \param g The green value used to draw on the rendering target.
396
* \param b The blue value used to draw on the rendering target.
397
* \param a The alpha value used to draw on the rendering target, usually
398
* ::SDL_ALPHA_OPAQUE (255).
400
* \return 0 on success, or -1 on error
402
extern DECLSPEC int SDL_SetRenderDrawColor(SDL_Renderer * renderer,
403
Uint8 r, Uint8 g, Uint8 b,
407
* \brief Get the color used for drawing operations (Fill and Line).
409
* \param r A pointer to the red value used to draw on the rendering target.
410
* \param g A pointer to the green value used to draw on the rendering target.
411
* \param b A pointer to the blue value used to draw on the rendering target.
412
* \param a A pointer to the alpha value used to draw on the rendering target,
413
* usually ::SDL_ALPHA_OPAQUE (255).
415
* \return 0 on success, or -1 on error
417
extern DECLSPEC int SDL_GetRenderDrawColor(SDL_Renderer * renderer,
418
Uint8 * r, Uint8 * g, Uint8 * b,
422
* \brief Set the blend mode used for drawing operations (Fill and Line).
424
* \param blendMode ::SDL_BlendMode to use for blending.
426
* \return 0 on success, or -1 on error
428
* \note If the blend mode is not supported, the closest supported mode is
431
* \sa SDL_GetRenderDrawBlendMode()
433
extern DECLSPEC int SDLCALL SDL_SetRenderDrawBlendMode(SDL_Renderer * renderer,
434
SDL_BlendMode blendMode);
437
* \brief Get the blend mode used for drawing operations.
439
* \param blendMode A pointer filled in with the current blend mode.
441
* \return 0 on success, or -1 on error
443
* \sa SDL_SetRenderDrawBlendMode()
445
extern DECLSPEC int SDLCALL SDL_GetRenderDrawBlendMode(SDL_Renderer * renderer,
446
SDL_BlendMode *blendMode);
449
* \brief Clear the current rendering target with the drawing color
451
* This function clears the entire rendering target, ignoring the viewport.
453
extern DECLSPEC int SDLCALL SDL_RenderClear(SDL_Renderer * renderer);
456
* \brief Draw a point on the current rendering target.
458
* \param x The x coordinate of the point.
459
* \param y The y coordinate of the point.
461
* \return 0 on success, or -1 on error
463
extern DECLSPEC int SDLCALL SDL_RenderDrawPoint(SDL_Renderer * renderer,
467
* \brief Draw multiple points on the current rendering target.
469
* \param points The points to draw
470
* \param count The number of points to draw
472
* \return 0 on success, or -1 on error
474
extern DECLSPEC int SDLCALL SDL_RenderDrawPoints(SDL_Renderer * renderer,
475
const SDL_Point * points,
479
* \brief Draw a line on the current rendering target.
481
* \param x1 The x coordinate of the start point.
482
* \param y1 The y coordinate of the start point.
483
* \param x2 The x coordinate of the end point.
484
* \param y2 The y coordinate of the end point.
486
* \return 0 on success, or -1 on error
488
extern DECLSPEC int SDLCALL SDL_RenderDrawLine(SDL_Renderer * renderer,
489
int x1, int y1, int x2, int y2);
492
* \brief Draw a series of connected lines on the current rendering target.
494
* \param points The points along the lines
495
* \param count The number of points, drawing count-1 lines
497
* \return 0 on success, or -1 on error
499
extern DECLSPEC int SDLCALL SDL_RenderDrawLines(SDL_Renderer * renderer,
500
const SDL_Point * points,
504
* \brief Draw a rectangle on the current rendering target.
506
* \param rect A pointer to the destination rectangle, or NULL to outline the entire rendering target.
508
* \return 0 on success, or -1 on error
510
extern DECLSPEC int SDLCALL SDL_RenderDrawRect(SDL_Renderer * renderer,
511
const SDL_Rect * rect);
514
* \brief Draw some number of rectangles on the current rendering target.
516
* \param rects A pointer to an array of destination rectangles.
517
* \param count The number of rectangles.
519
* \return 0 on success, or -1 on error
521
extern DECLSPEC int SDLCALL SDL_RenderDrawRects(SDL_Renderer * renderer,
522
const SDL_Rect * rects,
526
* \brief Fill a rectangle on the current rendering target with the drawing color.
528
* \param rect A pointer to the destination rectangle, or NULL for the entire
531
* \return 0 on success, or -1 on error
533
extern DECLSPEC int SDLCALL SDL_RenderFillRect(SDL_Renderer * renderer,
534
const SDL_Rect * rect);
537
* \brief Fill some number of rectangles on the current rendering target with the drawing color.
539
* \param rects A pointer to an array of destination rectangles.
540
* \param count The number of rectangles.
542
* \return 0 on success, or -1 on error
544
extern DECLSPEC int SDLCALL SDL_RenderFillRects(SDL_Renderer * renderer,
545
const SDL_Rect * rects,
549
* \brief Copy a portion of the texture to the current rendering target.
551
* \param texture The source texture.
552
* \param srcrect A pointer to the source rectangle, or NULL for the entire
554
* \param dstrect A pointer to the destination rectangle, or NULL for the
555
* entire rendering target.
557
* \return 0 on success, or -1 on error
559
extern DECLSPEC int SDLCALL SDL_RenderCopy(SDL_Renderer * renderer,
560
SDL_Texture * texture,
561
const SDL_Rect * srcrect,
562
const SDL_Rect * dstrect);
565
* \brief Read pixels from the current rendering target.
567
* \param rect A pointer to the rectangle to read, or NULL for the entire
569
* \param format The desired format of the pixel data, or 0 to use the format
570
* of the rendering target
571
* \param pixels A pointer to be filled in with the pixel data
572
* \param pitch The pitch of the pixels parameter.
574
* \return 0 on success, or -1 if pixel reading is not supported.
576
* \warning This is a very slow operation, and should not be used frequently.
578
extern DECLSPEC int SDLCALL SDL_RenderReadPixels(SDL_Renderer * renderer,
579
const SDL_Rect * rect,
581
void *pixels, int pitch);
584
* \brief Update the screen with rendering performed.
586
extern DECLSPEC void SDLCALL SDL_RenderPresent(SDL_Renderer * renderer);
589
* \brief Destroy the specified texture.
591
* \sa SDL_CreateTexture()
592
* \sa SDL_CreateTextureFromSurface()
594
extern DECLSPEC void SDLCALL SDL_DestroyTexture(SDL_Texture * texture);
597
* \brief Destroy the rendering context for a window and free associated
600
* \sa SDL_CreateRenderer()
602
extern DECLSPEC void SDLCALL SDL_DestroyRenderer(SDL_Renderer * renderer);
605
/* Ends C function definitions when using C++ */
611
#include "close_code.h"
613
#endif /* _SDL_render_h */
615
/* vi: set ts=4 sw=4 expandtab: */