WIP - port to Mali EGL
[mesa-demos/mali.git] / src / samples / line.c
blobb691b321e8b7f95baab05c919482badf9b81221b
1 /*
2 * Copyright (c) 1991, 1992, 1993 Silicon Graphics, Inc.
4 * Permission to use, copy, modify, distribute, and sell this software and
5 * its documentation for any purpose is hereby granted without fee, provided
6 * that (i) the above copyright notices and this permission notice appear in
7 * all copies of the software and related documentation, and (ii) the name of
8 * Silicon Graphics may not be used in any advertising or
9 * publicity relating to the software without the specific, prior written
10 * permission of Silicon Graphics.
12 * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF
13 * ANY KIND,
14 * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
15 * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
17 * IN NO EVENT SHALL SILICON GRAPHICS BE LIABLE FOR
18 * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
19 * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
20 * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
21 * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
22 * OF THIS SOFTWARE.
25 #include <stdio.h>
26 #include <string.h>
27 #include <stdlib.h>
28 #include "glut_wrap.h"
31 #define CI_OFFSET 16
34 GLenum rgb, doubleBuffer, windType;
36 GLenum mode1, mode2;
37 GLint size;
38 float pntA[3] = {
39 -160.0, 0.0, 0.0
41 float pntB[3] = {
42 -130.0, 0.0, 0.0
44 float pntC[3] = {
45 -40.0, -50.0, 0.0
47 float pntD[3] = {
48 30.0, 60.0, 0.0
52 #include "tkmap.c"
54 static void Init(void)
56 GLint i;
58 glClearColor(0.0, 0.0, 0.0, 0.0);
60 glLineStipple(1, 0xF0E0);
61 glBlendFunc(GL_SRC_ALPHA, GL_ONE);
63 if (!rgb) {
64 for (i = 0; i < 16; i++) {
65 glutSetColor(i+CI_OFFSET, i/15.0, i/15.0, 0.0);
69 mode1 = GL_FALSE;
70 mode2 = GL_FALSE;
71 size = 1;
74 static void Reshape(int width, int height)
77 glViewport(0, 0, (GLint)width, (GLint)height);
79 glMatrixMode(GL_PROJECTION);
80 glLoadIdentity();
81 gluOrtho2D(-175, 175, -175, 175);
82 glMatrixMode(GL_MODELVIEW);
85 static void Key(unsigned char key, int x, int y)
88 switch (key) {
89 case 27:
90 exit(1);
91 case '1':
92 mode1 = !mode1;
93 break;
94 case '2':
95 mode2 = !mode2;
96 break;
97 case 'W':
98 size++;
99 break;
100 case 'w':
101 size--;
102 if (size < 1) {
103 size = 1;
105 break;
106 default:
107 return;
110 glutPostRedisplay();
113 static void Draw(void)
115 GLint ci, i;
117 glClear(GL_COLOR_BUFFER_BIT);
119 glLineWidth(size);
121 if (mode1) {
122 glEnable(GL_LINE_STIPPLE);
123 } else {
124 glDisable(GL_LINE_STIPPLE);
127 if (mode2) {
128 ci = CI_OFFSET;
129 glEnable(GL_LINE_SMOOTH);
130 glEnable(GL_BLEND);
131 } else {
132 ci = COLOR_YELLOW;
133 glDisable(GL_LINE_SMOOTH);
134 glDisable(GL_BLEND);
137 glPushMatrix();
139 glShadeModel( GL_FLAT );
141 for (i = 0; i < 360; i += 5) {
142 glRotatef(5.0, 0,0,1);
144 (rgb) ? glColor3f(1.0, 1.0, 0.0) : glIndexi(ci);
145 glBegin(GL_LINE_STRIP);
146 glVertex3fv(pntA);
147 glVertex3fv(pntB);
148 glEnd();
150 glPointSize(1);
152 SetColor(COLOR_GREEN);
153 glBegin(GL_POINTS);
154 glVertex3fv(pntA);
155 glVertex3fv(pntB);
156 glEnd();
159 glPopMatrix();
161 glFlush();
163 if (doubleBuffer) {
164 glutSwapBuffers();
168 static GLenum Args(int argc, char **argv)
170 GLint i;
172 rgb = GL_TRUE;
173 doubleBuffer = GL_TRUE;
175 for (i = 1; i < argc; i++) {
176 if (strcmp(argv[i], "-ci") == 0) {
177 rgb = GL_FALSE;
178 } else if (strcmp(argv[i], "-rgb") == 0) {
179 rgb = GL_TRUE;
180 } else if (strcmp(argv[i], "-sb") == 0) {
181 doubleBuffer = GL_FALSE;
182 } else if (strcmp(argv[i], "-db") == 0) {
183 doubleBuffer = GL_TRUE;
184 } else {
185 printf("%s (Bad option).\n", argv[i]);
186 return GL_FALSE;
189 return GL_TRUE;
192 int main(int argc, char **argv)
194 glutInit(&argc, argv);
196 if (Args(argc, argv) == GL_FALSE) {
197 exit(1);
200 glutInitWindowPosition(0, 0); glutInitWindowSize( 300, 300);
202 windType = (rgb) ? GLUT_RGB : GLUT_INDEX;
203 windType |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE;
204 glutInitDisplayMode(windType);
206 if (glutCreateWindow("Line Test") == GL_FALSE) {
207 exit(1);
210 InitMap();
212 Init();
214 glutReshapeFunc(Reshape);
215 glutKeyboardFunc(Key);
216 glutDisplayFunc(Draw);
217 glutMainLoop();
218 return 0;