OpenGL函数学习

1.glBitmap

例子 画出三个F。各字符间距不同。

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

GLubyte rasters[24] = {
   0xc00x000xc00x000xc00x000xc00x000xc00x00,
   0xff0x000xff0x000xc00x000xc00x000xc00x00,
   0xff0xc00xff0xc0};

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

void display(void)
{
   glClear(GL_COLOR_BUFFER_BIT);
   glColor3f (1.01.01.0);
   glRasterPos2i (2020);
   //void glBitmap(    GLsizei      width, //位图的宽度
     
//GLsizei      height, //位图的高度
     //GLfloat      xorig, //定义位图原点
     //GLfloat      yorig, //定义位图原点
     
//GLfloat      xmove, //表示位图被光栅化之后的光栅位置的x y增加值 
     
//GLfloat      ymove,
     
//const GLubyte *      bitmap);

    
//11.0 光栅后 光栅位置在x向移动10个像素
   glBitmap (10120.00.010.00.0, rasters);
   //光栅后 光栅位置在x向移动20个像素
   glBitmap (10120.00.020.00.0, rasters);
   //11.0 光栅后 光栅位置在x向移动40个像素
   glBitmap (10120.00.040.00.0, rasters);
   glFlush();
}

void reshape(int w, int h)
{
   glViewport(00, (GLsizei) w, (GLsizei) h);
   glMatrixMode(GL_PROJECTION);
   glLoadIdentity();
   glOrtho (0, w, 0, h, -1.01.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(100100);
   glutInitWindowPosition(100100);
   glutCreateWindow(argv[0]);
   init();
   glutReshapeFunc(reshape);
   glutKeyboardFunc(keyboard);
   glutDisplayFunc(display);
   glutMainLoop();
   return 0;

}

 如图所示

 

 

posted @ 2012-05-28 14:29  thinkpore  阅读(129)  评论(0)    收藏  举报