Disclaimer: I am uncertain if this is the best place to post this question, so please advise me of how I can best find the answer if I am doing something wrong. I am asking this question because I am trying to optimize a drawing function of a PC game I am programming.
Preface: There is a matrix of blocks, that can be either on (black) or off (white). There will be different colors, but for the sake of simplicity I am presenting the problem to you as black and white only, so please imagine this matrix forming some random pattern like a QR code which would be a good example.
Problem: Instead of drawing each black block individually, I want to determine how to draw all black blocks using as minimum calls to my draw black rectangle function as possible.
Question: Is there any existing process that I can refer to so as to make my drawing process as efficient as possible, or how would I logically go about tackling this conundrum?
Edit: Tried to produce some example code for us to play with
std::vector<std::vector<bool>> matrix;
int width = 100;
int height = 100;
matrix.resize(height);
for(int h = 0; h < height; h++)
{
matrix[h].resize(width);
for(int w = 0; w < width; w++)
{
matrix[h][w] = random 1/0
}
}
void draw()
{
.. draw matrix using a minimum amount of calls to draw_rectangle
}
void draw_rectangle(int x, int y, int width, int height)
{
.. draws a set of black blocks
}