Question about a program referenced in the OpenGL programming book...

Started by
7 comments, last by BrknPhoenix 17 years, 9 months ago
The book 'Beginning OpenGL Programming' was made by the founder/s of this site as I understand it, so I figured what better place to ask :) The question is about a font programming recommended by the book called glFont2. There is a .h and a .cpp, which the directions with glFont2 say to compile with my project, so they're in my project... And glfont2.h generates compiler errors :( on this line:
		//Height is the same for now...might change in future
		size->second = (int)(header.chars[header.start_char]->dy *
			header.tex_height);
The error: base operand of '->' has non-pointer type 'glfont::GLFont::GLFontChar' I assume this compiles successfully for others, else it wouldn't be included in the book, so why does it generate an error for me? :(
Advertisement
Quote:Original post by BrknPhoenix
The book 'Beginning OpenGL Programming' was made by the founder/s of this site as I understand it, so I figured what better place to ask :)

The question is about a font programming recommended by the book called glFont2. There is a .h and a .cpp, which the directions with glFont2 say to compile with my project, so they're in my project...

And glfont2.h generates compiler errors :(

on this line:

		//Height is the same for now...might change in future		size->second = (int)(header.chars[header.start_char]->dy *			header.tex_height);


The error: base operand of '->' has non-pointer type 'glfont::GLFont::GLFontChar'

I assume this compiles successfully for others, else it wouldn't be included in the book, so why does it generate an error for me? :(


The:
size->second = (int)(header.chars[header.start_char]->dy * header.tex_height);

part should be:
size->second = (int)(header.chars[header.start_char].dy * header.tex_height);


I'm not sure if that will run correctly, as I just took the source and made sure it compiled. But I'm pretty sure it was just a typo. [smile]
Quote:"->dy" should be ".dy"... I think.


When I change it to that, there is a new error of 'second has not been declared'
Quote:Original post by BrknPhoenix
Quote:"->dy" should be ".dy"... I think.


When I change it to that, there is a new error of 'second has not been declared'


Hmm... Works for me.

Previous:
//Calculates the size in pixels of a character array	template<class T> void GetStringSize (const T *text,		std::pair<int, int> *size)	{		const T *i;		GLFontChar *glfont_char;		float width;		//Height is the same for now...might change in future		size->second = (int)(header.chars[header.start_char]->dy *			header.tex_height);		//Calculate width of string		width = 0.0F;		for (i = text; *i != (T)'\0'; i++)		{			//Make sure character is in range			if (*i < header.start_char || *i > header.end_char)				continue;			//Get pointer to glFont character			glfont_char = &header.chars[*i - header.start_char];			//Get width and height			width += glfont_char->dx * header.tex_width;		}		//Save width		size->first = (int)width;	}	//Template function to calculate size of a std::basic_string	template<class T> void GetStringSize (		const std::basic_string<T> &text, std::pair<int, int> *size)	{		unsigned int i;		T *c;		GLFontChar *glfont_char;		float width;		//Height is the same for now...might change in future		size->second = (int)(header.chars[header.start_char]->dy *			header.tex_height);		//Calculate width of string		width = 0.0F;		for (i = 0; i < text.size(); i++)		{			//Make sure character is in range			c = text;			if (c < header.start_char || c > header.end_char)				continue;			//Get pointer to glFont character			glfont_char = &header.chars[c - header.start_char];			//Get width and height			width += glfont_char->dx * header.tex_width;		}		//Save width		size->first = (int)width;	}

No compile errors:
//Calculates the size in pixels of a character array	template<class T> void GetStringSize (const T *text,		std::pair<int, int> *size)	{		const T *i;		GLFontChar *glfont_char;		float width;		//Height is the same for now...might change in future		size->second = (int)(header.chars[header.start_char].dy *			header.tex_height);		//Calculate width of string		width = 0.0F;		for (i = text; *i != (T)'\0'; i++)		{			//Make sure character is in range			if (*i < header.start_char || *i > header.end_char)				continue;			//Get pointer to glFont character			glfont_char = &header.chars[*i - header.start_char];			//Get width and height			width += glfont_char->dx * header.tex_width;		}		//Save width		size->first = (int)width;	}	//Template function to calculate size of a std::basic_string	template<class T> void GetStringSize (		const std::basic_string<T> &text, std::pair<int, int> *size)	{		unsigned int i;		T *c;		GLFontChar *glfont_char;		float width;		//Height is the same for now...might change in future		size->second = (int)(header.chars[header.start_char].dy *			header.tex_height);		//Calculate width of string		width = 0.0F;		for (i = 0; i < text.size(); i++)		{			//Make sure character is in range			c = text;			if (c < header.start_char || c > header.end_char)				continue;			//Get pointer to glFont character			glfont_char = &header.chars[c - header.start_char];			//Get width and height			width += glfont_char->dx * header.tex_width;		}		//Save width		size->first = (int)width;	}


Those are the only changes I made (in red).
Well.... I'm using Dev-C++ to compile, could that have anything to do with it?
Quote:Original post by BrknPhoenix
Well.... I'm using Dev-C++ to compile, could that have anything to do with it?


It shouldn't. Dev-Cpp uses GCC and I tested this with GCC, so I don't know. It still gives you an error when you change the things in red? Odd...
Actually, I can't see any red in your post at all. Perhaps there is an account option or something that I don't have enabled...

edit: Weird, I clicked edit on your post to see the tags, and when I returned to your post after, I could see the red. Huh... *shrug* Oh well. I'm at work so I can't try it right now but I'll compile it with the changes when I get home.
Huzaaaaah it works now, thanks :)

I must have misinterpreted what you said earlier and replaced the wrong -> with .

I wonder why this is the standard file for glFont if it doesn't compile.... huh... oh well, thanks
Gaaaaaaaah I've run across another problem. Okay.... I'm following the directions provided with glFont to the letter, and it isn't displaying the fonts correctly. It displays them:

1) Upside down
2) Flipped horizontally
3) It shows a lot more random characters than just the string I wanted

For example, if I tell it I want it to output "RAWR!", it will put...

DO[]A
AMMFL
aggoM
!RWAR

Flipped horizontally and upside down of course :)

This topic is closed to new replies.

Advertisement