《高效学习OpenGL》 之 位图与字体 glRasterPos(), glWindowPos(), glBitmap()

   void glRasterPos4d (GLdouble x, GLdouble y, GLdouble z = 0, GLdouble w = 1);
   void glRasterPos4dv (const GLdouble *v);
   //确定当前光栅位置,x,y,z,w指定了当前光栅位置的坐标
   glWindowPos(Type x, Type y, Type z);
   //用窗口坐标指定当前光栅位置,不必进行矩阵变换、裁剪、或纹理坐标生成。z值被变换为由glDepthRange()设置的当前近侧平面值和远侧平面值

   void glBitmap (GLsizei , GLsizei height, GLfloat xorig, GLfloat yorig, GLfloat , GLfloat , const GLubyte *bitmap);
   //绘制由bitmap指定的位图,bitmap是一个指向位图图像的指针,位图的原点是当前光栅位置,如果当前光栅位置无效,则这个函数不会绘制任何东西。
   //width和height表示位图的宽度和高度,xorig和yorig定义了位图的原点,他是根据当期光栅位置确定的,右上为正。
   //xmove和ymove表示位图光栅化之后光栅坐标的x增加值和y增加值

函数实例

#include <GL/glut.h>
#include <stdlib.h>

GLubyte rasters[24] = {
   0xc0, 0x00, 0xc0, 0x00, 0xc0, 0x00, 0xc0, 0x00, 0xc0, 0x00,
   0xff, 0x00, 0xff, 0x00, 0xc0, 0x00, 0xc0, 0x00, 0xc0, 0x00,
   0xff, 0xc0, 0xff, 0xc0};

void init(void)
{
   glPixelStorei (GL_UNPACK_ALIGNMENT, 1);
   glClearColor (0.0, 0.0, 0.0, 0.0);
}

void display(void)
{
   glClear(GL_COLOR_BUFFER_BIT);
   glColor3f (1.0, 1.0, 1.0);
   glRasterPos2i (20, 20);//确定当前光栅位置,x,y,z,w指定了当前光栅位置的坐标
   glBitmap (10, 12, 0.0, 0.0, 11.0, 0.0, rasters);
   glBitmap (10, 12, 0.0, 0.0, 11.0, 0.0, rasters);
   glBitmap (10, 12, 0.0, 0.0, 11.0, 0.0, rasters);
   //绘制由bitmap指定的位图,bitmap是一个指向位图图像的指针,位图的原点是当前光栅位置,如果当前光栅位置无效,则这个函数不会绘制任何东西。
   //width和height表示位图的宽度和高度,xorig和yorig定义了位图的原点,他是根据当期光栅位置确定的,右上为正。
   //xmove和ymove表示位图光栅化之后光栅坐标的x增加值和y增加值
   glFlush();
}

void reshape(int w, int h)
{
   glViewport(0, 0, (GLsizei) w, (GLsizei) h);
   glMatrixMode(GL_PROJECTION);
   glLoadIdentity();
   glOrtho (0, w, 0, h, -1.0, 1.0);
   glMatrixMode(GL_MODELVIEW);
}

void keyboard(unsigned char key, int x, int y)
{
   switch (key) {
      case 27:
         exit(0);
   }
}

/*  Main Loop
 *  Open window with initial window size, title bar, 
 *  RGBA display mode, and handle input events.
 */
int main(int argc, char** argv)
{
   glutInit(&argc, argv);
   glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
   glutInitWindowSize(100, 100);
   glutInitWindowPosition(100, 100);
   glutCreateWindow(argv[0]);
   init();
   glutReshapeFunc(reshape);
   glutKeyboardFunc(keyboard);
   glutDisplayFunc(display);
   glutMainLoop();
   return 0;
}

运行结果:


  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

虚坏叔叔

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值