在glutBitmapCharacter openGL中加倍

时间:2012-12-11 15:54:51

标签: opengl

快速提问:

如何使用

绘制double值

glutBitmapCharacter

我尝试了很多选项,但没有一个可行,我不知道如何将double转换为char *

1 个答案:

答案 0 :(得分:1)

#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;
}