There is something wrong with my code and I don’t see it.
I have a texture with a font (on the x-as you could say).
When you type in a textbox, the int value of the letters go to “daText” and to “letter”. “Letter” goes into an alphabetArray and gets the right stuff (length, position etc) from the texture. That all works great, but the small problem is that the next letter is just displayed over the previous one. The quad does not want to copy or it does not want to move…
Thanks for looking. Below is the code, I hope it’s a bit clear.
edit: The texture is 2048x32 in size.
static System::Void Render(System::Void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture[0]);
int letter = 47; //the answer to all
GLfloat beginX = 100.0;
GLfloat beginY = 0.0;
for (int x = 0; x < textbox_lenght; x++){
letter = daText[x];
glBegin(GL_QUADS);
glTexCoord2f( (alphabetArray[letter][2]/2048.0) ,1.0); glVertex3f(beginX, beginY, 0.0);
glTexCoord2f( ((alphabetArray[letter][2]+alphabetArray[letter][0])/2048.0) ,1.0); glVertex3f(beginX+alphabetArray[letter][0], beginY, 0.0);
glTexCoord2f( ((alphabetArray[letter][2]+alphabetArray[letter][0])/2048.0) ,(7.0/32.0)); glVertex3f(beginX+alphabetArray[letter][0], beginY+25.0, 0.0);
glTexCoord2f( (alphabetArray[letter][2]/2048.0) ,(7.0/32.0)); glVertex3f(beginX, beginY+25.0, 0.0);
glEnd();
beginX += alphabetArray[letter][0];
}
glDisable(GL_BLEND);
glDisable(GL_TEXTURE_2D);
glFlush();
}
Part of the alphabetArray:
static int alphabetArray[][3] = {
//[0] = length letter
//[1] = height letter
//[2] = position letter from the left
0,0,0, //0
0,0,0, //1
0,0,0, //2
0,0,0, //3
0,0,0, //4
0,0,0, //5
0,0,0, //6
0,0,0, //7
0,0,0, //8
0,0,0, //9
0,0,0, //10 = ENTER
0,0,0, //11
0,0,0, //12
0,0,0, //13
0,0,0, //14
0,0,0, //15
0,0,0, //16
0,0,0, //17
0,0,0, //18
0,0,0, //19
0,0,0, //20
0,0,0, //21
0,0,0, //22
0,0,0, //23
0,0,0, //24
0,0,0, //25
0,0,0, //26
0,0,0, //27
0,0,0, //28
0,0,0, //29
0,0,0, //30
0,0,0, //31
9,25,0, //32
6,25,9, //33
11,25,15, //34
0,0,0, //35
12,25,26, //36
11,25,38, //37
0,0,0, //38
6,25,49, //39
9,25,55, //40
9,25,64, //41
12,25,73, //42
0,0,0, //43
6,25,85, //44
11,25,91, //45
6,25,102, //46
12,25,108, //47
12,25,120, //48
9,25,132, //49
12,25,141, //50
12,25,153, //51
13,25,165, //52
12,25,178, //53
12,25,190, //54
12,25,202, //55
12,25,214, //56
12,25,226, //57
6,25,238, //58
6,25,244, //59
0,0,0, //60
0,0,0, //61
0,0,0, //62
11,25,250, //63
6,25,261, //64
11,25,267, //65
11,25,278, //66
11,25,289, //67
11,25,300, //68
11,25,311, //69
11,25,322, //70
11,25,333, //71
11,25,344, //72
8,25,355, //73
12,25,363, //74
13,25,375, //75
11,25,388, //76
....