HOWTO draw circles, arcs and vector graphics in SDL?

前端 未结 4 2053
一个人的身影
一个人的身影 2021-02-02 15:43

(I\'m using SDL2)

SDL is a relatively small library for \"low level access to audio, keyboard, mouse, joystick, and graphics hardware via OpenGL and Direct3D\" It\'s us

4条回答
  •  无人共我
    2021-02-02 16:15

    SDL allows for third party libs to draw on a texture. If cairo was desirable, it could be used in a function like this:

    cairo_t*cb(cairo_t*cr)
    {cairo_set_source_rgb(cr, 1.0, 1.0, 1.0);
     cairo_rectangle(cr, 10, 20, 128, 128);
     cairo_stroke(cr);
     return cr;
    }
    

    then cb can be passed to this function:

    cairo_t*cai(SDL_Window*w,SDL_Renderer*r,cairo_t*(*f)(cairo_t*))
    {int width, height, pitch;void *pixels;
     SDL_GetWindowSize(w, &width, &height);
     SDL_Texture*t=SDL_CreateTexture(r,SDL_PIXELFORMAT_ARGB8888,SDL_TEXTUREACCESS_STREAMING,width,height);
     SDL_LockTexture(t, NULL, &pixels, &pitch);
     cairo_surface_t *cs=cairo_image_surface_create_for_data(pixels,CAIRO_FORMAT_ARGB32,width,height,pitch);
     cairo_t*s=cairo_create(cs);
     cairo_t*fr=f(s);SDL_UnlockTexture(t);SDL_RenderCopy(r,t,NULL,NULL);SDL_RenderPresent(r);
     return fr;
    }
    

提交回复
热议问题