1 /*
2  * Test Z values of glBitmap.
3  * Brian Paul
4  * 19 Feb 2010
5  */
6 
7 
8 #include <assert.h>
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <string.h>
12 #include <math.h>
13 #include <glad/glad.h>
14 #include "glut_wrap.h"
15 
16 
17 static GLint Win = 0;
18 
19 
20 static void
PrintString(const char * s)21 PrintString(const char *s)
22 {
23    while (*s) {
24       glutBitmapCharacter(GLUT_BITMAP_8_BY_13, (int) *s);
25       s++;
26    }
27 }
28 
29 
30 static void
Display(void)31 Display(void)
32 {
33    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
34 
35    glMatrixMode(GL_PROJECTION);
36    glLoadIdentity();
37    glOrtho(-3.0, 3.0, -3.0, 3.0, -2.0, 2.0);
38 
39    glMatrixMode(GL_MODELVIEW);
40    glLoadIdentity();
41 
42    glColor3f(1, 1, 1);
43    glRasterPos2f(-2.0, 2.6);
44    PrintString("Z = -1.0");
45    glRasterPos2f(-0.5, 2.6);
46    PrintString("Z = 0.0");
47    glRasterPos2f(1.0, 2.6);
48    PrintString("Z = 1.0");
49 
50    glColor3f(0, 0.4, 0.6);
51    glBegin(GL_QUADS);
52    glVertex3f(-2.0, -2.5, -1);
53    glVertex3f(-1.0, -2.5, -1);
54    glVertex3f(-1.0, 2.5, -1);
55    glVertex3f(-2.0, 2.5, -1);
56 
57    glVertex3f(-0.5, -2.5, 0);
58    glVertex3f(0.5, -2.5, 0);
59    glVertex3f(0.5, 2.5, 0);
60    glVertex3f(-0.5, 2.5, 0);
61 
62    glVertex3f(1.0, -2.5, 1);
63    glVertex3f(2.0, -2.5, 1);
64    glVertex3f(2.0, 2.5, 1);
65    glVertex3f(1.0, 2.5, 1);
66    glEnd();
67 
68    glColor3f(1, 1, 1);
69 
70    glRasterPos3f(-2.0, -1, -1.0);
71    PrintString("This is a bitmap string drawn at z = -1.0");
72 
73    glRasterPos3f(-2.0, 0, 0.0);
74    PrintString("This is a bitmap string drawn at z = 0.0");
75 
76    glRasterPos3f(-2.0, 1, 1.0);
77    PrintString("This is a bitmap string drawn at z = 1.0");
78 
79    glRasterPos3f(-1.5, -2.8, 0.0);
80    PrintString("GL_DEPTH_FUNC = GL_LEQUAL");
81 
82    glutSwapBuffers();
83 }
84 
85 
86 static void
Reshape(int width,int height)87 Reshape(int width, int height)
88 {
89    glViewport(0, 0, width, height);
90 }
91 
92 
93 static void
Key(unsigned char key,int x,int y)94 Key(unsigned char key, int x, int y)
95 {
96    if (key == 27) {
97       glutDestroyWindow(Win);
98       exit(0);
99    }
100    glutPostRedisplay();
101 }
102 
103 
104 static void
Init(void)105 Init(void)
106 {
107    glClearColor(0.25, 0.25, 0.25, 0.0);
108    glDepthFunc(GL_LEQUAL);
109    glEnable(GL_DEPTH_TEST);
110 }
111 
112 
113 int
main(int argc,char * argv[])114 main(int argc, char *argv[])
115 {
116    glutInitWindowSize(400, 400);
117    glutInit(&argc, argv);
118    glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
119    Win = glutCreateWindow(argv[0]);
120    gladLoadGL();
121    glutReshapeFunc(Reshape);
122    glutKeyboardFunc(Key);
123    glutDisplayFunc(Display);
124    Init();
125    glutMainLoop();
126    return 0;
127 }
128