132001f49Smrg#include <stdio.h>
232001f49Smrg#include <string.h>
332001f49Smrg#include <stdlib.h>
432001f49Smrg#include <GL/glew.h>
532001f49Smrg#include "glut_wrap.h"
632001f49Smrg
732001f49Smrg
832001f49Smrg#define PIXEL_CENTER(x) ((long)(x) + 0.5)
932001f49Smrg
1032001f49Smrg#define GAP 10
1132001f49Smrg#define ROWS 3
1232001f49Smrg#define COLS 4
1332001f49Smrg
1432001f49Smrg#define OPENGL_WIDTH 48
1532001f49Smrg#define OPENGL_HEIGHT 13
1632001f49Smrg
1732001f49Smrg
1832001f49SmrgGLenum provoking = GL_LAST_VERTEX_CONVENTION_EXT;
1932001f49SmrgGLenum rgb, doubleBuffer, windType;
2032001f49SmrgGLint windW, windH;
2132001f49Smrg
2232001f49SmrgGLenum mode1, mode2;
2332001f49SmrgGLint boxW, boxH;
2432001f49SmrgGLubyte OpenGL_bits[] = {
2532001f49Smrg   0x00, 0x03, 0x00, 0x00, 0x00, 0x00,
2632001f49Smrg   0x7f, 0xfb, 0xff, 0xff, 0xff, 0x01,
2732001f49Smrg   0x7f, 0xfb, 0xff, 0xff, 0xff, 0x01,
2832001f49Smrg   0x00, 0x03, 0x00, 0x00, 0x00, 0x00,
2932001f49Smrg   0x3e, 0x8f, 0xb7, 0xf9, 0xfc, 0x01,
3032001f49Smrg   0x63, 0xdb, 0xb0, 0x8d, 0x0d, 0x00,
3132001f49Smrg   0x63, 0xdb, 0xb7, 0x8d, 0x0d, 0x00,
3232001f49Smrg   0x63, 0xdb, 0xb6, 0x8d, 0x0d, 0x00,
3332001f49Smrg   0x63, 0x8f, 0xf3, 0xcc, 0x0d, 0x00,
3432001f49Smrg   0x63, 0x00, 0x00, 0x0c, 0x4c, 0x0a,
3532001f49Smrg   0x63, 0x00, 0x00, 0x0c, 0x4c, 0x0e,
3632001f49Smrg   0x63, 0x00, 0x00, 0x8c, 0xed, 0x0e,
3732001f49Smrg   0x3e, 0x00, 0x00, 0xf8, 0x0c, 0x00,
3832001f49Smrg};
3932001f49Smrg
4032001f49Smrg
4132001f49Smrg#include "tkmap.c"
4232001f49Smrg
4332001f49Smrgstatic void Init(void)
4432001f49Smrg{
4532001f49Smrg
4632001f49Smrg    mode1 = GL_TRUE;
4732001f49Smrg    mode2 = GL_TRUE;
4832001f49Smrg}
4932001f49Smrg
5032001f49Smrgstatic void Reshape(int width, int height)
5132001f49Smrg{
5232001f49Smrg
5332001f49Smrg    windW = (GLint)width;
5432001f49Smrg    windH = (GLint)height;
5532001f49Smrg}
5632001f49Smrg
5732001f49Smrgstatic void RotateColorMask(void)
5832001f49Smrg{
5932001f49Smrg    static GLint rotation = 0;
6032001f49Smrg
6132001f49Smrg    rotation = (rotation + 1) & 0x3;
6232001f49Smrg    switch (rotation) {
6332001f49Smrg      case 0:
6432001f49Smrg	glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
6532001f49Smrg	glIndexMask( 0xff );
6632001f49Smrg	break;
6732001f49Smrg      case 1:
6832001f49Smrg	glColorMask(GL_FALSE, GL_TRUE, GL_TRUE, GL_TRUE);
6932001f49Smrg	glIndexMask(0xFE);
7032001f49Smrg	break;
7132001f49Smrg      case 2:
7232001f49Smrg	glColorMask(GL_TRUE, GL_FALSE, GL_TRUE, GL_TRUE);
7332001f49Smrg	glIndexMask(0xFD);
7432001f49Smrg	break;
7532001f49Smrg      case 3:
7632001f49Smrg	glColorMask(GL_TRUE, GL_TRUE, GL_FALSE, GL_TRUE);
7732001f49Smrg	glIndexMask(0xFB);
7832001f49Smrg	break;
7932001f49Smrg    }
8032001f49Smrg}
8132001f49Smrg
8232001f49Smrgstatic void Key(unsigned char key, int x, int y)
8332001f49Smrg{
8432001f49Smrg
8532001f49Smrg    switch (key) {
8632001f49Smrg      case 27:
8732001f49Smrg	exit(1);
8832001f49Smrg      case '1':
8932001f49Smrg	mode1 = !mode1;
9032001f49Smrg	break;
9132001f49Smrg      case '2':
9232001f49Smrg	mode2 = !mode2;
9332001f49Smrg	break;
9432001f49Smrg      case '3':
9532001f49Smrg	RotateColorMask();
9632001f49Smrg	break;
9732001f49Smrg      case 'p':
9832001f49Smrg         if (provoking == GL_FIRST_VERTEX_CONVENTION_EXT) {
9932001f49Smrg            printf("provoke last\n");
10032001f49Smrg            provoking = GL_LAST_VERTEX_CONVENTION_EXT;
10132001f49Smrg         }
10232001f49Smrg         else {
10332001f49Smrg            printf("provoke first\n");
10432001f49Smrg            provoking = GL_FIRST_VERTEX_CONVENTION_EXT;
10532001f49Smrg         }
10632001f49Smrg         glProvokingVertexEXT(provoking);
10732001f49Smrg         break;
10832001f49Smrg      default:
10932001f49Smrg	return;
11032001f49Smrg    }
11132001f49Smrg
11232001f49Smrg    glutPostRedisplay();
11332001f49Smrg}
11432001f49Smrg
11532001f49Smrgstatic void Viewport(GLint row, GLint column)
11632001f49Smrg{
11732001f49Smrg    GLint x, y;
11832001f49Smrg
11932001f49Smrg    boxW = (windW - (COLS + 1) * GAP) / COLS;
12032001f49Smrg    boxH = (windH - (ROWS + 1) * GAP) / ROWS;
12132001f49Smrg
12232001f49Smrg    x = GAP + column * (boxW + GAP);
12332001f49Smrg    y = GAP + row * (boxH + GAP);
12432001f49Smrg
12532001f49Smrg    glViewport(x, y, boxW, boxH);
12632001f49Smrg
12732001f49Smrg    glMatrixMode(GL_PROJECTION);
12832001f49Smrg    glLoadIdentity();
12932001f49Smrg    glOrtho(-boxW/2, boxW/2, -boxH/2, boxH/2, 0.0, 1.0);
13032001f49Smrg    glMatrixMode(GL_MODELVIEW);
13132001f49Smrg
13232001f49Smrg    glEnable(GL_SCISSOR_TEST);
13332001f49Smrg    glScissor(x, y, boxW, boxH);
13432001f49Smrg}
13532001f49Smrg
13632001f49Smrgstatic void Point(void)
13732001f49Smrg{
13832001f49Smrg    GLint i;
13932001f49Smrg
14032001f49Smrg    glBegin(GL_POINTS);
14132001f49Smrg	SetColor(COLOR_WHITE);
14232001f49Smrg	glVertex2i(0, 0);
14332001f49Smrg	for (i = 1; i < 8; i++) {
14432001f49Smrg	    GLint j = i * 2;
14532001f49Smrg	    SetColor(COLOR_BLACK+i);
14632001f49Smrg	    glVertex2i(-j, -j);
14732001f49Smrg	    glVertex2i(-j, 0);
14832001f49Smrg	    glVertex2i(-j, j);
14932001f49Smrg	    glVertex2i(0, j);
15032001f49Smrg	    glVertex2i(j, j);
15132001f49Smrg	    glVertex2i(j, 0);
15232001f49Smrg	    glVertex2i(j, -j);
15332001f49Smrg	    glVertex2i(0, -j);
15432001f49Smrg	}
15532001f49Smrg    glEnd();
15632001f49Smrg}
15732001f49Smrg
15832001f49Smrgstatic void Lines(void)
15932001f49Smrg{
16032001f49Smrg    GLint i;
16132001f49Smrg
16232001f49Smrg    glPushMatrix();
16332001f49Smrg
16432001f49Smrg    glTranslatef(-12, 0, 0);
16532001f49Smrg    for (i = 1; i < 8; i++) {
16632001f49Smrg	glBegin(GL_LINES);
16732001f49Smrg	    SetColor(COLOR_BLACK+i);
16832001f49Smrg	    glVertex2i(-boxW/4, -boxH/4);
16932001f49Smrg	    SetColor(COLOR_BLACK+i+1);
17032001f49Smrg	    glVertex2i(boxW/4, boxH/4);
17132001f49Smrg	glEnd();
17232001f49Smrg	glTranslatef(4, 0, 0);
17332001f49Smrg    }
17432001f49Smrg
17532001f49Smrg    glPopMatrix();
17632001f49Smrg
17732001f49Smrg    glBegin(GL_LINES);
17832001f49Smrg	glVertex2i(0, 0);
17932001f49Smrg    glEnd();
18032001f49Smrg}
18132001f49Smrg
18232001f49Smrgstatic void LineStrip(void)
18332001f49Smrg{
18432001f49Smrg
18532001f49Smrg    glBegin(GL_LINE_STRIP);
18632001f49Smrg	SetColor(COLOR_RED);
18732001f49Smrg	glVertex2f(PIXEL_CENTER(-boxW/4), PIXEL_CENTER(-boxH/4));
18832001f49Smrg	SetColor(COLOR_GREEN);
18932001f49Smrg	glVertex2f(PIXEL_CENTER(-boxW/4), PIXEL_CENTER(boxH/4));
19032001f49Smrg	SetColor(COLOR_BLUE);
19132001f49Smrg	glVertex2f(PIXEL_CENTER(boxW/4), PIXEL_CENTER(boxH/4));
19232001f49Smrg	SetColor(COLOR_WHITE);
19332001f49Smrg	glVertex2f(PIXEL_CENTER(boxW/4), PIXEL_CENTER(-boxH/4));
19432001f49Smrg    glEnd();
19532001f49Smrg
19632001f49Smrg    glBegin(GL_LINE_STRIP);
19732001f49Smrg	glVertex2i(0, 0);
19832001f49Smrg    glEnd();
19932001f49Smrg}
20032001f49Smrg
20132001f49Smrgstatic void LineLoop(void)
20232001f49Smrg{
20332001f49Smrg
20432001f49Smrg    glBegin(GL_LINE_LOOP);
20532001f49Smrg	SetColor(COLOR_RED);
20632001f49Smrg	glVertex2f(PIXEL_CENTER(-boxW/4), PIXEL_CENTER(-boxH/4));
20732001f49Smrg	SetColor(COLOR_GREEN);
20832001f49Smrg	glVertex2f(PIXEL_CENTER(-boxW/4), PIXEL_CENTER(boxH/4));
20932001f49Smrg	SetColor(COLOR_BLUE);
21032001f49Smrg	glVertex2f(PIXEL_CENTER(boxW/4), PIXEL_CENTER(boxH/4));
21132001f49Smrg	SetColor(COLOR_WHITE);
21232001f49Smrg	glVertex2f(PIXEL_CENTER(boxW/4), PIXEL_CENTER(-boxH/4));
21332001f49Smrg    glEnd();
21432001f49Smrg
21532001f49Smrg    glEnable(GL_LOGIC_OP);
21632001f49Smrg    glLogicOp(GL_XOR);
21732001f49Smrg
21832001f49Smrg    glEnable(GL_BLEND);
21932001f49Smrg    glBlendFunc(GL_ONE, GL_ONE);
22032001f49Smrg
22132001f49Smrg    SetColor(COLOR_MAGENTA);
22232001f49Smrg    glBegin(GL_LINE_LOOP);
22332001f49Smrg	glVertex2f(PIXEL_CENTER(-boxW/8), PIXEL_CENTER(-boxH/8));
22432001f49Smrg	glVertex2f(PIXEL_CENTER(-boxW/8), PIXEL_CENTER(boxH/8));
22532001f49Smrg    glEnd();
22632001f49Smrg    glBegin(GL_LINE_LOOP);
22732001f49Smrg	glVertex2f(PIXEL_CENTER(-boxW/8), PIXEL_CENTER(boxH/8+5));
22832001f49Smrg	glVertex2f(PIXEL_CENTER(boxW/8), PIXEL_CENTER(boxH/8+5));
22932001f49Smrg    glEnd();
23032001f49Smrg    glDisable(GL_LOGIC_OP);
23132001f49Smrg    glDisable(GL_BLEND);
23232001f49Smrg
23332001f49Smrg    SetColor(COLOR_GREEN);
23432001f49Smrg    glBegin(GL_POINTS);
23532001f49Smrg	glVertex2i(0, 0);
23632001f49Smrg    glEnd();
23732001f49Smrg
23832001f49Smrg    glBegin(GL_LINE_LOOP);
23932001f49Smrg	glVertex2i(0, 0);
24032001f49Smrg    glEnd();
24132001f49Smrg}
24232001f49Smrg
24332001f49Smrgstatic void Bitmap(void)
24432001f49Smrg{
24532001f49Smrg
24632001f49Smrg    glBegin(GL_LINES);
24732001f49Smrg	SetColor(COLOR_GREEN);
24832001f49Smrg	glVertex2i(-boxW/2, 0);
24932001f49Smrg	glVertex2i(boxW/2, 0);
25032001f49Smrg	glVertex2i(0, -boxH/2);
25132001f49Smrg	glVertex2i(0, boxH/2);
25232001f49Smrg	SetColor(COLOR_RED);
25332001f49Smrg	glVertex2i(0, -3);
25432001f49Smrg	glVertex2i(0, -3+OPENGL_HEIGHT);
25532001f49Smrg	SetColor(COLOR_BLUE);
25632001f49Smrg	glVertex2i(0, -3);
25732001f49Smrg	glVertex2i(OPENGL_WIDTH, -3);
25832001f49Smrg    glEnd();
25932001f49Smrg
26032001f49Smrg    SetColor(COLOR_GREEN);
26132001f49Smrg
26232001f49Smrg    glPixelStorei(GL_UNPACK_LSB_FIRST, GL_TRUE);
26332001f49Smrg    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
26432001f49Smrg
26532001f49Smrg    glRasterPos2i(0, 0);
26632001f49Smrg    glBitmap(OPENGL_WIDTH, OPENGL_HEIGHT, 0, 3, 0.0, 0.0, OpenGL_bits);
26732001f49Smrg}
26832001f49Smrg
26932001f49Smrgstatic void Triangles(void)
27032001f49Smrg{
27132001f49Smrg
27232001f49Smrg    glBegin(GL_TRIANGLES);
27332001f49Smrg	SetColor(COLOR_GREEN);
27432001f49Smrg	glVertex2i(-boxW/4, -boxH/4);
27532001f49Smrg	SetColor(COLOR_RED);
27632001f49Smrg	glVertex2i(-boxW/8, -boxH/16);
27732001f49Smrg	SetColor(COLOR_BLUE);
27832001f49Smrg	glVertex2i(boxW/8, -boxH/16);
27932001f49Smrg
28032001f49Smrg	SetColor(COLOR_GREEN);
28132001f49Smrg	glVertex2i(-boxW/4, boxH/4);
28232001f49Smrg	SetColor(COLOR_RED);
28332001f49Smrg	glVertex2i(-boxW/8, boxH/16);
28432001f49Smrg	SetColor(COLOR_BLUE);
28532001f49Smrg	glVertex2i(boxW/8, boxH/16);
28632001f49Smrg    glEnd();
28732001f49Smrg
28832001f49Smrg    glBegin(GL_TRIANGLES);
28932001f49Smrg	glVertex2i(0, 0);
29032001f49Smrg	glVertex2i(-100, 100);
29132001f49Smrg    glEnd();
29232001f49Smrg}
29332001f49Smrg
29432001f49Smrgstatic void TriangleStrip(void)
29532001f49Smrg{
29632001f49Smrg
29732001f49Smrg    glBegin(GL_TRIANGLE_STRIP);
29832001f49Smrg	SetColor(COLOR_GREEN);
29932001f49Smrg	glVertex2i(-boxW/4, -boxH/4);
30032001f49Smrg	SetColor(COLOR_RED);
30132001f49Smrg	glVertex2i(-boxW/4, boxH/4);
30232001f49Smrg	SetColor(COLOR_BLUE);
30332001f49Smrg	glVertex2i(0, -boxH/4);
30432001f49Smrg	SetColor(COLOR_WHITE);
30532001f49Smrg	glVertex2i(0, boxH/4);
30632001f49Smrg	SetColor(COLOR_CYAN);
30732001f49Smrg	glVertex2i(boxW/4, -boxH/4);
30832001f49Smrg	SetColor(COLOR_YELLOW);
30932001f49Smrg	glVertex2i(boxW/4, boxH/4);
31032001f49Smrg    glEnd();
31132001f49Smrg
31232001f49Smrg    glBegin(GL_TRIANGLE_STRIP);
31332001f49Smrg	glVertex2i(0, 0);
31432001f49Smrg	glVertex2i(-100, 100);
31532001f49Smrg    glEnd();
31632001f49Smrg}
31732001f49Smrg
31832001f49Smrgstatic void TriangleFan(void)
31932001f49Smrg{
32032001f49Smrg    GLint vx[8][2];
32132001f49Smrg    GLint x0, y0, x1, y1, x2, y2, x3, y3;
32232001f49Smrg    GLint i;
32332001f49Smrg
32432001f49Smrg    y0 = -boxH/4;
32532001f49Smrg    y1 = y0 + boxH/2/3;
32632001f49Smrg    y2 = y1 + boxH/2/3;
32732001f49Smrg    y3 = boxH/4;
32832001f49Smrg    x0 = -boxW/4;
32932001f49Smrg    x1 = x0 + boxW/2/3;
33032001f49Smrg    x2 = x1 + boxW/2/3;
33132001f49Smrg    x3 = boxW/4;
33232001f49Smrg
33332001f49Smrg    vx[0][0] = x0; vx[0][1] = y1;
33432001f49Smrg    vx[1][0] = x0; vx[1][1] = y2;
33532001f49Smrg    vx[2][0] = x1; vx[2][1] = y3;
33632001f49Smrg    vx[3][0] = x2; vx[3][1] = y3;
33732001f49Smrg    vx[4][0] = x3; vx[4][1] = y2;
33832001f49Smrg    vx[5][0] = x3; vx[5][1] = y1;
33932001f49Smrg    vx[6][0] = x2; vx[6][1] = y0;
34032001f49Smrg    vx[7][0] = x1; vx[7][1] = y0;
34132001f49Smrg
34232001f49Smrg    glBegin(GL_TRIANGLE_FAN);
34332001f49Smrg	SetColor(COLOR_WHITE);
34432001f49Smrg	glVertex2i(0, 0);
34532001f49Smrg	for (i = 0; i < 8; i++) {
34632001f49Smrg	    SetColor(COLOR_WHITE-i);
34732001f49Smrg	    glVertex2iv(vx[i]);
34832001f49Smrg	}
34932001f49Smrg    glEnd();
35032001f49Smrg
35132001f49Smrg    glBegin(GL_TRIANGLE_FAN);
35232001f49Smrg	glVertex2i(0, 0);
35332001f49Smrg	glVertex2i(-100, 100);
35432001f49Smrg    glEnd();
35532001f49Smrg}
35632001f49Smrg
35732001f49Smrgstatic void Rect(void)
35832001f49Smrg{
35932001f49Smrg
36032001f49Smrg    SetColor(COLOR_GREEN);
36132001f49Smrg    glRecti(-boxW/4, -boxH/4, boxW/4, boxH/4);
36232001f49Smrg}
36332001f49Smrg
36432001f49Smrgstatic void PolygonFunc(void)
36532001f49Smrg{
36632001f49Smrg    GLint vx[8][2];
36732001f49Smrg    GLint x0, y0, x1, y1, x2, y2, x3, y3;
36832001f49Smrg    GLint i;
36932001f49Smrg
37032001f49Smrg    y0 = -boxH/4;
37132001f49Smrg    y1 = y0 + boxH/2/3;
37232001f49Smrg    y2 = y1 + boxH/2/3;
37332001f49Smrg    y3 = boxH/4;
37432001f49Smrg    x0 = -boxW/4;
37532001f49Smrg    x1 = x0 + boxW/2/3;
37632001f49Smrg    x2 = x1 + boxW/2/3;
37732001f49Smrg    x3 = boxW/4;
37832001f49Smrg
37932001f49Smrg    vx[0][0] = x0; vx[0][1] = y1;
38032001f49Smrg    vx[1][0] = x0; vx[1][1] = y2;
38132001f49Smrg    vx[2][0] = x1; vx[2][1] = y3;
38232001f49Smrg    vx[3][0] = x2; vx[3][1] = y3;
38332001f49Smrg    vx[4][0] = x3; vx[4][1] = y2;
38432001f49Smrg    vx[5][0] = x3; vx[5][1] = y1;
38532001f49Smrg    vx[6][0] = x2; vx[6][1] = y0;
38632001f49Smrg    vx[7][0] = x1; vx[7][1] = y0;
38732001f49Smrg
38832001f49Smrg    glBegin(GL_POLYGON);
38932001f49Smrg	for (i = 0; i < 8; i++) {
39032001f49Smrg	    SetColor(COLOR_WHITE-i);
39132001f49Smrg	    glVertex2iv(vx[i]);
39232001f49Smrg	}
39332001f49Smrg    glEnd();
39432001f49Smrg
39532001f49Smrg    glBegin(GL_POLYGON);
39632001f49Smrg	glVertex2i(0, 0);
39732001f49Smrg	glVertex2i(100, 100);
39832001f49Smrg    glEnd();
39932001f49Smrg}
40032001f49Smrg
40132001f49Smrgstatic void Quads(void)
40232001f49Smrg{
40332001f49Smrg
40432001f49Smrg    glBegin(GL_QUADS);
40532001f49Smrg	SetColor(COLOR_GREEN);
40632001f49Smrg	glVertex2i(-boxW/4, -boxH/4);
40732001f49Smrg	SetColor(COLOR_RED);
40832001f49Smrg	glVertex2i(-boxW/8, -boxH/16);
40932001f49Smrg	SetColor(COLOR_BLUE);
41032001f49Smrg	glVertex2i(boxW/8, -boxH/16);
41132001f49Smrg	SetColor(COLOR_WHITE);
41232001f49Smrg	glVertex2i(boxW/4, -boxH/4);
41332001f49Smrg
41432001f49Smrg	SetColor(COLOR_GREEN);
41532001f49Smrg	glVertex2i(-boxW/4, boxH/4);
41632001f49Smrg	SetColor(COLOR_RED);
41732001f49Smrg	glVertex2i(-boxW/8, boxH/16);
41832001f49Smrg	SetColor(COLOR_BLUE);
41932001f49Smrg	glVertex2i(boxW/8, boxH/16);
42032001f49Smrg	SetColor(COLOR_WHITE);
42132001f49Smrg	glVertex2i(boxW/4, boxH/4);
42232001f49Smrg    glEnd();
42332001f49Smrg
42432001f49Smrg    glBegin(GL_QUADS);
42532001f49Smrg	glVertex2i(0, 0);
42632001f49Smrg	glVertex2i(100, 100);
42732001f49Smrg	glVertex2i(-100, 100);
42832001f49Smrg    glEnd();
42932001f49Smrg}
43032001f49Smrg
43132001f49Smrgstatic void QuadStrip(void)
43232001f49Smrg{
43332001f49Smrg
43432001f49Smrg    glBegin(GL_QUAD_STRIP);
43532001f49Smrg	SetColor(COLOR_GREEN);
43632001f49Smrg	glVertex2i(-boxW/4, -boxH/4);
43732001f49Smrg	SetColor(COLOR_RED);
43832001f49Smrg	glVertex2i(-boxW/4, boxH/4);
43932001f49Smrg	SetColor(COLOR_BLUE);
44032001f49Smrg	glVertex2i(0, -boxH/4);
44132001f49Smrg	SetColor(COLOR_WHITE);
44232001f49Smrg	glVertex2i(0, boxH/4);
44332001f49Smrg	SetColor(COLOR_CYAN);
44432001f49Smrg	glVertex2i(boxW/4, -boxH/4);
44532001f49Smrg	SetColor(COLOR_YELLOW);
44632001f49Smrg	glVertex2i(boxW/4, boxH/4);
44732001f49Smrg    glEnd();
44832001f49Smrg
44932001f49Smrg    glBegin(GL_QUAD_STRIP);
45032001f49Smrg	glVertex2i(0, 0);
45132001f49Smrg	glVertex2i(100, 100);
45232001f49Smrg	glVertex2i(-100, 100);
45332001f49Smrg    glEnd();
45432001f49Smrg}
45532001f49Smrg
45632001f49Smrgstatic void Draw(void)
45732001f49Smrg{
45832001f49Smrg
45932001f49Smrg    glViewport(0, 0, windW, windH);
46032001f49Smrg    glDisable(GL_SCISSOR_TEST);
46132001f49Smrg
46232001f49Smrg    glPushAttrib(GL_COLOR_BUFFER_BIT);
46332001f49Smrg
46432001f49Smrg    glColorMask(1, 1, 1, 1);
46532001f49Smrg    glIndexMask(~0);
46632001f49Smrg
46732001f49Smrg    glClearColor(0.0, 0.0, 0.0, 0.0);
46832001f49Smrg    glClear(GL_COLOR_BUFFER_BIT);
46932001f49Smrg
47032001f49Smrg    glPopAttrib();
47132001f49Smrg
47232001f49Smrg    if (mode1) {
47332001f49Smrg	glShadeModel(GL_SMOOTH);
47432001f49Smrg    } else {
47532001f49Smrg	glShadeModel(GL_FLAT);
47632001f49Smrg    }
47732001f49Smrg
47832001f49Smrg    if (mode2) {
47932001f49Smrg	glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
48032001f49Smrg    } else {
48132001f49Smrg	glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
48232001f49Smrg    }
48332001f49Smrg
48432001f49Smrg    Viewport(0, 0); Point();
48532001f49Smrg    Viewport(0, 1); Lines();
48632001f49Smrg    Viewport(0, 2); LineStrip();
48732001f49Smrg    Viewport(0, 3); LineLoop();
48832001f49Smrg
48932001f49Smrg    Viewport(1, 0); Bitmap();
49032001f49Smrg    Viewport(1, 1); TriangleFan();
49132001f49Smrg    Viewport(1, 2); Triangles();
49232001f49Smrg    Viewport(1, 3); TriangleStrip();
49332001f49Smrg
49432001f49Smrg    Viewport(2, 0); Rect();
49532001f49Smrg    Viewport(2, 1); PolygonFunc();
49632001f49Smrg    Viewport(2, 2); Quads();
49732001f49Smrg    Viewport(2, 3); QuadStrip();
49832001f49Smrg
49932001f49Smrg    glFlush();
50032001f49Smrg
50132001f49Smrg    if (doubleBuffer) {
50232001f49Smrg	glutSwapBuffers();
50332001f49Smrg    }
50432001f49Smrg}
50532001f49Smrg
50632001f49Smrgstatic GLenum Args(int argc, char **argv)
50732001f49Smrg{
50832001f49Smrg    GLint i;
50932001f49Smrg
51032001f49Smrg    rgb = GL_TRUE;
51132001f49Smrg    doubleBuffer = GL_FALSE;
51232001f49Smrg
51332001f49Smrg    for (i = 1; i < argc; i++) {
51432001f49Smrg	if (strcmp(argv[i], "-ci") == 0) {
51532001f49Smrg	    rgb = GL_FALSE;
51632001f49Smrg	} else if (strcmp(argv[i], "-rgb") == 0) {
51732001f49Smrg	    rgb = GL_TRUE;
51832001f49Smrg	} else if (strcmp(argv[i], "-sb") == 0) {
51932001f49Smrg	    doubleBuffer = GL_FALSE;
52032001f49Smrg	} else if (strcmp(argv[i], "-db") == 0) {
52132001f49Smrg	    doubleBuffer = GL_TRUE;
52232001f49Smrg	} else {
52332001f49Smrg	    printf("%s (Bad option).\n", argv[i]);
52432001f49Smrg	    return GL_FALSE;
52532001f49Smrg	}
52632001f49Smrg    }
52732001f49Smrg    return GL_TRUE;
52832001f49Smrg}
52932001f49Smrg
53032001f49Smrgint main(int argc, char **argv)
53132001f49Smrg{
53232001f49Smrg    glutInit(&argc, argv);
53332001f49Smrg
53432001f49Smrg    if (Args(argc, argv) == GL_FALSE) {
53532001f49Smrg	exit(1);
53632001f49Smrg    }
53732001f49Smrg
53832001f49Smrg    windW = 600;
53932001f49Smrg    windH = 300;
54032001f49Smrg    glutInitWindowPosition(0, 0); glutInitWindowSize( windW, windH);
54132001f49Smrg
54232001f49Smrg    windType = (rgb) ? GLUT_RGB : GLUT_INDEX;
54332001f49Smrg    windType |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE;
54432001f49Smrg    glutInitDisplayMode(windType);
54532001f49Smrg
54632001f49Smrg    if (glutCreateWindow("Primitive Test") == GL_FALSE) {
54732001f49Smrg	exit(1);
54832001f49Smrg    }
54932001f49Smrg
55032001f49Smrg    glewInit();
55132001f49Smrg    InitMap();
55232001f49Smrg
55332001f49Smrg    Init();
55432001f49Smrg
55532001f49Smrg    glutReshapeFunc(Reshape);
55632001f49Smrg    glutKeyboardFunc(Key);
55732001f49Smrg    glutDisplayFunc(Draw);
55832001f49Smrg    glutMainLoop();
55932001f49Smrg	return 0;
56032001f49Smrg}
561