edubart / sokol_gp

Minimal modern efficient cross platform 2D graphics painter in C
MIT No Attribution
456 stars 24 forks source link

flip sgp_draw_textured_rect_ex #11

Closed kariem2k closed 1 year ago

kariem2k commented 2 years ago

Hello,

I was wondering if there is a way to flip the textures drawn by sgp_draw_textured_rect_ex? I tried sending negative w,h and but does not work. Also, I don't think negative scaling will work?

Thanks

edubart commented 1 year ago

Both using negative height or negative scaling should work, but in both you should offset Y to work. So the options are:

  1. Use negative height in src_rect and while offsetting y by height when using sgp_draw_textured_rect_ex, for example you can can use src_rect = {w, h, -w, -h} to draw it flipped in both axes, whereas normally you would use src_rect = {0, 0, w, h} to draw unflipped.
  2. Use negative scale, but negative scale will invert the orientation of axes, so you must also translate coordinate system by the viewport size before scaling, this means you can use something like sgp_translate(sapp_width(), sapp_height()) and then sgp_scale(-1.0, -1.0). Also remember to use sgp_push_transform/sgp_pop_transform when transforming space.