首页 > Windows开发 > 详细

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

时间:2014-02-25 07:00:20      阅读:507      评论:0      收藏:0      [点我收藏+]
   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;
}

运行结果:

bubuko.com,布布扣

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

原文:http://blog.csdn.net/biggbang/article/details/19804171

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!