2 * Copyright (c) 2011 David Airlie
4 * Based on tri.c which is:
5 * Copyright (c) 1991, 1992, 1993 Silicon Graphics, Inc.
7 * Permission to use, copy, modify, distribute, and sell this software and
8 * its documentation for any purpose is hereby granted without fee, provided
9 * that (i) the above copyright notices and this permission notice appear in
10 * all copies of the software and related documentation, and (ii) the name of
11 * Silicon Graphics may not be used in any advertising or
12 * publicity relating to the software without the specific, prior written
13 * permission of Silicon Graphics.
15 * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF
17 * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
18 * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
20 * IN NO EVENT SHALL SILICON GRAPHICS BE LIABLE FOR
21 * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
22 * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
23 * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
24 * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
32 #include "glut_wrap.h"
34 GLenum doubleBuffer
= 1;
37 static void Init(void)
39 fprintf(stderr
, "GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER
));
40 fprintf(stderr
, "GL_VERSION = %s\n", (char *) glGetString(GL_VERSION
));
41 fprintf(stderr
, "GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR
));
44 #ifndef GL_ARB_vertex_type_2_10_10_10_rev
45 fprintf(stderr
,"built without ARB_vertex_type_2_10_10_10_rev\n");
49 if (!glutExtensionSupported("GL_ARB_vertex_type_2_10_10_10_rev")){
50 fprintf(stderr
,"requires ARB_vertex_type_2_10_10_10_rev\n");
54 glClearColor(0.3, 0.1, 0.3, 0.0);
57 static void Reshape(int width
, int height
)
60 glViewport(0, 0, (GLint
)width
, (GLint
)height
);
62 glMatrixMode(GL_PROJECTION
);
64 glOrtho(-100.0, 100.0, -100.0, 100.0, -50.0, 1000.0);
65 glMatrixMode(GL_MODELVIEW
);
68 static void Key(unsigned char key
, int x
, int y
)
72 glutDestroyWindow(win
);
80 #define i32to10(x) ((x) >= 0 ? (x & 0x1ff) : 1024-(abs((x))& 0x1ff))
81 #define i32to2(x) ((x) >= 0 ? (x & 0x1) : 1-abs((x)))
83 static unsigned iconv(int x
, int y
, int z
, int w
)
88 val
|= i32to10(y
) << 10;
89 val
|= i32to10(z
) << 20;
90 val
|= i32to2(w
) << 30;
93 #define conv(x,y,z,w) (((x) & 0x3ff) | ((y) & 0x3ff) << 10 | ((z) & 0x3ff)<< 20 | ((w) & 0x3) << 30)
95 static void Draw(void)
97 glClear(GL_COLOR_BUFFER_BIT
);
99 #ifdef GL_ARB_vertex_type_2_10_10_10_rev
100 glBegin(GL_TRIANGLES
);
101 glColorP3ui(GL_UNSIGNED_INT_2_10_10_10_REV
, conv(820, 0, 0, 0));
102 glVertexP3ui(GL_INT_2_10_10_10_REV
, iconv(-90, -90, -30, 0));
103 glColorP3ui(GL_UNSIGNED_INT_2_10_10_10_REV
, conv(0, 921, 0, 0));
104 glVertexP3ui(GL_INT_2_10_10_10_REV
, iconv(90, -90, -30, 0));
105 glColorP3ui(GL_UNSIGNED_INT_2_10_10_10_REV
, conv(0, 0, 716, 0));
106 glVertexP3ui(GL_INT_2_10_10_10_REV
, iconv(0, 90, -30, 0));
108 #endif /* GL_ARB_vertex_type_2_10_10_10_rev */
117 static GLenum
Args(int argc
, char **argv
)
121 for (i
= 1; i
< argc
; i
++) {
122 if (strcmp(argv
[i
], "-sb") == 0) {
123 doubleBuffer
= GL_FALSE
;
124 } else if (strcmp(argv
[i
], "-db") == 0) {
125 doubleBuffer
= GL_TRUE
;
127 fprintf(stderr
, "%s (Bad option).\n", argv
[i
]);
134 int main(int argc
, char **argv
)
138 glutInit(&argc
, argv
);
140 if (Args(argc
, argv
) == GL_FALSE
) {
144 glutInitWindowPosition(0, 0); glutInitWindowSize( 250, 250);
146 type
= GLUT_RGB
| GLUT_ALPHA
;
147 type
|= (doubleBuffer
) ? GLUT_DOUBLE
: GLUT_SINGLE
;
148 glutInitDisplayMode(type
);
150 win
= glutCreateWindow(*argv
);
158 glutReshapeFunc(Reshape
);
159 glutKeyboardFunc(Key
);
160 glutDisplayFunc(Draw
);