Jakob Bornecrantz | bd2f921 | 2009-02-21 11:58:48 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 1991, 1992, 1993 Silicon Graphics, Inc. |
| 3 | * |
| 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. |
| 11 | * |
| 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. |
| 16 | * |
| 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. |
| 23 | */ |
| 24 | |
| 25 | #include <stdio.h> |
| 26 | #include <string.h> |
| 27 | #include <stdlib.h> |
| 28 | #include <GL/glut.h> |
| 29 | |
| 30 | GLenum doubleBuffer = 1; |
| 31 | int win; |
Keith Whitwell | c691f96 | 2009-04-20 15:50:44 +0100 | [diff] [blame^] | 32 | static float tx = 0; |
| 33 | static float ty = 0; |
| 34 | static float tw = 250; |
| 35 | static float th = 250; |
Jakob Bornecrantz | bd2f921 | 2009-02-21 11:58:48 +0100 | [diff] [blame] | 36 | |
| 37 | static void Init(void) |
| 38 | { |
| 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)); |
Keith Whitwell | eb9801c | 2009-03-24 16:35:29 +0000 | [diff] [blame] | 42 | fflush(stderr); |
Jakob Bornecrantz | bd2f921 | 2009-02-21 11:58:48 +0100 | [diff] [blame] | 43 | |
| 44 | glClearColor(0.3, 0.1, 0.3, 0.0); |
| 45 | } |
| 46 | |
| 47 | static void Reshape(int width, int height) |
| 48 | { |
Keith Whitwell | c691f96 | 2009-04-20 15:50:44 +0100 | [diff] [blame^] | 49 | tw = width; |
| 50 | th = height; |
Jakob Bornecrantz | bd2f921 | 2009-02-21 11:58:48 +0100 | [diff] [blame] | 51 | } |
| 52 | |
Keith Whitwell | c691f96 | 2009-04-20 15:50:44 +0100 | [diff] [blame^] | 53 | |
Jakob Bornecrantz | bd2f921 | 2009-02-21 11:58:48 +0100 | [diff] [blame] | 54 | static void Key(unsigned char key, int x, int y) |
| 55 | { |
| 56 | switch (key) { |
| 57 | case 27: |
| 58 | exit(0); |
| 59 | default: |
| 60 | glutPostRedisplay(); |
| 61 | return; |
| 62 | } |
| 63 | } |
| 64 | |
Keith Whitwell | c691f96 | 2009-04-20 15:50:44 +0100 | [diff] [blame^] | 65 | |
Jakob Bornecrantz | bd2f921 | 2009-02-21 11:58:48 +0100 | [diff] [blame] | 66 | static void Draw(void) |
| 67 | { |
Keith Whitwell | c691f96 | 2009-04-20 15:50:44 +0100 | [diff] [blame^] | 68 | int i; |
| 69 | |
| 70 | fprintf(stderr, "%f %f\n", tx, ty); |
| 71 | fflush(stderr); |
| 72 | |
| 73 | glMatrixMode(GL_PROJECTION); |
| 74 | glLoadIdentity(); |
| 75 | glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 1000.0); |
| 76 | glMatrixMode(GL_MODELVIEW); |
| 77 | |
Jakob Bornecrantz | bd2f921 | 2009-02-21 11:58:48 +0100 | [diff] [blame] | 78 | glClear(GL_COLOR_BUFFER_BIT); |
| 79 | |
Keith Whitwell | c691f96 | 2009-04-20 15:50:44 +0100 | [diff] [blame^] | 80 | glViewport(0, 0, tw, th); |
| 81 | |
| 82 | glBegin(GL_LINES); |
| 83 | glColor3f(1,1,0); |
| 84 | glVertex3f(-1, 0, -30.0); |
| 85 | glVertex3f(1, 0, -30.0); |
| 86 | |
| 87 | glVertex3f(0, -1, -30.0); |
| 88 | glVertex3f(0, 1, -30.0); |
Jakob Bornecrantz | bd2f921 | 2009-02-21 11:58:48 +0100 | [diff] [blame] | 89 | glEnd(); |
| 90 | |
Keith Whitwell | c691f96 | 2009-04-20 15:50:44 +0100 | [diff] [blame^] | 91 | |
| 92 | /* |
| 93 | */ |
| 94 | glViewport(tx, ty, tw, th); |
| 95 | |
| 96 | |
| 97 | glBegin(GL_TRIANGLES); |
| 98 | glColor3f(1,0,0); |
| 99 | glVertex3f(-1, -1, -30.0); |
| 100 | glVertex3f(0, -1, -30.0); |
| 101 | glVertex3f(-.5, -.5, -30.0); |
| 102 | |
| 103 | glColor3f(1,1,1); |
| 104 | glVertex3f(0, -1, -30.0); |
| 105 | glVertex3f(1, -1, -30.0); |
| 106 | glVertex3f(.5, -.5, -30.0); |
| 107 | |
| 108 | glVertex3f(-.5, -.5, -30.0); |
| 109 | glVertex3f(.5, -.5, -30.0); |
| 110 | glVertex3f(0, 0, -30.0); |
| 111 | |
| 112 | |
| 113 | glColor3f(0,1,0); |
| 114 | glVertex3f(1, 1, -30.0); |
| 115 | glVertex3f(0, 1, -30.0); |
| 116 | glVertex3f(.5, .5, -30.0); |
| 117 | |
| 118 | glColor3f(1,1,1); |
| 119 | glVertex3f(0, 1, -30.0); |
| 120 | glVertex3f(-1, 1, -30.0); |
| 121 | glVertex3f(-.5, .5, -30.0); |
| 122 | |
| 123 | glVertex3f(.5, .5, -30.0); |
| 124 | glVertex3f(-.5, .5, -30.0); |
| 125 | glVertex3f( 0, 0, -30.0); |
| 126 | |
| 127 | glEnd(); |
| 128 | |
| 129 | |
| 130 | glViewport(0, 0, tw, th); |
| 131 | |
| 132 | glBegin(GL_LINES); |
| 133 | glColor3f(.5,.5,0); |
| 134 | for (i = -10; i < 10; i++) { |
| 135 | float f = i / 10.0; |
| 136 | |
| 137 | if (i == 0) |
| 138 | continue; |
| 139 | |
| 140 | glVertex3f(-1, f, -30.0); |
| 141 | glVertex3f(1, f, -30.0); |
| 142 | |
| 143 | glVertex3f(f, -1, -30.0); |
| 144 | glVertex3f(f, 1, -30.0); |
| 145 | } |
| 146 | glEnd(); |
| 147 | |
| 148 | |
| 149 | |
Jakob Bornecrantz | bd2f921 | 2009-02-21 11:58:48 +0100 | [diff] [blame] | 150 | glFlush(); |
| 151 | |
| 152 | if (doubleBuffer) { |
| 153 | glutSwapBuffers(); |
| 154 | } |
| 155 | } |
| 156 | |
| 157 | static GLenum Args(int argc, char **argv) |
| 158 | { |
| 159 | GLint i; |
| 160 | |
Keith Whitwell | c691f96 | 2009-04-20 15:50:44 +0100 | [diff] [blame^] | 161 | if (getenv("VPX")) |
| 162 | tx = atof(getenv("VPX")); |
| 163 | |
| 164 | if (getenv("VPY")) |
| 165 | ty = atof(getenv("VPY")); |
| 166 | |
| 167 | |
Jakob Bornecrantz | bd2f921 | 2009-02-21 11:58:48 +0100 | [diff] [blame] | 168 | for (i = 1; i < argc; i++) { |
| 169 | if (strcmp(argv[i], "-sb") == 0) { |
| 170 | doubleBuffer = GL_FALSE; |
| 171 | } else if (strcmp(argv[i], "-db") == 0) { |
| 172 | doubleBuffer = GL_TRUE; |
| 173 | } else { |
| 174 | fprintf(stderr, "%s (Bad option).\n", argv[i]); |
| 175 | return GL_FALSE; |
| 176 | } |
| 177 | } |
| 178 | return GL_TRUE; |
| 179 | } |
| 180 | |
Keith Whitwell | c691f96 | 2009-04-20 15:50:44 +0100 | [diff] [blame^] | 181 | |
| 182 | static void |
| 183 | special(int k, int x, int y) |
| 184 | { |
| 185 | switch (k) { |
| 186 | case GLUT_KEY_UP: |
| 187 | ty += 1.0; |
| 188 | break; |
| 189 | case GLUT_KEY_DOWN: |
| 190 | ty -= 1.0; |
| 191 | break; |
| 192 | case GLUT_KEY_LEFT: |
| 193 | tx -= 1.0; |
| 194 | break; |
| 195 | case GLUT_KEY_RIGHT: |
| 196 | tx += 1.0; |
| 197 | break; |
| 198 | default: |
| 199 | return; |
| 200 | } |
| 201 | glutPostRedisplay(); |
| 202 | } |
| 203 | |
| 204 | |
Jakob Bornecrantz | bd2f921 | 2009-02-21 11:58:48 +0100 | [diff] [blame] | 205 | int main(int argc, char **argv) |
| 206 | { |
| 207 | GLenum type; |
| 208 | |
| 209 | glutInit(&argc, argv); |
| 210 | |
| 211 | if (Args(argc, argv) == GL_FALSE) { |
| 212 | exit(1); |
| 213 | } |
| 214 | |
| 215 | glutInitWindowPosition(0, 0); glutInitWindowSize( 250, 250); |
| 216 | |
| 217 | type = GLUT_RGB | GLUT_ALPHA; |
| 218 | type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; |
| 219 | glutInitDisplayMode(type); |
| 220 | |
| 221 | win = glutCreateWindow(*argv); |
| 222 | if (!win) { |
| 223 | exit(1); |
| 224 | } |
| 225 | |
| 226 | Init(); |
| 227 | |
| 228 | glutReshapeFunc(Reshape); |
Keith Whitwell | c691f96 | 2009-04-20 15:50:44 +0100 | [diff] [blame^] | 229 | glutKeyboardFunc(Key); |
| 230 | glutSpecialFunc(special); |
Jakob Bornecrantz | bd2f921 | 2009-02-21 11:58:48 +0100 | [diff] [blame] | 231 | glutDisplayFunc(Draw); |
| 232 | glutMainLoop(); |
| 233 | return 0; |
| 234 | } |