Text-Renderer/src/main.cpp

57 lines
1.5 KiB
C++

#include <iostream>
#include "add.h"
#include "Bitmap.h"
/*
* @author: Julian Hinxlage
* @since: v0.0.0
* @brief: An image is loaded and used as a font.
* A string is converted and displayed in the console.
* Currently only to test.
*/
int main() {
Bitmap bitmap;
bitmap.load("../res/font.bmp");
std::string str = "Hello, World!";
//values used to calculate the coordinates of the characters
int xOffset = 1;
int yOffset = 2;
int xSize = 6;
int ySize = 7;
int xCount = 18;
int xStart = 0;
int yStart = 2;
//print vertical
//i is the current row
for (int i = 0; i < ySize; i++) {
//loop through the characters in the string
for (char c : str) {
//index of character(x and y)
int index = (c - ' ');
int xIndex = index % xCount;
int yIndex = index / xCount;
//character index to pixel index conversion
int x = xIndex * (xSize + xOffset) + xStart;
int y = yIndex * (ySize + yOffset) + yStart;
//print current row of the current character
for (int j = x; j < x + xSize; j++) {
auto *pixel = (unsigned int *) bitmap.getPixel(j, i + y);
if (*pixel == 0) {
std::cout << " ";
} else {
std::cout << "1";
}
}
std::cout << " ";
}
std::cout << std::endl;
}
return 0;
}