How to get antialiasing with sdl2 ( SOLVED )

Hello everybody,

I'm trying to draw some simple figures in a window with sdl2 crate but i get stairlike lines:


Here is my Cargo.toml

name = "draw-test"
version = "0.1.0"
authors = ["Guish"]
edition = "2018"

rand = "0.6.5"

version = "0.32.2"
default-features = false
features = ["gfx"]

And here the code:

extern crate sdl2;
use sdl2::pixels::Color;
use sdl2::rect::Rect;
use std::{thread, time};

use sdl2::gfx::primitives::DrawRenderer;
use sdl2::render::WindowCanvas;

use sdl2::event::Event;
use sdl2::keyboard::Keycode;
use sdl2::EventPump;

fn init() -> (WindowCanvas, EventPump) {
    let sdl_context = sdl2::init().unwrap();
    let video_subsystem =;

    let window = video_subsystem
        .window("demo", 400, 400)

    let mut renderer = window.into_canvas().build().unwrap();

    let event_pump = sdl_context.event_pump().unwrap();

    renderer.set_draw_color(Color::RGB(255, 255, 255));

    (renderer, event_pump)

fn main() {
    let (mut r, mut e) = init();
    let color = Color::RGB(255, 0, 0);
    r.fill_rect(Rect::new(10, 10, 100, 100));
    let _ =, 100, 30, color);

    'running: loop {
        for event in e.poll_iter() {
            match event {
                Event::KeyDown {
                    keycode: Some(Keycode::Escape),
                } => break 'running,
                _ => {}

I was unable to find info about antialiasing on crate docs or other sources.

Could anyone give me advice about how add it to this example?

Also any other simple way to draw circles and arc on a window would be welcome.

Many Thanks!

You seem to look for DrawRenderer::aa_circle():

fn aa_circle<C: ToColor>(&self, x: i16, y: i16, rad: i16, color: C) -> Result<(), String>

SDL2_gfx: I:/Sources/sdl2gfx/SDL2_gfxPrimitives.h File Reference

SDL2_GFXPRIMITIVES_SCOPE int aacircleColor(SDL_Renderer *renderer, Sint16 x, Sint16 y, Sint16 rad, Uint32 color)

Draw anti-aliased circle with blending.

Thank you dkim!

I got lost on crate doc and couldn't figure out that aa was antialiasing :persevere:

Docs for the library at are more descriptive, thanks for pointing it.


This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.