Text-Renderer/main/main.cpp

65 lines
1.7 KiB
C++
Raw Normal View History

2019-10-15 14:00:06 +02:00
#include <iostream>
#include "add.h"
#include "Bitmap.h"
2019-10-15 14:00:06 +02:00
/**
* @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.
*/
2019-10-15 14:00:06 +02:00
int main() {
Bitmap bitmap;
bitmap.load("../res/font.bmp");
2019-10-16 12:17:59 +02:00
std::string str;
std::cout << "string to draw: ";
std::cin >> str;
//values used to calculate the coordinates of the characters
2019-10-16 12:17:59 +02:00
int xOffset = 2;
int yOffset = 2;
2019-10-16 12:17:59 +02:00
int xSize = 5;
int ySize = 7;
int xCount = 18;
2019-10-16 12:17:59 +02:00
int xStart = 1;
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++) {
2019-10-16 12:17:59 +02:00
char *pixel_ptr = bitmap.getPixel(j, i + y);
unsigned int pixel = 0;
*((char*)&pixel+0) = pixel_ptr[0];
*((char*)&pixel+1) = pixel_ptr[1];
*((char*)&pixel+2) = pixel_ptr[2];
if (pixel == 0) {
std::cout << " ";
} else {
2019-10-16 12:17:59 +02:00
std::cout << "1";
}
2019-10-16 12:17:59 +02:00
}
std::cout << " ";
}
std::cout << std::endl;
}
2019-10-15 14:00:06 +02:00
return 0;
}