I decided to make my own fonts with SDL and am almost finished. Unfortunately I have a small problem and dont really know how to describe it.
This is supposed to be a two but for some reason is messing up. Screenshot at bottom of post. Any help is appreciated.
Here is some of my font array
Code:// myfonts.h const int CHAR_WIDTH = 8; const int CHAR_HEIGHT = 12; const unsigned char font1[][96] = { // Character /* / */ == 47 { 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,1, 0,0,0,0,0,0,1,1, 0,0,0,0,0,1,1,0, 0,0,0,0,1,1,0,0, 0,0,0,1,1,0,0,0, 0,0,1,1,0,0,0,0, 0,1,1,0,0,0,0,0, 1,1,0,0,0,0,0,0, 1,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0 }, // Number 0 { 0,1,1,1,1,1,0,0, 1,0,0,0,0,0,1,0, 1,0,0,0,0,0,1,0, 1,0,0,0,0,0,1,0, 1,0,0,0,0,0,1,0, 1,0,0,0,0,0,1,0, 1,0,0,0,0,0,1,0, 1,0,0,0,0,0,1,0, 1,0,0,0,0,0,1,0, 0,1,1,1,1,1,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, }, // Number 1 { 0,0,0,1,0,0,0,0, 0,0,1,1,0,0,0,0, 0,0,0,1,0,0,0,0, 0,0,0,1,0,0,0,0, 0,0,0,1,0,0,0,0, 0,0,0,1,0,0,0,0, 0,0,0,1,0,0,0,0, 0,0,0,1,0,0,0,0, 0,0,0,1,0,0,0,0, 0,1,1,1,1,1,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0 }, // Number 2 { 0,1,1,1,1,1,0,0, 1,0,0,0,0,0,1,0, 1,0,0,0,0,0,1,0, 0,0,0,0,0,1,0,0, 0,0,0,0,1,0,0,0, 0,0,0,1,0,0,0,0, 0,0,1,0,0,0,0,0, 0,1,0,0,0,0,0,0, 1,0,0,0,0,0,0,0, 1,1,1,1,1,1,1,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0 }, etc...Code:// CFont.cpp #include "CFont.h" #include "myfonts.h" CFont::CFont(SDL_Surface* nScreen) { //ctor m_Screen = nScreen; m_RealWidth = m_Screen->pitch / 4; } CFont::~CFont() { //dtor m_Screen = NULL; } void CFont::PrintString(int nX, int nY, std::string nString) { if(!m_Screen) return; m_X = nX; m_Y = nY; int length = nString.size(); // Calculate Screen position m_Position = m_Y * m_RealWidth + m_X; for(int index = 0; index < length; index++) { PrintASCIIChar(nString[index]); // Move screen position along x axis to print next char m_Position += 8; } } void CFont::PrintASCIIChar(char ch) { if(!m_Screen) return; // This is to keep within range of our font values if(ch < 47 || ch > 122) return; // Offset into the font array so that we draw the correct character int i = ch - 47; int factor = 0; // Making variables local int position = m_Position; /*Screen Position*/ int realWidth = m_RealWidth; int width = CHAR_WIDTH; int x = m_X; int y = m_Y; // each character is 8 * 12 = 96 // character width is 8 so factor is used to track so I know when I hit the character width for(int alpha = 0; alpha < 96; alpha++, factor++) { if(font1[i][alpha]) { // Set pixel to white at current screen postion adding in the factor to move along the x axis ((unsigned int*)m_Screen->pixels)[position + factor] = 0xffffff; } if(factor == width) { factor = 0; // Move screen postion along y axis to print the next line in the array y++; } // Recalculate screen position position = y * realWidth + x; } }