Problem after changing numbers to variables

Started by
5 comments, last by Moriquendi 14 years ago
Hey guys! I have strange problem. I want to make bitmap fonts. I loaded texture, and now I have to set coords for each letter. Here it is:

glBindTexture(GL_TEXTURE_2D, tex_font);	

  		glNewList(base+licznik,GL_COMPILE);
			glBegin(GL_QUADS);
glTexCoord2f(0.5937			,1-0.00195);
 glVertex2i(0,0);
				
glTexCoord2f(0.5937+0.06445 ,1-0.00195);
glVertex2i(20,0);
				
glTexCoord2f(0.5937+0.06445 ,1-0.00195-0.1035);			glVertex2i(20,50);						
				
glTexCoord2f(0.5937	, 1-0.00195-0.1035);
 glVertex2i(0,50);

			glEnd();
			glTranslated(10,0,0);
		glEndList();
And it's "working". As you can see I put static numbers. These numbers are coords for letter "0" (number actually). But when I put variables into this code:

glTexCoord2f(poz_x	,(1-poz_y));
 glVertex2i(0,0);
				
glTexCoord2f((poz_x+z_width) ,(1-poz_y));	
 glVertex2i(20,0);
.....
It's nor working. I can see just a black background - no letters. I'm 100% sure that variables have the same value. So why it's not working? (Variables are float)
Advertisement
Quote:Original post by Moriquendi
I'm 100% sure that variables have the same value.


100% sure as in you put a breakpoint and inspected the value just before those functions are called?

-me

Yep, I had put breakpoint and checked value.
The same.

Edit:
I don't know, it sounds stupid.
I create this letters in a loop. Maybe somethings goes wrong when I create many latters with different coords...
Do you have any article about bitmap fonts? :\
Hey,
I don't know what's happening.

When I put in code this:
  poz_x = StringToInt(pozyc_x);  poz_y = StringToInt(pozyc_y);  i_width = StringToInt(s_width);  ///s_width - string with number  i_height = StringToInt(s_height);  poz_x = 0.5937;  poz_y = 0.00195;  z_width = 0.06445;  z_height = 0.1035;...		glTexCoord2f(poz_x ,1-poz_y);		glVertex2i(0,0);..........	

it work's fine. But when I don't - variables are the same (checked thanks to breakpoints) but it doesn't work...


So I variables have correct values...
I guess that there is sth wrong when I convert string to Int.
Here's stringtoInt function:

int StringToInt(string str){	std::stringstream ss;    int temp;    ss << str;    ss >> temp;    return temp;}


[Edited by - Moriquendi on April 16, 2010 11:23:50 AM]
Why are you converting from strings to ints when your variables are floats?
Ok, I changed StringToInt to atof() function, but it doesn't metter becouse I convert strings that have int variables.
Later, I write:
poz_x = poz_x/512;



I think the problem isn't variables. I have to do sth wrong in my code...
Can anybody look at it? : -<

http://wklej.to/4640
I DIT IT!!!! Yeeeeaaa

I have a bug where I call the lists.
Thanks you all for help! Love gamedev.net!

This topic is closed to new replies.

Advertisement