Pogosim
Loading...
Searching...
No Matches
render.cpp File Reference
#include <SDL2/SDL.h>
#include <box2d/box2d.h>
#include <vector>
#include <random>
#include <iostream>
#include <fstream>
#include <sstream>
#include "utils.h"
#include "distances.h"
#include "render.h"
#include "spogobot.h"
#include "fpng.h"

Functions

void draw_polygon (SDL_Renderer *renderer, const std::vector< b2Vec2 > &polygon)
 Draws a polygon using an SDL renderer.
void save_window_to_png (SDL_Renderer *renderer, SDL_Window *window, const std::string &filename)
 Saves the content of an SDL window to a PNG file.

Function Documentation

◆ draw_polygon()

void draw_polygon ( SDL_Renderer * renderer,
const std::vector< b2Vec2 > & polygon )

Draws a polygon using an SDL renderer.

This function renders a polygon by drawing red lines between consecutive vertices on the provided SDL renderer. It also closes the polygon by drawing a line between the last and first vertex.

Parameters
rendererPointer to the SDL_Renderer to use for drawing.
polygonA vector of b2Vec2 points defining the polygon.

◆ save_window_to_png()

void save_window_to_png ( SDL_Renderer * renderer,
SDL_Window * window,
const std::string & filename )

Saves the content of an SDL window to a PNG file.

This function reads the pixels from the SDL renderer associated with a window and saves the image as a PNG file. It also ensures that the directory path for the output file exists.

Parameters
rendererPointer to the SDL_Renderer used for capturing the window content.
windowPointer to the SDL_Window from which to capture the content.
filenameThe file path where the PNG image will be saved.