Wiki Page Content

SDL_RenderDrawLines

Use this function to draw a series of connected lines on the current rendering target.

Syntax

int SDL_RenderDrawLines(SDL_Renderer*    renderer,
                        const SDL_Point* points,
                        int              count)

Function Parameters

renderer

the rendering context

points

an array of SDL_Point structures representing points along the lines

count

the number of points, drawing count-1 lines

Return Value

Returns 0 on success or a negative error code on failure; call SDL_GetError() for more information.

Code Examples

#include "SDL.h"

#define POINTS_COUNT 4

static SDL_Point points[POINTS_COUNT] = {
    {320, 200},
    {300, 240},
    {340, 240},
    {320, 200}
};

int main(int argc, char* argv[])
{
    if (SDL_Init(SDL_INIT_VIDEO) == 0) {
        SDL_Window* window = NULL;
        SDL_Renderer* renderer = NULL;

        if (SDL_CreateWindowAndRenderer(640, 480, 0, &window, &renderer) == 0) {
            SDL_bool done = SDL_FALSE;

            while (!done) {
                SDL_Event event;

                SDL_SetRenderDrawColor(renderer, 0, 0, 0, SDL_ALPHA_OPAQUE);
                SDL_RenderClear(renderer);

                SDL_SetRenderDrawColor(renderer, 255, 255, 255, SDL_ALPHA_OPAQUE);
                SDL_RenderDrawLines(renderer, points, POINTS_COUNT);
                SDL_RenderPresent(renderer);

                while (SDL_PollEvent(&event)) {
                    if (event.type == SDL_QUIT) {
                        done = SDL_TRUE;
                    }
                }
            }
        }

        if (renderer) {
            SDL_DestroyRenderer(renderer);
        }
        if (window) {
            SDL_DestroyWindow(window);
        }
    }
    SDL_Quit();
    return 0;
}

Remarks

You can add useful comments here

Version

This function is available since SDL 2.0.0.


CategoryAPI, CategoryRender

None: SDL_RenderDrawLines (last edited 2017-01-14 23:00:16 by PhilippWiesemann)

Feedback
Please include your contact information if you'd like to receive a reply.
Submit