132001f49Smrg/*
232001f49Smrg * Copyright (c) 1991, 1992, 1993 Silicon Graphics, Inc.
332001f49Smrg *
432001f49Smrg * Permission to use, copy, modify, distribute, and sell this software and
532001f49Smrg * its documentation for any purpose is hereby granted without fee, provided
632001f49Smrg * that (i) the above copyright notices and this permission notice appear in
732001f49Smrg * all copies of the software and related documentation, and (ii) the name of
832001f49Smrg * Silicon Graphics may not be used in any advertising or
932001f49Smrg * publicity relating to the software without the specific, prior written
1032001f49Smrg * permission of Silicon Graphics.
1132001f49Smrg *
1232001f49Smrg * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF
1332001f49Smrg * ANY KIND,
1432001f49Smrg * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
1532001f49Smrg * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
1632001f49Smrg *
1732001f49Smrg * IN NO EVENT SHALL SILICON GRAPHICS BE LIABLE FOR
1832001f49Smrg * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
1932001f49Smrg * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
2032001f49Smrg * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
2132001f49Smrg * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
2232001f49Smrg * OF THIS SOFTWARE.
2332001f49Smrg */
2432001f49Smrg
2532001f49Smrg#include <stdio.h>
2632001f49Smrg#include <string.h>
2732001f49Smrg#include <stdlib.h>
2832001f49Smrg#include "glut_wrap.h"
2932001f49Smrg
3032001f49Smrg
3132001f49Smrg#define OPENGL_WIDTH 24
3232001f49Smrg#define OPENGL_HEIGHT 13
3332001f49Smrg
3432001f49Smrg
3532001f49SmrgGLenum rgb, doubleBuffer, windType;
3632001f49Smrg
3732001f49Smrgfloat boxA[3] = {
3832001f49Smrg    0, 0, 0
3932001f49Smrg};
4032001f49Smrgfloat boxB[3] = {
4132001f49Smrg    -100, 0, 0
4232001f49Smrg};
4332001f49Smrgfloat boxC[3] = {
4432001f49Smrg    100, 0, 0
4532001f49Smrg};
4632001f49Smrgfloat boxD[3] = {
4732001f49Smrg    0, 95, 0
4832001f49Smrg};
4932001f49Smrgfloat boxE[3] = {
5032001f49Smrg    0, -105, 0
5132001f49Smrg};
5232001f49SmrgGLubyte OpenGL_bits1[] = {
5332001f49Smrg   0x00, 0x03, 0x00,
5432001f49Smrg   0x7f, 0xfb, 0xff,
5532001f49Smrg   0x7f, 0xfb, 0xff,
5632001f49Smrg   0x00, 0x03, 0x00,
5732001f49Smrg   0x3e, 0x8f, 0xb7,
5832001f49Smrg   0x63, 0xdb, 0xb0,
5932001f49Smrg   0x63, 0xdb, 0xb7,
6032001f49Smrg   0x63, 0xdb, 0xb6,
6132001f49Smrg   0x63, 0x8f, 0xf3,
6232001f49Smrg   0x63, 0x00, 0x00,
6332001f49Smrg   0x63, 0x00, 0x00,
6432001f49Smrg   0x63, 0x00, 0x00,
6532001f49Smrg   0x3e, 0x00, 0x00,
6632001f49Smrg};
6732001f49SmrgGLubyte OpenGL_bits2[] = {
6832001f49Smrg   0x00, 0x00, 0x00,
6932001f49Smrg   0xff, 0xff, 0x01,
7032001f49Smrg   0xff, 0xff, 0x01,
7132001f49Smrg   0x00, 0x00, 0x00,
7232001f49Smrg   0xf9, 0xfc, 0x01,
7332001f49Smrg   0x8d, 0x0d, 0x00,
7432001f49Smrg   0x8d, 0x0d, 0x00,
7532001f49Smrg   0x8d, 0x0d, 0x00,
7632001f49Smrg   0xcc, 0x0d, 0x00,
7732001f49Smrg   0x0c, 0x4c, 0x0a,
7832001f49Smrg   0x0c, 0x4c, 0x0e,
7932001f49Smrg   0x8c, 0xed, 0x0e,
8032001f49Smrg   0xf8, 0x0c, 0x00,
8132001f49Smrg};
8232001f49SmrgGLubyte logo_bits[] = {
8332001f49Smrg   0x00, 0x66, 0x66,
8432001f49Smrg   0xff, 0x66, 0x66,
8532001f49Smrg   0x00, 0x00, 0x00,
8632001f49Smrg   0xff, 0x3c, 0x3c,
8732001f49Smrg   0x00, 0x42, 0x40,
8832001f49Smrg   0xff, 0x42, 0x40,
8932001f49Smrg   0x00, 0x41, 0x40,
9032001f49Smrg   0xff, 0x21, 0x20,
9132001f49Smrg   0x00, 0x2f, 0x20,
9232001f49Smrg   0xff, 0x20, 0x20,
9332001f49Smrg   0x00, 0x10, 0x90,
9432001f49Smrg   0xff, 0x10, 0x90,
9532001f49Smrg   0x00, 0x0f, 0x10,
9632001f49Smrg   0xff, 0x00, 0x00,
9732001f49Smrg   0x00, 0x66, 0x66,
9832001f49Smrg   0xff, 0x66, 0x66,
9932001f49Smrg};
10032001f49Smrg
10132001f49Smrg#include "tkmap.c"
10232001f49Smrg
10332001f49Smrgstatic void Init(void)
10432001f49Smrg{
10532001f49Smrg
10632001f49Smrg    glClearColor(0.0, 0.0, 0.0, 0.0);
10732001f49Smrg    glClearIndex(0.0);
10832001f49Smrg}
10932001f49Smrg
11032001f49Smrgstatic void Reshape(int width, int height)
11132001f49Smrg{
11232001f49Smrg
11332001f49Smrg    glViewport(0, 0, (GLint)width, (GLint)height);
11432001f49Smrg
11532001f49Smrg    glMatrixMode(GL_PROJECTION);
11632001f49Smrg    glLoadIdentity();
11732001f49Smrg    gluOrtho2D(-175, 175, -175, 175);
11832001f49Smrg    glMatrixMode(GL_MODELVIEW);
11932001f49Smrg}
12032001f49Smrg
12132001f49Smrgstatic void Key(unsigned char key, int x, int y)
12232001f49Smrg{
12332001f49Smrg
12432001f49Smrg    switch (key) {
12532001f49Smrg      case 27:
12632001f49Smrg        exit(1);
12732001f49Smrg    }
12832001f49Smrg}
12932001f49Smrg
13032001f49Smrgstatic void Draw(void)
13132001f49Smrg{
13232001f49Smrg    float mapI[2], mapIA[2], mapIR[2];
13332001f49Smrg
13432001f49Smrg    glClear(GL_COLOR_BUFFER_BIT);
13532001f49Smrg
13632001f49Smrg    mapI[0] = 0.0;
13732001f49Smrg    mapI[1] = 1.0;
13832001f49Smrg    mapIR[0] = 0.0;
13932001f49Smrg    mapIR[1] = 0.0;
14032001f49Smrg    mapIA[0] = 1.0;
14132001f49Smrg    mapIA[1] = 1.0;
14232001f49Smrg
14332001f49Smrg    glPixelMapfv(GL_PIXEL_MAP_I_TO_R, 2, mapIR);
14432001f49Smrg    glPixelMapfv(GL_PIXEL_MAP_I_TO_G, 2, mapI);
14532001f49Smrg    glPixelMapfv(GL_PIXEL_MAP_I_TO_B, 2, mapI);
14632001f49Smrg    glPixelMapfv(GL_PIXEL_MAP_I_TO_A, 2, mapIA);
14732001f49Smrg    glPixelTransferi(GL_MAP_COLOR, GL_TRUE);
14832001f49Smrg
14932001f49Smrg    SetColor(COLOR_WHITE);
15032001f49Smrg    glRasterPos3fv(boxA);
15132001f49Smrg    glPixelStorei(GL_UNPACK_ROW_LENGTH, 24);
15232001f49Smrg    glPixelStorei(GL_UNPACK_SKIP_PIXELS, 8);
15332001f49Smrg    glPixelStorei(GL_UNPACK_SKIP_ROWS, 2);
15432001f49Smrg    glPixelStorei(GL_UNPACK_LSB_FIRST, GL_FALSE);
15532001f49Smrg    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
15632001f49Smrg    glBitmap(16, 12, 8.0, 0.0, 0.0, 0.0, logo_bits);
15732001f49Smrg
15832001f49Smrg    glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
15932001f49Smrg    glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
16032001f49Smrg    glPixelStorei(GL_UNPACK_SKIP_ROWS, 0);
16132001f49Smrg    glPixelStorei(GL_UNPACK_LSB_FIRST, GL_TRUE);
16232001f49Smrg    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
16332001f49Smrg
16432001f49Smrg    SetColor(COLOR_WHITE);
16532001f49Smrg    glRasterPos3fv(boxB);
16632001f49Smrg    glBitmap(OPENGL_WIDTH, OPENGL_HEIGHT, OPENGL_WIDTH, 0.0, OPENGL_WIDTH, 0.0,
16732001f49Smrg	     OpenGL_bits1);
16832001f49Smrg    glBitmap(OPENGL_WIDTH, OPENGL_HEIGHT, OPENGL_WIDTH, 0.0, OPENGL_WIDTH, 0.0,
16932001f49Smrg	     OpenGL_bits2);
17032001f49Smrg
17132001f49Smrg    SetColor(COLOR_YELLOW);
17232001f49Smrg    glRasterPos3fv(boxC);
17332001f49Smrg    glBitmap(OPENGL_WIDTH, OPENGL_HEIGHT, OPENGL_WIDTH, 0.0, OPENGL_WIDTH, 0.0,
17432001f49Smrg	     OpenGL_bits1);
17532001f49Smrg    glBitmap(OPENGL_WIDTH, OPENGL_HEIGHT, OPENGL_WIDTH, 0.0, OPENGL_WIDTH, 0.0,
17632001f49Smrg	     OpenGL_bits2);
17732001f49Smrg
17832001f49Smrg    SetColor(COLOR_CYAN);
17932001f49Smrg    glRasterPos3fv(boxD);
18032001f49Smrg    glBitmap(OPENGL_WIDTH, OPENGL_HEIGHT, OPENGL_WIDTH, 0.0, OPENGL_WIDTH, 0.0,
18132001f49Smrg	     OpenGL_bits1);
18232001f49Smrg    glBitmap(OPENGL_WIDTH, OPENGL_HEIGHT, OPENGL_WIDTH, 0.0, OPENGL_WIDTH, 0.0,
18332001f49Smrg	     OpenGL_bits2);
18432001f49Smrg
18532001f49Smrg    SetColor(COLOR_RED);
18632001f49Smrg    glRasterPos3fv(boxE);
18732001f49Smrg    glBitmap(OPENGL_WIDTH, OPENGL_HEIGHT, OPENGL_WIDTH, 0.0, OPENGL_WIDTH, 0.0,
18832001f49Smrg	     OpenGL_bits1);
18932001f49Smrg    glBitmap(OPENGL_WIDTH, OPENGL_HEIGHT, OPENGL_WIDTH, 0.0, OPENGL_WIDTH, 0.0,
19032001f49Smrg	     OpenGL_bits2);
19132001f49Smrg
19232001f49Smrg    glFlush();
19332001f49Smrg
19432001f49Smrg    if (doubleBuffer) {
19532001f49Smrg	glutSwapBuffers();
19632001f49Smrg    }
19732001f49Smrg}
19832001f49Smrg
19932001f49Smrgstatic GLenum Args(int argc, char **argv)
20032001f49Smrg{
20132001f49Smrg    GLint i;
20232001f49Smrg
20332001f49Smrg    rgb = GL_TRUE;
20432001f49Smrg    doubleBuffer = GL_FALSE;
20532001f49Smrg
20632001f49Smrg    for (i = 1; i < argc; i++) {
20732001f49Smrg	if (strcmp(argv[i], "-ci") == 0) {
20832001f49Smrg	    rgb = GL_FALSE;
20932001f49Smrg	} else if (strcmp(argv[i], "-rgb") == 0) {
21032001f49Smrg	    rgb = GL_TRUE;
21132001f49Smrg	} else if (strcmp(argv[i], "-sb") == 0) {
21232001f49Smrg	    doubleBuffer = GL_FALSE;
21332001f49Smrg	} else if (strcmp(argv[i], "-db") == 0) {
21432001f49Smrg	    doubleBuffer = GL_TRUE;
21532001f49Smrg	} else {
21632001f49Smrg	    printf("%s (Bad option).\n", argv[i]);
21732001f49Smrg	    return GL_FALSE;
21832001f49Smrg	}
21932001f49Smrg    }
22032001f49Smrg    return GL_TRUE;
22132001f49Smrg}
22232001f49Smrg
22332001f49Smrgint main(int argc, char **argv)
22432001f49Smrg{
22532001f49Smrg    glutInit(&argc, argv);
22632001f49Smrg
22732001f49Smrg    if (Args(argc, argv) == GL_FALSE) {
22832001f49Smrg	exit(1);
22932001f49Smrg    }
23032001f49Smrg
23132001f49Smrg    glutInitWindowPosition(0, 0); glutInitWindowSize( 300, 300);
23232001f49Smrg
23332001f49Smrg    windType = (rgb) ? GLUT_RGB : GLUT_INDEX;
23432001f49Smrg    windType |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE;
23532001f49Smrg    glutInitDisplayMode(windType);
23632001f49Smrg
23732001f49Smrg    if (glutCreateWindow("Bitmap Test") == GL_FALSE) {
23832001f49Smrg	exit(1);
23932001f49Smrg    }
24032001f49Smrg
24132001f49Smrg    InitMap();
24232001f49Smrg
24332001f49Smrg    Init();
24432001f49Smrg
24532001f49Smrg    glutReshapeFunc(Reshape);
24632001f49Smrg    glutKeyboardFunc(Key);
24732001f49Smrg    glutDisplayFunc(Draw);
24832001f49Smrg    glutMainLoop();
24932001f49Smrg	return 0;
25032001f49Smrg}
251