132001f49Smrg/*
232001f49Smrg * Test Z values of glBitmap.
332001f49Smrg * Brian Paul
432001f49Smrg * 19 Feb 2010
532001f49Smrg */
632001f49Smrg
732001f49Smrg
832001f49Smrg#include <assert.h>
932001f49Smrg#include <stdio.h>
1032001f49Smrg#include <stdlib.h>
1132001f49Smrg#include <string.h>
1232001f49Smrg#include <math.h>
1332001f49Smrg#include <GL/glew.h>
1432001f49Smrg#include "glut_wrap.h"
1532001f49Smrg
1632001f49Smrg
1732001f49Smrgstatic GLint Win = 0;
1832001f49Smrg
1932001f49Smrg
2032001f49Smrgstatic void
2132001f49SmrgPrintString(const char *s)
2232001f49Smrg{
2332001f49Smrg   while (*s) {
2432001f49Smrg      glutBitmapCharacter(GLUT_BITMAP_8_BY_13, (int) *s);
2532001f49Smrg      s++;
2632001f49Smrg   }
2732001f49Smrg}
2832001f49Smrg
2932001f49Smrg
3032001f49Smrgstatic void
3132001f49SmrgDisplay(void)
3232001f49Smrg{
3332001f49Smrg   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
3432001f49Smrg
3532001f49Smrg   glMatrixMode(GL_PROJECTION);
3632001f49Smrg   glLoadIdentity();
3732001f49Smrg   glOrtho(-3.0, 3.0, -3.0, 3.0, -2.0, 2.0);
3832001f49Smrg
3932001f49Smrg   glMatrixMode(GL_MODELVIEW);
4032001f49Smrg   glLoadIdentity();
4132001f49Smrg
4232001f49Smrg   glColor3f(1, 1, 1);
4332001f49Smrg   glRasterPos2f(-2.0, 2.6);
4432001f49Smrg   PrintString("Z = -1.0");
4532001f49Smrg   glRasterPos2f(-0.5, 2.6);
4632001f49Smrg   PrintString("Z = 0.0");
4732001f49Smrg   glRasterPos2f(1.0, 2.6);
4832001f49Smrg   PrintString("Z = 1.0");
4932001f49Smrg
5032001f49Smrg   glColor3f(0, 0.4, 0.6);
5132001f49Smrg   glBegin(GL_QUADS);
5232001f49Smrg   glVertex3f(-2.0, -2.5, -1);
5332001f49Smrg   glVertex3f(-1.0, -2.5, -1);
5432001f49Smrg   glVertex3f(-1.0, 2.5, -1);
5532001f49Smrg   glVertex3f(-2.0, 2.5, -1);
5632001f49Smrg
5732001f49Smrg   glVertex3f(-0.5, -2.5, 0);
5832001f49Smrg   glVertex3f(0.5, -2.5, 0);
5932001f49Smrg   glVertex3f(0.5, 2.5, 0);
6032001f49Smrg   glVertex3f(-0.5, 2.5, 0);
6132001f49Smrg
6232001f49Smrg   glVertex3f(1.0, -2.5, 1);
6332001f49Smrg   glVertex3f(2.0, -2.5, 1);
6432001f49Smrg   glVertex3f(2.0, 2.5, 1);
6532001f49Smrg   glVertex3f(1.0, 2.5, 1);
6632001f49Smrg   glEnd();
6732001f49Smrg
6832001f49Smrg   glColor3f(1, 1, 1);
6932001f49Smrg
7032001f49Smrg   glRasterPos3f(-2.0, -1, -1.0);
7132001f49Smrg   PrintString("This is a bitmap string drawn at z = -1.0");
7232001f49Smrg
7332001f49Smrg   glRasterPos3f(-2.0, 0, 0.0);
7432001f49Smrg   PrintString("This is a bitmap string drawn at z = 0.0");
7532001f49Smrg
7632001f49Smrg   glRasterPos3f(-2.0, 1, 1.0);
7732001f49Smrg   PrintString("This is a bitmap string drawn at z = 1.0");
7832001f49Smrg
7932001f49Smrg   glRasterPos3f(-1.5, -2.8, 0.0);
8032001f49Smrg   PrintString("GL_DEPTH_FUNC = GL_LEQUAL");
8132001f49Smrg
8232001f49Smrg   glutSwapBuffers();
8332001f49Smrg}
8432001f49Smrg
8532001f49Smrg
8632001f49Smrgstatic void
8732001f49SmrgReshape(int width, int height)
8832001f49Smrg{
8932001f49Smrg   glViewport(0, 0, width, height);
9032001f49Smrg}
9132001f49Smrg
9232001f49Smrg
9332001f49Smrgstatic void
9432001f49SmrgKey(unsigned char key, int x, int y)
9532001f49Smrg{
9632001f49Smrg   if (key == 27) {
9732001f49Smrg      glutDestroyWindow(Win);
9832001f49Smrg      exit(0);
9932001f49Smrg   }
10032001f49Smrg   glutPostRedisplay();
10132001f49Smrg}
10232001f49Smrg
10332001f49Smrg
10432001f49Smrgstatic void
10532001f49SmrgInit(void)
10632001f49Smrg{
10732001f49Smrg   glClearColor(0.25, 0.25, 0.25, 0.0);
10832001f49Smrg   glDepthFunc(GL_LEQUAL);
10932001f49Smrg   glEnable(GL_DEPTH_TEST);
11032001f49Smrg}
11132001f49Smrg
11232001f49Smrg
11332001f49Smrgint
11432001f49Smrgmain(int argc, char *argv[])
11532001f49Smrg{
11632001f49Smrg   glutInitWindowSize(400, 400);
11732001f49Smrg   glutInit(&argc, argv);
11832001f49Smrg   glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
11932001f49Smrg   Win = glutCreateWindow(argv[0]);
12032001f49Smrg   glewInit();
12132001f49Smrg   glutReshapeFunc(Reshape);
12232001f49Smrg   glutKeyboardFunc(Key);
12332001f49Smrg   glutDisplayFunc(Display);
12432001f49Smrg   Init();
12532001f49Smrg   glutMainLoop();
12632001f49Smrg   return 0;
12732001f49Smrg}
128