glutBitmapCharacter函数的使用

我们从百度百科上摘抄了一部分介绍:

glutBitmapCharacter( font ,  character)

2功能简介编辑

glut工具函数,用于在glut窗口某位置显示字符。
由于是glut 内置函数,功能有所限制,只能显示英文 字符,而且字体、大小都不能任意设置。

3参数介绍与实例编辑

font

设置 字符的字体,选择范围如下:
(注明两个参数,其他与此类似)
GLUT_BITMAP_8_BY_13
GLUT_BITMAP_9_BY_15
GLUT_BITMAP_TIMES_ROMAN_10 字体:TIMES_ROMAN 大小:10
GLUT_BITMAP_TIMES_ROMAN_24 字体:TIMES_ROMAN 大小:24
GLUT_BITMAP_HELVETICA_10
GLUT_BITMAP_HELVETICA_12
GLUT_BITMAP_HELVETICA_18

character

要显示的字符。


我们主要是使用函数实现
void drawtext()
{  
    
        glClear(GL_COLOR_BUFFER_BIT);  
		        float x=200;
               float y=200;
        
        
        char *string="hello world! ";

  char *c;
  glRasterPos2f(x, y);
  for (c=string; *c != '\0'; c++) {
	  glutBitmapCharacter(GLUT_BITMAP_8_BY_13, *c);//此处为作图函数。不必要在glbegin()函数之间的。
  }
    
          
}  

完整的函数
#include<stdlib.h>  
#include <GL/glut.h>  

void myinit(void)  
{  
   
/* attributes */  
  
      glClearColor(1.0, 1.0, 1.0, 0.0); /* white background */  
      glColor3f(1.0, 0.0, 0.0); /* draw in red */  
  

  
      glMatrixMode(GL_PROJECTION);  
      glLoadIdentity();  
      gluOrtho2D(0.0, 500.0, 0.0, 500.0);  
      glMatrixMode(GL_MODELVIEW);  
}  
  
void drawtext()
{  
    
        glClear(GL_COLOR_BUFFER_BIT);  
		        float x=200;
               float y=200;
        
        
      char *string="hello world! ";
  char *c;
  glRasterPos2f(x, y);
  for (c=string; *c != '\0'; c++) {
	  glutBitmapCharacter(GLUT_BITMAP_8_BY_13, *c);
  }
    
          
}  
  
/* the display callback: */  
void display( void )  
{  
    glClear(GL_COLOR_BUFFER_BIT);  /*clear the window */  
  
    /*----------------------------------------*/  
    /*  viewport stuff                        */  
    /*----------------------------------------*/  
    /* set up a viewport in the screen window */  
    /* args to glViewport are left, bottom, width, height */  
    glViewport(0, 0, 500, 500);  
    /* NB: default viewport has same coords as in myinit, */  
    /* so this could be omitted: */  
  
      
    drawtext();
  
    /* and flush that buffer to the screen */  
    glFlush();   
 }  
  
int main(int argc, char** argv)  
{  
  
/* Standard GLUT initialization */  

    glutInit(&argc,argv);  
    glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB); /* default, not needed */  
    glutInitWindowSize(500,500); /* 500 x 500 pixel window */  
    glutInitWindowPosition(0,0); /* place window top left on display */  
    glutCreateWindow("写字"); /* window title */  
    glutDisplayFunc(display); /* display callback invoked when window opened */  
     myinit(); /* set attributes */  
    glutMainLoop(); /* enter event loop */  
}  



  • 4
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值