How to put texture on a polygon?

Hello, I want to draw a circle process and put image on it. How to do it?
like this:

timg

Welcome to SDL discourse.

Just add associate a different images in each time step. It can be anything. For example you can have 100 images one for each percentage and render them as far your counter goes.

Or you can make a trick with a single and small arc (maybe 2pi/100 radians) and rotate in a loop.

Or you can go and draw your own circle primitives with SDL_gfx.

This page has a nice tutorial for C++ (that I do not use), is pretty simple to convert to pure C if suits you better.

http://lazyfoo.net/tutorials/SDL/07_texture_loading_and_rendering/index.php

and

http://lazyfoo.net/tutorials/SDL/08_geometry_rendering/index.php

If you have any question or problems with your code let us know.

Thanks for your reply. But I don’t want to use sequence images, it need lot of work, space and seem not smooth. Can SDL2 texture on the Line? I can draw many lines to show a image.

not on the line, on rects only, but you can do a very thin rectangle.

About curved line, no.

For that you need to go with 1. shaders or 2. primitives.

Thgere is no need to use 100 images, you can use a single one and drawing in a loop rotating around it’s center.

And you can make it as smooth as you want using animations. The brain is easy to trick.

About SDL_GFX, I saw it can draw polygon, but I can not find any tutorial for how to texture image on the polygon. Do you have some information? Thanks.
I do not want to use OpenGL, our project will run at PC, embedded Android, embedded Linux, the OpenGL version is different, it is very hard to maintenance.

Afaik no, you can’t texture in a primitive, but you can use alpha blending in your primitive, assign a colorkey and draw the texture on back. Then you can paint your surface as you please. the surface is just a array of pixel colors you can draw on it.

But rectangle can not incline, it only parallel with screen.

once you draw in a rect, you can rotate it and blit it on screen.

Checked again, only textures can be easily rotated, surfaces cannot.

Do you mean a mask? I think this is a good idea, I can draw the alpha line in mask texture, and show the 100% image circle piece after piece, and the same time the circle rotate to catch the new alpha line.

You call mask, I call ColorKey. Same thing :grinning:

About Texture rotation, check: https://wiki.libsdl.org/SDL_RenderCopyEx

Sorry, another question, how to draw the image in a rect? I can draw texture on screen or other texture.

Just loading a image (for example SDL_LoadBMP()) gives you a surface.

You can blit a surface into another with https://wiki.libsdl.org/SDL_BlitSurface

WIth software renderer your window has a default surface that can be fetched with SDL_GetWindowSurface().

Using accelerated renderer you have a texture renderer that should be treated slightly different.

I really recommend you to follow the Lazyfoo’s tutorial. It will explain you all these things.

I see, in SDL the texture is a rectangle too. Thank you, I do not find it before. :grinning:

Everything is a rectangle because you’re handling an array of pixels. If you want to deal with polygons you need to move to a different approach, that would be OpenGL/Vulkan.

To handle different shapes you need to trick the rendering, for example setting a color as “invisible”, we call it assign a ColorKey.