1 #define GLUT_DISABLE_ATEXIT_HACK
 2 #include "gl/glut.h"
 3 
 4 GLubyte zebra[]={0x00,0x00,0x00,0x00,
 5                 0x37,0x20,0x00,0x00,
 6                 0x13,0x60,0x00,0x00,
 7                 0x10,0x60,0x00,0x00,
 8                 0x14,0x60,0x00,0x00,
 9                 0x16,0x38,0x00,0x00,
10                 0x06,0x18,0x00,0x00,
11                 0x07,0x10,0x00,0x00,
12                 0x07,0x40,0x00,0x00,
13                 0x03,0x60,0x00,0x00,
14                 0x03,0x70,0x00,0x00,
15                 0x01,0x70,0x00,0x3e,
16                 0x02,0x78,0x0a,0x78,
17                 0x01,0x18,0x01,0x60,
18                 0x01,0x48,0x0a,0x08,
19                 0x00,0x62,0x14,0x00,
20                 0x00,0xf6,0x11,0xf0,
21                 0x00,0xfa,0x43,0xe0,
22                 0x00,0x7c,0xea,0x60,
23                 0x00,0x3d,0xcb,0x60,
24                 0x00,0x19,0x9d,0x40,
25                 0x00,0x08,0x22,0xc0,
26                 0x00,0x00,0x09,0x80,
27                 0x00,0x02,0x40,0x80,
28                 0x00,0x01,0x1b,0x80,
29                 0x00,0x01,0x08,0x80,
30                 0x00,0x00,0x00,0x00,
31                 0x00,0x00,0x28,0x00,
32                 0x00,0x00,0x29,0x00,
33                 0x00,0x00,0x49,0x80,
34                 0x00,0x00,0x99,0x80,
35                 0x00,0x00,0x00,0x00,
36 };
37 
38 void Initialization(void);
39 void OnDisPlay(void);
40 void OnReshape(int,int);
41 
42 void main(int argc,char* argv[])
43 {
44     glutInit(&argc,argv);
45     glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
46     glutInitWindowSize(600,480);
47     glutCreateWindow("EXAM601");
48 
49     glutReshapeFunc(OnReshape);
50     glutDisplayFunc(OnDisPlay);
51 
52     Initialization();
53     
54     glutMainLoop();
55 }
56 
57 void Initialization(void)
58 {
59     glClearColor(1,1,1,1);
60 }
61 
62 void OnDisPlay(void)
63 {
64     glClear(GL_COLOR_BUFFER_BIT);
65 
66     glColor3f(1,0,0);
67 
68     glRasterPos2i(-3,-3); //指定当前光栅位置
69     glBitmap(32,32,0,0,0,0,zebra);
70 
71     glPointSize(5);
72     glBegin(GL_POINTS);
73         glColor3f(0,1,0);
74         glVertex2i(0,0);
75     glEnd();
76 
77     glutSwapBuffers();
78 }
79 
80 void OnReshape(int w,int h)
81 {
82     GLfloat aspect =(GLfloat)w/(GLfloat)h;
83     GLfloat nRange=100.0f;
84  
85     glViewport(0,0,w,h);
86  
87     glMatrixMode(GL_PROJECTION); //将当前矩阵指定为投影模式
88     glLoadIdentity();
89  
90     //设置三维投影区
91  
92     if (w<=h)
93      glOrtho(-nRange,nRange,-nRange*aspect,nRange*aspect,-nRange,nRange);
94     else
95      glOrtho(-nRange,nRange,-nRange/aspect,nRange/aspect,-nRange,nRange);
96 }
 posted on 2012-04-30 10:46  xiacl  阅读(261)  评论(0)    收藏  举报