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 CI_OFFSET 16
3232001f49Smrg
3332001f49Smrg
3432001f49SmrgGLenum rgb, doubleBuffer, windType;
3532001f49Smrg
3632001f49SmrgGLenum mode1, mode2;
3732001f49SmrgGLint size;
3832001f49Smrgfloat pntA[3] = {
3932001f49Smrg    -160.0, 0.0, 0.0
4032001f49Smrg};
4132001f49Smrgfloat pntB[3] = {
4232001f49Smrg    -130.0, 0.0, 0.0
4332001f49Smrg};
4432001f49Smrgfloat pntC[3] = {
4532001f49Smrg    -40.0, -50.0, 0.0
4632001f49Smrg};
4732001f49Smrgfloat pntD[3] = {
4832001f49Smrg    30.0, 60.0, 0.0
4932001f49Smrg};
5032001f49Smrg
5132001f49Smrg
5232001f49Smrg#include "tkmap.c"
5332001f49Smrg
5432001f49Smrgstatic void Init(void)
5532001f49Smrg{
5632001f49Smrg    GLint i;
5732001f49Smrg
5832001f49Smrg    glClearColor(0.0, 0.0, 0.0, 0.0);
5932001f49Smrg
6032001f49Smrg    glLineStipple(1, 0xF0E0);
6132001f49Smrg    glBlendFunc(GL_SRC_ALPHA, GL_ONE);
6232001f49Smrg
6332001f49Smrg    if (!rgb) {
6432001f49Smrg	for (i = 0; i < 16; i++) {
6532001f49Smrg	    glutSetColor(i+CI_OFFSET, i/15.0, i/15.0, 0.0);
6632001f49Smrg	}
6732001f49Smrg    }
6832001f49Smrg
6932001f49Smrg    mode1 = GL_FALSE;
7032001f49Smrg    mode2 = GL_FALSE;
7132001f49Smrg    size = 1;
7232001f49Smrg}
7332001f49Smrg
7432001f49Smrgstatic void Reshape(int width, int height)
7532001f49Smrg{
7632001f49Smrg
7732001f49Smrg    glViewport(0, 0, (GLint)width, (GLint)height);
7832001f49Smrg
7932001f49Smrg    glMatrixMode(GL_PROJECTION);
8032001f49Smrg    glLoadIdentity();
8132001f49Smrg    gluOrtho2D(-175, 175, -175, 175);
8232001f49Smrg    glMatrixMode(GL_MODELVIEW);
8332001f49Smrg}
8432001f49Smrg
8532001f49Smrgstatic void Key(unsigned char key, int x, int y)
8632001f49Smrg{
8732001f49Smrg
8832001f49Smrg    switch (key) {
8932001f49Smrg      case 27:
9032001f49Smrg	exit(1);
9132001f49Smrg      case '1':
9232001f49Smrg	mode1 = !mode1;
9332001f49Smrg	break;
9432001f49Smrg      case '2':
9532001f49Smrg	mode2 = !mode2;
9632001f49Smrg	break;
9732001f49Smrg      case 'W':
9832001f49Smrg	size++;
9932001f49Smrg	break;
10032001f49Smrg      case 'w':
10132001f49Smrg	size--;
10232001f49Smrg	if (size < 1) {
10332001f49Smrg	    size = 1;
10432001f49Smrg	}
10532001f49Smrg	break;
10632001f49Smrg      default:
10732001f49Smrg	return;
10832001f49Smrg    }
10932001f49Smrg
11032001f49Smrg    glutPostRedisplay();
11132001f49Smrg}
11232001f49Smrg
11332001f49Smrgstatic void Draw(void)
11432001f49Smrg{
11532001f49Smrg    GLint ci, i;
11632001f49Smrg
11732001f49Smrg    glClear(GL_COLOR_BUFFER_BIT);
11832001f49Smrg
11932001f49Smrg    glLineWidth(size);
12032001f49Smrg
12132001f49Smrg    if (mode1) {
12232001f49Smrg	glEnable(GL_LINE_STIPPLE);
12332001f49Smrg    } else {
12432001f49Smrg	glDisable(GL_LINE_STIPPLE);
12532001f49Smrg    }
12632001f49Smrg
12732001f49Smrg    if (mode2) {
12832001f49Smrg	ci = CI_OFFSET;
12932001f49Smrg	glEnable(GL_LINE_SMOOTH);
13032001f49Smrg	glEnable(GL_BLEND);
13132001f49Smrg    } else {
13232001f49Smrg	ci = COLOR_YELLOW;
13332001f49Smrg	glDisable(GL_LINE_SMOOTH);
13432001f49Smrg	glDisable(GL_BLEND);
13532001f49Smrg    }
13632001f49Smrg
13732001f49Smrg    glPushMatrix();
13832001f49Smrg
13932001f49Smrg    glShadeModel( GL_FLAT );
14032001f49Smrg
14132001f49Smrg    for (i = 0; i < 360; i += 5) {
14232001f49Smrg	glRotatef(5.0, 0,0,1);
14332001f49Smrg
14432001f49Smrg	(rgb) ? glColor3f(1.0, 1.0, 0.0) : glIndexi(ci);
14532001f49Smrg	glBegin(GL_LINE_STRIP);
14632001f49Smrg	    glVertex3fv(pntA);
14732001f49Smrg	    glVertex3fv(pntB);
14832001f49Smrg	glEnd();
14932001f49Smrg
15032001f49Smrg	glPointSize(1);
15132001f49Smrg
15232001f49Smrg	SetColor(COLOR_GREEN);
15332001f49Smrg	glBegin(GL_POINTS);
15432001f49Smrg	    glVertex3fv(pntA);
15532001f49Smrg	    glVertex3fv(pntB);
15632001f49Smrg	glEnd();
15732001f49Smrg    }
15832001f49Smrg
15932001f49Smrg    glPopMatrix();
16032001f49Smrg
16132001f49Smrg    glFlush();
16232001f49Smrg
16332001f49Smrg    if (doubleBuffer) {
16432001f49Smrg	glutSwapBuffers();
16532001f49Smrg    }
16632001f49Smrg}
16732001f49Smrg
16832001f49Smrgstatic GLenum Args(int argc, char **argv)
16932001f49Smrg{
17032001f49Smrg    GLint i;
17132001f49Smrg
17232001f49Smrg    rgb = GL_TRUE;
17332001f49Smrg    doubleBuffer = GL_TRUE;
17432001f49Smrg
17532001f49Smrg    for (i = 1; i < argc; i++) {
17632001f49Smrg	if (strcmp(argv[i], "-ci") == 0) {
17732001f49Smrg	    rgb = GL_FALSE;
17832001f49Smrg	} else if (strcmp(argv[i], "-rgb") == 0) {
17932001f49Smrg	    rgb = GL_TRUE;
18032001f49Smrg	} else if (strcmp(argv[i], "-sb") == 0) {
18132001f49Smrg	    doubleBuffer = GL_FALSE;
18232001f49Smrg	} else if (strcmp(argv[i], "-db") == 0) {
18332001f49Smrg	    doubleBuffer = GL_TRUE;
18432001f49Smrg	} else {
18532001f49Smrg	    printf("%s (Bad option).\n", argv[i]);
18632001f49Smrg	    return GL_FALSE;
18732001f49Smrg	}
18832001f49Smrg    }
18932001f49Smrg    return GL_TRUE;
19032001f49Smrg}
19132001f49Smrg
19232001f49Smrgint main(int argc, char **argv)
19332001f49Smrg{
19432001f49Smrg    glutInit(&argc, argv);
19532001f49Smrg
19632001f49Smrg    if (Args(argc, argv) == GL_FALSE) {
19732001f49Smrg	exit(1);
19832001f49Smrg    }
19932001f49Smrg
20032001f49Smrg    glutInitWindowPosition(0, 0); glutInitWindowSize( 300, 300);
20132001f49Smrg
20232001f49Smrg    windType = (rgb) ? GLUT_RGB : GLUT_INDEX;
20332001f49Smrg    windType |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE;
20432001f49Smrg    glutInitDisplayMode(windType);
20532001f49Smrg
20632001f49Smrg    if (glutCreateWindow("Line Test") == GL_FALSE) {
20732001f49Smrg	exit(1);
20832001f49Smrg    }
20932001f49Smrg
21032001f49Smrg    InitMap();
21132001f49Smrg
21232001f49Smrg    Init();
21332001f49Smrg
21432001f49Smrg    glutReshapeFunc(Reshape);
21532001f49Smrg    glutKeyboardFunc(Key);
21632001f49Smrg    glutDisplayFunc(Draw);
21732001f49Smrg    glutMainLoop();
21832001f49Smrg	return 0;
21932001f49Smrg}
220