Jump to content
  • Advertisement
Sign in to follow this  
BrknPhoenix

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

This topic is 4427 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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? :(

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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).

Share this post


Link to post
Share on other sites
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...

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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 :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!