OpenGL:绘制矩形后不显示文本

时间:2012-01-04 07:13:09

标签: c++ opengl glut

我正在设计一个秤。在那里我需要以白色显示数字。目前在下面的代码中,我试图只显示“825”。之后,我尝试绘制一个灰色的矩形框,以获得比例的背景。但是当我尝试执行时,我看不到数字(“825,在下面的例子中)是不可见的。只有灰色矩形可见。

#define SPD_SCALE_TAPE_STATIC_LINE_COLOR_160        160        // Light GRAY
#define SPD_SCALE_TAPE_STATIC_LINE_COLOR_120        120        // Light GRAY
#define SPD_SCALE_TAPE_STATIC_LINE_COLOR_180        180        // Light GRAY
#define SPD_SCALE_TAPE_STATIC_LINE_COLOR_050        50        // Light GRAY

// Co-ordinates for GRAY box
#define SPD_SCALE_TAPE_GRAY_X1    -8.0
#define SPD_SCALE_TAPE_GRAY_Y1    0.5
#define SPD_SCALE_TAPE_GRAY_X2    -6.0
#define SPD_SCALE_TAPE_GRAY_Y2    6.3

// Method to draw the text with TIMES NEW ROMAN with FONT size = 24
void drawText_TIMES_24(float x, float y, float z, char* text)
{

    int i_len = 0;

    i_len = strlen(text);

    if( i_len > 0)
    {
        glPushMatrix();
        glRasterPos3f(x,y,z);

        while( *text != '\0' )
        {
        if( i_len == 2 )
        {
            glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, ' ');
            i_len = 0;
        }
        else
        {
            glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, *text);
            text = text+1;
         }
       }
        glPopMatrix();
    }
}


void drawAir_Speed_ReadOut_Val(void)
{
    char a[] = "825";
    glColor3ub(0, 255, 0);

    drawText_TIMES_24(-7.5, 3.0, 0.0, a);

}

// Method to draw Spd Scale Tape Gray Rect
void drawSpd_Scale_Tape_Gray_Rect(void)
{
    glColor3ub(SPD_SCALE_TAPE_STATIC_LINE_COLOR_050,     SPD_SCALE_TAPE_STATIC_LINE_COLOR_050, SPD_SCALE_TAPE_STATIC_LINE_COLOR_050);

// Draw TOP rectangle GRAY box
    glRectf(SPD_SCALE_TAPE_GRAY_X1, SPD_SCALE_TAPE_GRAY_Y1, SPD_SCALE_TAPE_GRAY_X2, SPD_SCALE_TAPE_GRAY_Y2);

// Draw BOTTOM rectangle GRAY box
glRectf(-6.0, -0.5, -8.0, -6.3);

// Draw TOP triangle GRAY box
drawTriangle (-6.5, 0.5, -6.0, 0.0, -6.0, 0.5);

// Draw BOTTOM triangle GRAY box
drawTriangle (-6.5, -0.5, -6.0, 0.0, -6.0, -0.5);

}

void draw(void)
{
  drawAir_Speed_ReadOut_Val();
  drawSpd_Scale_Tape_Gray_Rect();
}

1 个答案:

答案 0 :(得分:0)

猜测 - 您是否在drawText_TIMES_24()内的第一个glPushMatrix()之前调用了glRasterPos3f()?如果是这种情况,你应该考虑调用glTranslatef()而不是做额外的glRasterPos3f()?