Home > other >  Rectangle to Texture in SDL2 C
Rectangle to Texture in SDL2 C

Time:06-17

Is it possible to create a Rectangle and somehow turn it into a Texture in SDL2 C?

You can easily load images to textures using the image library but making a simple rectangle seems a lot more complicated.

CodePudding user response:

It is generally not meaningful to create a texture in which all pixels are the same color, as that would be a waste of video memory.

If you want to render a single rectangle in a single color without an outline, it would be more efficient to do this directly using the function SDL_RenderFillRect.

If you really want to create a texture for a single rectangle in a single color without an outline, then you can create an SDL_Surface with SDL_CreateRGBSurface, then use SDL_FillRect on that SDL_Surface to set the color, and then use SDL_CreateTextureFromSurface to create a SDL_Texture from that SDL_Surface.

  •  Tags:  
  • c sdl
  • Related