DJScantron
Newcomer
I have a square texture, not unlike the one here: http://en.wikipedia.org/wiki/Image:ASCII_full.svg (except mine has 2 blank rows at the bottom.)
I've tried for a while to come up with the proper tex coords for each character, but I still can't get it right.
The spacing of the coords is correct(I think), I get a whole character when I render, but It's the wrong one(or completely gray).
Here's what I have so far.(condensed)
NOTE: I'm flipping the texture vertically on load.
I've tried for a while to come up with the proper tex coords for each character, but I still can't get it right.
The spacing of the coords is correct(I think), I get a whole character when I render, but It's the wrong one(or completely gray).
Here's what I have so far.(condensed)
NOTE: I'm flipping the texture vertically on load.
Code:
int chx = 8, chy = 16; //each characters width and height
int imgx = 128, imgy = 128 //font texture dimensions
//array of float pointers.
//each element points to an array of 4 tex coords for an ascii character
float **texCoords;
texCoords = new float*[16*6];
for(int i = 0; i < 16*6; ++i)
{
texCoords[i] = new float[2*4];
}
//normally these would be literals, because the font will always be 6 rows of 16 chars each
const int CPR = 16; //characters per row
const int NOR = 6; //number of rows
for(int y = 0; y < NOR; ++y)
{
for(int x = 0; x < CPR; ++x)
{
//top left vertex
texCoords[(NOR * y) + x][0] = (float)x*chx / imgx;
texCoords[(NOR * y) + x][1] = (float)y*chy / imgy;
//bottom left vertex
texCoords[(NOR * y) + x][2] = (float)x*chx / imgx ;
texCoords[(NOR * y) + x][3] = ((float)y*chy - chy) / imgy;
//top right vertex
texCoords[(NOR * y) + x][4] = ((float)x*chx + chx) / imgx;
texCoords[(NOR * y) + x][5] = (float)y*chy / imgy;
//bottom right vertex
texCoords[(NOR * y) + x][6] = ((float)x*chx + chx) / imgx;
texCoords[(NOR * y) + x][7] = ((float)y*chy - chy) / imgy;
}
}