Making the API simpler, removed support for palettized video modes and textures.
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 an additional color value used in render copy operations.
225 * \param texture The texture to update.
226 * \param r The red color value multiplied into copy operations.
227 * \param g The green color value multiplied into copy operations.
228 * \param b The blue color value multiplied into copy operations.
230 * \return 0 on success, or -1 if the texture is not valid or color modulation
233 * \sa SDL_GetTextureColorMod()
235 extern DECLSPEC int SDLCALL SDL_SetTextureColorMod(SDL_Texture * texture,
236 Uint8 r, Uint8 g, Uint8 b);
240 * \brief Get the additional color value used in render copy operations.
242 * \param texture The texture to query.
243 * \param r A pointer filled in with the current red color value.
244 * \param g A pointer filled in with the current green color value.
245 * \param b A pointer filled in with the current blue color value.
247 * \return 0 on success, or -1 if the texture is not valid.
249 * \sa SDL_SetTextureColorMod()
251 extern DECLSPEC int SDLCALL SDL_GetTextureColorMod(SDL_Texture * texture,
252 Uint8 * r, Uint8 * g,
256 * \brief Set an additional alpha value used in render copy operations.
258 * \param texture The texture to update.
259 * \param alpha The alpha value multiplied into copy operations.
261 * \return 0 on success, or -1 if the texture is not valid or alpha modulation
264 * \sa SDL_GetTextureAlphaMod()
266 extern DECLSPEC int SDLCALL SDL_SetTextureAlphaMod(SDL_Texture * texture,
270 * \brief Get the additional alpha value used in render copy operations.
272 * \param texture The texture to query.
273 * \param alpha A pointer filled in with the current alpha value.
275 * \return 0 on success, or -1 if the texture is not valid.
277 * \sa SDL_SetTextureAlphaMod()
279 extern DECLSPEC int SDLCALL SDL_GetTextureAlphaMod(SDL_Texture * texture,
283 * \brief Set the blend mode used for texture copy operations.
285 * \param texture The texture to update.
286 * \param blendMode ::SDL_BlendMode to use for texture blending.
288 * \return 0 on success, or -1 if the texture is not valid or the blend mode is
291 * \note If the blend mode is not supported, the closest supported mode is
294 * \sa SDL_GetTextureBlendMode()
296 extern DECLSPEC int SDLCALL SDL_SetTextureBlendMode(SDL_Texture * texture,
297 SDL_BlendMode blendMode);
300 * \brief Get the blend mode used for texture copy operations.
302 * \param texture The texture to query.
303 * \param blendMode A pointer filled in with the current blend mode.
305 * \return 0 on success, or -1 if the texture is not valid.
307 * \sa SDL_SetTextureBlendMode()
309 extern DECLSPEC int SDLCALL SDL_GetTextureBlendMode(SDL_Texture * texture,
310 SDL_BlendMode *blendMode);
313 * \brief Update the given texture rectangle with new pixel data.
315 * \param texture The texture to update
316 * \param rect A pointer to the rectangle of pixels to update, or NULL to
317 * update the entire texture.
318 * \param pixels The raw pixel data.
319 * \param pitch The number of bytes between rows of pixel data.
321 * \return 0 on success, or -1 if the texture is not valid.
323 * \note This is a fairly slow function.
325 extern DECLSPEC int SDLCALL SDL_UpdateTexture(SDL_Texture * texture,
326 const SDL_Rect * rect,
327 const void *pixels, int pitch);
330 * \brief Lock a portion of the texture for pixel access.
332 * \param texture The texture to lock for access, which was created with
333 * ::SDL_TEXTUREACCESS_STREAMING.
334 * \param rect A pointer to the rectangle to lock for access. If the rect
335 * is NULL, the entire texture will be locked.
336 * \param markDirty If this is nonzero, the locked area will be marked dirty
337 * when the texture is unlocked.
338 * \param pixels This is filled in with a pointer to the locked pixels,
339 * appropriately offset by the locked area.
340 * \param pitch This is filled in with the pitch of the locked pixels.
342 * \return 0 on success, or -1 if the texture is not valid or was created with
343 * ::SDL_TEXTUREACCESS_STATIC.
345 * \sa SDL_DirtyTexture()
346 * \sa SDL_UnlockTexture()
348 extern DECLSPEC int SDLCALL SDL_LockTexture(SDL_Texture * texture,
349 const SDL_Rect * rect,
350 int markDirty, void **pixels,
354 * \brief Unlock a texture, uploading the changes to renderer memory, if needed.
356 * \sa SDL_LockTexture()
357 * \sa SDL_DirtyTexture()
359 extern DECLSPEC void SDLCALL SDL_UnlockTexture(SDL_Texture * texture);
362 * \brief Mark the specified rectangles of the texture as dirty.
364 * \param texture The texture to mark dirty, which was created with
365 * ::SDL_TEXTUREACCESS_STREAMING.
366 * \param numrects The number of rectangles pointed to by rects.
367 * \param rects The pointer to an array of dirty rectangles.
369 * \sa SDL_LockTexture()
370 * \sa SDL_UnlockTexture()
372 extern DECLSPEC void SDLCALL SDL_DirtyTexture(SDL_Texture * texture,
374 const SDL_Rect * rects);
377 * \brief Set the color used for drawing operations (Fill and Line).
379 * \param r The red value used to draw on the rendering target.
380 * \param g The green value used to draw on the rendering target.
381 * \param b The blue value used to draw on the rendering target.
382 * \param a The alpha value used to draw on the rendering target, usually
383 * ::SDL_ALPHA_OPAQUE (255).
385 * \return 0 on success, or -1 on error
387 extern DECLSPEC int SDL_SetRenderDrawColor(SDL_Renderer * renderer,
388 Uint8 r, Uint8 g, Uint8 b,
392 * \brief Get the color used for drawing operations (Fill and Line).
394 * \param r A pointer to the red value used to draw on the rendering target.
395 * \param g A pointer to the green value used to draw on the rendering target.
396 * \param b A pointer to the blue value used to draw on the rendering target.
397 * \param a A pointer to the alpha value used to draw on the rendering target,
398 * usually ::SDL_ALPHA_OPAQUE (255).
400 * \return 0 on success, or -1 on error
402 extern DECLSPEC int SDL_GetRenderDrawColor(SDL_Renderer * renderer,
403 Uint8 * r, Uint8 * g, Uint8 * b,
407 * \brief Set the blend mode used for drawing operations (Fill and Line).
409 * \param blendMode ::SDL_BlendMode to use for blending.
411 * \return 0 on success, or -1 on error
413 * \note If the blend mode is not supported, the closest supported mode is
416 * \sa SDL_GetRenderDrawBlendMode()
418 extern DECLSPEC int SDLCALL SDL_SetRenderDrawBlendMode(SDL_Renderer * renderer,
419 SDL_BlendMode blendMode);
422 * \brief Get the blend mode used for drawing operations.
424 * \param blendMode A pointer filled in with the current blend mode.
426 * \return 0 on success, or -1 on error
428 * \sa SDL_SetRenderDrawBlendMode()
430 extern DECLSPEC int SDLCALL SDL_GetRenderDrawBlendMode(SDL_Renderer * renderer,
431 SDL_BlendMode *blendMode);
434 * \brief Clear the current rendering target with the drawing color
436 extern DECLSPEC int SDLCALL SDL_RenderClear(SDL_Renderer * renderer);
439 * \brief Draw a point on the current rendering target.
441 * \param x The x coordinate of the point.
442 * \param y The y coordinate of the point.
444 * \return 0 on success, or -1 on error
446 extern DECLSPEC int SDLCALL SDL_RenderDrawPoint(SDL_Renderer * renderer,
450 * \brief Draw multiple points on the current rendering target.
452 * \param points The points to draw
453 * \param count The number of points to draw
455 * \return 0 on success, or -1 on error
457 extern DECLSPEC int SDLCALL SDL_RenderDrawPoints(SDL_Renderer * renderer,
458 const SDL_Point * points,
462 * \brief Draw a line on the current rendering target.
464 * \param x1 The x coordinate of the start point.
465 * \param y1 The y coordinate of the start point.
466 * \param x2 The x coordinate of the end point.
467 * \param y2 The y coordinate of the end point.
469 * \return 0 on success, or -1 on error
471 extern DECLSPEC int SDLCALL SDL_RenderDrawLine(SDL_Renderer * renderer,
472 int x1, int y1, int x2, int y2);
475 * \brief Draw a series of connected lines on the current rendering target.
477 * \param points The points along the lines
478 * \param count The number of points, drawing count-1 lines
480 * \return 0 on success, or -1 on error
482 extern DECLSPEC int SDLCALL SDL_RenderDrawLines(SDL_Renderer * renderer,
483 const SDL_Point * points,
487 * \brief Draw a rectangle on the current rendering target.
489 * \param rect A pointer to the destination rectangle, or NULL to outline the entire rendering target.
491 * \return 0 on success, or -1 on error
493 extern DECLSPEC int SDLCALL SDL_RenderDrawRect(SDL_Renderer * renderer,
494 const SDL_Rect * rect);
497 * \brief Draw some number of rectangles on the current rendering target.
499 * \param rects A pointer to an array of destination rectangles.
500 * \param count The number of rectangles.
502 * \return 0 on success, or -1 on error
504 extern DECLSPEC int SDLCALL SDL_RenderDrawRects(SDL_Renderer * renderer,
505 const SDL_Rect ** rects,
509 * \brief Fill a rectangle on the current rendering target with the drawing color.
511 * \param rect A pointer to the destination rectangle, or NULL for the entire
514 * \return 0 on success, or -1 on error
516 extern DECLSPEC int SDLCALL SDL_RenderFillRect(SDL_Renderer * renderer,
517 const SDL_Rect * rect);
520 * \brief Fill some number of rectangles on the current rendering target with the drawing color.
522 * \param rects A pointer to an array of destination rectangles.
523 * \param count The number of rectangles.
525 * \return 0 on success, or -1 on error
527 extern DECLSPEC int SDLCALL SDL_RenderFillRects(SDL_Renderer * renderer,
528 const SDL_Rect ** rect,
532 * \brief Copy a portion of the texture to the current rendering target.
534 * \param texture The source texture.
535 * \param srcrect A pointer to the source rectangle, or NULL for the entire
537 * \param dstrect A pointer to the destination rectangle, or NULL for the
538 * entire rendering target.
540 * \return 0 on success, or -1 on error
542 extern DECLSPEC int SDLCALL SDL_RenderCopy(SDL_Renderer * renderer,
543 SDL_Texture * texture,
544 const SDL_Rect * srcrect,
545 const SDL_Rect * dstrect);
548 * \brief Read pixels from the current rendering target.
550 * \param rect A pointer to the rectangle to read, or NULL for the entire
552 * \param format The desired format of the pixel data, or 0 to use the format
553 * of the rendering target
554 * \param pixels A pointer to be filled in with the pixel data
555 * \param pitch The pitch of the pixels parameter.
557 * \return 0 on success, or -1 if pixel reading is not supported.
559 * \warning This is a very slow operation, and should not be used frequently.
561 extern DECLSPEC int SDLCALL SDL_RenderReadPixels(SDL_Renderer * renderer,
562 const SDL_Rect * rect,
564 void *pixels, int pitch);
567 * \brief Write pixels to the current rendering target.
569 * \param rect A pointer to the rectangle to write, or NULL for the entire
571 * \param format The format of the pixel data, or 0 to use the format
572 * of the rendering target
573 * \param pixels A pointer to the pixel data to write.
574 * \param pitch The pitch of the pixels parameter.
576 * \return 0 on success, or -1 if pixel writing is not supported.
578 * \warning This is a very slow operation, and should not be used frequently.
580 extern DECLSPEC int SDLCALL SDL_RenderWritePixels(SDL_Renderer * renderer,
581 const SDL_Rect * rect,
587 * \brief Update the screen with rendering performed.
589 extern DECLSPEC void SDLCALL SDL_RenderPresent(SDL_Renderer * renderer);
592 * \brief Destroy the specified texture.
594 * \sa SDL_CreateTexture()
595 * \sa SDL_CreateTextureFromSurface()
597 extern DECLSPEC void SDLCALL SDL_DestroyTexture(SDL_Texture * texture);
600 * \brief Destroy the rendering context for a window and free associated
603 * \sa SDL_CreateRenderer()
605 extern DECLSPEC void SDLCALL SDL_DestroyRenderer(SDL_Renderer * renderer);
608 /* Ends C function definitions when using C++ */
614 #include "close_code.h"
616 #endif /* _SDL_render_h */
618 /* vi: set ts=4 sw=4 expandtab: */