sdl_renderfillrect
The sdl_renderfillrect
function is used in the SDL (Simple DirectMedia Layer) library for rendering filled rectangles on the screen. It is a part of the SDL rendering API and allows you to draw filled rectangles of a specified size and color on the screen.
Here is an example of how to use the sdl_renderfillrect
function in C:
#include <SDL.h>
int main() {
// Initialize SDL
SDL_Init(SDL_INIT_VIDEO);
// Create a window
SDL_Window* window = SDL_CreateWindow("SDL Render Fill Rect", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 800, 600, 0);
// Create a renderer
SDL_Renderer* renderer = SDL_CreateRenderer(window, -1, 0);
// Set the color for the filled rectangle
SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255); // Red color
// Create a rectangle
SDL_Rect rect;
rect.x = 100;
rect.y = 100;
rect.w = 200;
rect.h = 150;
// Render the filled rectangle
SDL_RenderFillRect(renderer, &rect);
// Update the screen
SDL_RenderPresent(renderer);
// Wait for a few seconds
SDL_Delay(3000);
// Clean up
SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(window);
SDL_Quit();
return 0;
}
This code initializes SDL, creates a window and a renderer, sets the color for the filled rectangle, creates a rectangle with the desired position and size, renders the filled rectangle on the screen, updates the screen, waits for a few seconds, and then cleans up the resources.
Please note that you need to have the SDL library installed and properly configured in your development environment to use the sdl_renderfillrect
function.