grimfang4 / sdl-gpu

A library for high-performance, modern 2D graphics with SDL written in C.
MIT License
1.19k stars 123 forks source link

Draw textured polygon? #214

Closed nikita-yfh closed 3 years ago

nikita-yfh commented 3 years ago

I need to draw a non-convex textured polygon, or a set of textured triangles. image In this picture, I am achieving the result using SDL_GFX, but its capabilities have become lacking: I can't rotate the image. Can I do something similar with SDL_GPU, and with the ability to rotate the image?

aganm commented 3 years ago

You could rotate each vertex before rendering to get this effect.

I believe SDL_gpu can do that with GPU_Rotate.

nikita-yfh commented 3 years ago

I solved this by using GPU_PrimitiveBatch, passing the vertex coordinates and texture coordinates to it.

aganm commented 3 years ago

Did you solve the image rotation too?

nikita-yfh commented 3 years ago

Yes, I solved. I rotate vertices with point rotation function (xd = x×cos(a) - y×sin(a); yd = y×cos(a) + x×sin(a)). image