快速提问:
我怎样才能使用双倍的价值
glutBitmapCharacter
?
我尝试了很多选项,但没有一个有效,我不知道如何将 double 转换为 char *
#include <GL/glut.h>
#include <sstream>
#include <iomanip>
void glString( const std::string str, void* font = GLUT_BITMAP_8_BY_13 )
{
    for( size_t i = 0; i < str.size(); ++i )
    {
        glutBitmapCharacter( font, str[i] );
    }
}
void display()
{
    glClear( GL_COLOR_BUFFER_BIT );
    glMatrixMode( GL_PROJECTION );
    glLoadIdentity();
    double w = glutGet( GLUT_WINDOW_WIDTH );
    double h = glutGet( GLUT_WINDOW_HEIGHT );
    glOrtho( 0, w, h, 0, -1, 1);
    glMatrixMode( GL_MODELVIEW );
    glLoadIdentity();
    glColor3ub( 255, 255, 255 );
    glRasterPos2i( 50, 50 );
    double val = 3.14159265358979323846;
    std::ostringstream oss;
    oss << std::setprecision(17) << val;
    glString( oss.str() );
    glutSwapBuffers();
}
int main( int argc, char **argv )
{
    glutInit( &argc, argv );
    glutInitDisplayMode( GLUT_RGBA | GLUT_DOUBLE );
    glutInitWindowSize( 640, 480 );
    glutCreateWindow( "Text" );
    glutDisplayFunc( display );
    glutMainLoop();
    return 0;
}