OpenGL -- 位图 glBitmap

来源:互联网 发布:mysql w10 编辑:程序博客网 时间:2024/06/16 10:22

直接代码和结果

代码

#include <gl\glut.h>    #include <gl\GLU.h>#include <gl\GL.h>#include <math.h>#include <windows.h>#include <stdio.h>#include <stdlib.h>#define PI 3.1415926     int WinWidth, WinHeight;void Draw(){    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);    glColor3f(1.0f, 0.0f, 0.0f);    // 一个向上的箭头    GLubyte bitShape[20] = {        0x1c, 0x00, 0x1c, 0x00, 0x1c, 0x00, 0x1c, 0x00, 0x1c, 0x00,        0xff, 0x80, 0x7f, 0x00, 0x3e, 0x00, 0x1c, 0x00, 0x08, 0x00    };    glPixelStorei(GL_UNPACK_ALIGNMENT,1);    glRasterPos2i(100, 100);    glBitmap(9, 10, 0.0, 0.0, 100, 100, bitShape);    glutSwapBuffers();}void Reshape(int w, int h){    WinWidth = w;    WinHeight = h;    // //改变显示区域,起始位置为客户端窗口左下角(非坐标原点)    glViewport(0, 0, w, h);    glMatrixMode(GL_PROJECTION);    glLoadIdentity();    glOrtho(0, w, 0, h, -1.0, 1.0);    glMatrixMode(GL_MODELVIEW);}int main(int argc, char *argv[]){    WinWidth = 400;    WinHeight = 400;    glutInit(&argc, argv);    glutInitDisplayMode(GLUT_DEPTH | GLUT_RGB | GLUT_DOUBLE);    //glutInitWindowPosition(100, 100);    glutInitWindowSize(WinWidth, WinHeight);    glutCreateWindow("HelloOpenGL");    /*    目的:当窗口尺寸改变时,图形比例不发生变化    思路:窗口宽高比改变时,通过改变窗口显示区域大小,并利用投影矩阵改变观测物体大小使之适应变化。    */    glutReshapeFunc(&Reshape);    glutDisplayFunc(&Draw);    glutMainLoop();    return 0;}

截图

这里写图片描述

参考

  • 《计算机图形学》(第四版)Page 58.

  • http://www.cnblogs.com/tekkaman/p/3918245.html

  • OpenGL 位图和图像概念
    http://www.cnblogs.com/wendao/archive/2011/12/23/ogl_bitmap_image_learning.html

位图是由1和0组成的矩形数组,作为窗口中一个矩形区域的绘图掩码。 假设我们正在绘制一副位图,并且当前的光栅颜色是红色。在位图中为1的地方,帧缓冲区中的对应像素就用红色像素(或者根据实际生效的片段操作,与红色像素进行混合)代替。对于位图中为0的地方,就不会生成片段,像素的内容不受影响。位图的最常见用途就是在屏幕上绘制字符。

0 0
原创粉丝点击