J
Jim Langston
I am writing some functions desgined to output text to an opengl window. I
wish to support both single byte character and multi-byte characters. This
works rather well and I wind up with:
template <class t>
void jglDrawText( const jglFont& font, t text, jglRGBColor rGBC, const
jglVertex2& position ) {
glColor3f( rGBC.red, rGBC.green, rGBC.blue);
// Position The Text On The Screen
glRasterPos2f(position.x, position.y);
jglPrint(font, text); // Print GL Text To The Screen
}
Where jglPrint has 2 signatures:
GLvoid jglPrint( const jglFont& font, const char *text );
GLvoid jglPrint( const jglFont& font, const wchar_t *text );
jglPrint is not a template because there are sufficient differences between
how to output a normal character .vs. a wide character (I look for
unprintable characters in wide char sets, etc..)
Now, I also want to allow jglPrint to be able to print strings, so I have
void jglDrawText( const jglFont& font, const std::string& text, jglRGBColor
rGBC, const jglVertex2& position );
which simply calls jglDrawText with text.c_str() as a parm for text.
Thinking about it, this also makes for a template as the code is exactly the
same for normal std::string and std::wstring. But now I get into a quandry.
I can't create 2 templates with the same name. Do I have to keep
specializing? Or do I have to come up with some other name for printing
strings? jglPrintString ?
It may be easier to just keep specializing as I add them but I was hoping
there was some pattern I'm missing here.
Regards,
Jim Langston
wish to support both single byte character and multi-byte characters. This
works rather well and I wind up with:
template <class t>
void jglDrawText( const jglFont& font, t text, jglRGBColor rGBC, const
jglVertex2& position ) {
glColor3f( rGBC.red, rGBC.green, rGBC.blue);
// Position The Text On The Screen
glRasterPos2f(position.x, position.y);
jglPrint(font, text); // Print GL Text To The Screen
}
Where jglPrint has 2 signatures:
GLvoid jglPrint( const jglFont& font, const char *text );
GLvoid jglPrint( const jglFont& font, const wchar_t *text );
jglPrint is not a template because there are sufficient differences between
how to output a normal character .vs. a wide character (I look for
unprintable characters in wide char sets, etc..)
Now, I also want to allow jglPrint to be able to print strings, so I have
void jglDrawText( const jglFont& font, const std::string& text, jglRGBColor
rGBC, const jglVertex2& position );
which simply calls jglDrawText with text.c_str() as a parm for text.
Thinking about it, this also makes for a template as the code is exactly the
same for normal std::string and std::wstring. But now I get into a quandry.
I can't create 2 templates with the same name. Do I have to keep
specializing? Or do I have to come up with some other name for printing
strings? jglPrintString ?
It may be easier to just keep specializing as I add them but I was hoping
there was some pattern I'm missing here.
Regards,
Jim Langston