Multiple quads from one texture do not move

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. :slight_smile:


 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
....


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();

I’m surprised this draws anything at all, given that you never call glVertex() between glBegin()/glEnd().
To have your quads show up next to instead of on top of each other you need to increment their x coordinate in every iteration of the for loop.

mmm the code looks correct, my only doubth… is where daText came from? It contain only one character or the whole string?

Performance hint, put the glBegin / glEnd outside the for.
And last thing, the answer to the ultimate question of life the universe and everything is 42, not 47. :stuck_out_tongue:

@carsten neumann: psss… scroll on the right.

Thank you very much! That solved it. The “daText” only got the the last letter, I forgot to increment it.

Also thanks for the performance hint, I implemented it right away.

42 :smiley:

One quick question. Since I use a texture with 2048 x 32 size, I’m “blocking out” people with opengl 1.1 (max. 1024).

Are there many people with opengl 1.1 or?

What should I do?

Are there many people with opengl 1.1 or?

Technically, you’re locking out people with GeForce 1/2-class hardware. Until GL 2.0, OpenGL versions do not correlate well with hardware capabilities.

If you honestly care about such hardware, then you can use more than one texture. But it should be noted that this hardware is over a decade old.