progs/redbook: add additional tests for GL 1.4
[mesa.git] / progs / redbook / mvarray.c
1 /*
2 * Copyright (c) 1993-2003, Silicon Graphics, Inc.
3 * All Rights Reserved
4 *
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose and without fee is hereby granted, provided that the above
7 * copyright notice appear in all copies and that both the copyright
8 * notice and this permission notice appear in supporting documentation,
9 * and that the name of Silicon Graphics, Inc. not be used in
10 * advertising or publicity pertaining to distribution of the software
11 * without specific, written prior permission.
12 *
13 * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS" AND
14 * WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
16 * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
17 * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
18 * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
19 * OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION, LOSS OF
20 * PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF THIRD
21 * PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN ADVISED OF
22 * THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON ANY THEORY OF
23 * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE POSSESSION, USE
24 * OR PERFORMANCE OF THIS SOFTWARE.
25 *
26 * US Government Users Restricted Rights
27 * Use, duplication, or disclosure by the Government is subject to
28 * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
29 * (c)(1)(ii) of the Rights in Technical Data and Computer Software
30 * clause at DFARS 252.227-7013 and/or in similar or successor clauses
31 * in the FAR or the DOD or NASA FAR Supplement. Unpublished - rights
32 * reserved under the copyright laws of the United States.
33 *
34 * Contractor/manufacturer is:
35 * Silicon Graphics, Inc.
36 * 1500 Crittenden Lane
37 * Mountain View, CA 94043
38 * United State of America
39 *
40 * OpenGL(R) is a registered trademark of Silicon Graphics, Inc.
41 */
42
43 /*
44 * mvarray.c
45 * This program demonstrates multiple vertex arrays,
46 * specifically the OpenGL routine glMultiDrawElements().
47 */
48
49 #define GL_GLEXT_PROTOTYPES
50
51 #include <GL/glut.h>
52 #include <stdlib.h>
53 #include <stdio.h>
54
55 #ifdef GL_VERSION_1_3
56
57 static void setupPointer(void)
58 {
59 static GLint vertices[] = {25, 25,
60 75, 75,
61 100, 125,
62 150, 75,
63 200, 175,
64 250, 150,
65 300, 125,
66 100, 200,
67 150, 250,
68 200, 225,
69 250, 300,
70 300, 250};
71
72 glEnableClientState (GL_VERTEX_ARRAY);
73 glVertexPointer (2, GL_INT, 0, vertices);
74 }
75
76 static void init(void)
77 {
78 glClearColor (0.0, 0.0, 0.0, 0.0);
79 glShadeModel (GL_SMOOTH);
80 setupPointer ();
81 }
82
83 static void display(void)
84 {
85 static GLubyte oneIndices[] = {0, 1, 2, 3, 4, 5, 6};
86 static GLubyte twoIndices[] = {1, 7, 8, 9, 10, 11};
87 static GLsizei count[] = {7, 6};
88 static GLvoid * indices[2] = {oneIndices, twoIndices};
89
90 glClear (GL_COLOR_BUFFER_BIT);
91 glColor3f (1.0, 1.0, 1.0);
92 glMultiDrawElementsEXT (GL_LINE_STRIP, count, GL_UNSIGNED_BYTE,
93 (const GLvoid **) indices, 2);
94 glFlush ();
95 }
96
97 static void reshape (int w, int h)
98 {
99 glViewport (0, 0, (GLsizei) w, (GLsizei) h);
100 glMatrixMode (GL_PROJECTION);
101 glLoadIdentity ();
102 gluOrtho2D (0.0, (GLdouble) w, 0.0, (GLdouble) h);
103 }
104
105 static void keyboard(unsigned char key, int x, int y)
106 {
107 switch (key) {
108 case 27:
109 exit(0);
110 break;
111 }
112 }
113
114 int main(int argc, char** argv)
115 {
116 glutInit(&argc, argv);
117 glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
118 glutInitWindowSize (350, 350);
119 glutInitWindowPosition (100, 100);
120 glutCreateWindow (argv[0]);
121 init ();
122 glutDisplayFunc(display);
123 glutReshapeFunc(reshape);
124 glutKeyboardFunc (keyboard);
125 glutMainLoop();
126 return 0;
127 }
128 #else
129 int main(int argc, char** argv)
130 {
131 fprintf (stderr, "This program demonstrates a feature which is not in OpenGL Version 1.0.\n");
132 fprintf (stderr, "If your implementation of OpenGL Version 1.0 has the right extensions,\n");
133 fprintf (stderr, "you may be able to modify this program to make it run.\n");
134 return 0;
135 }
136 #endif