Brian Paul | 642699a | 2003-06-16 14:32:44 +0000 | [diff] [blame] | 1 | /* |
Daniel Borca | 84396a7 | 2005-02-14 15:04:52 +0000 | [diff] [blame] | 2 | * DOS/DJGPP Mesa Utility Toolkit |
| 3 | * Version: 1.0 |
Brian Paul | 642699a | 2003-06-16 14:32:44 +0000 | [diff] [blame] | 4 | * |
Daniel Borca | 84396a7 | 2005-02-14 15:04:52 +0000 | [diff] [blame] | 5 | * Copyright (C) 2005 Daniel Borca All Rights Reserved. |
Brian Paul | 642699a | 2003-06-16 14:32:44 +0000 | [diff] [blame] | 6 | * |
Daniel Borca | 84396a7 | 2005-02-14 15:04:52 +0000 | [diff] [blame] | 7 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 8 | * copy of this software and associated documentation files (the "Software"), |
| 9 | * to deal in the Software without restriction, including without limitation |
| 10 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 11 | * and/or sell copies of the Software, and to permit persons to whom the |
| 12 | * Software is furnished to do so, subject to the following conditions: |
Brian Paul | 642699a | 2003-06-16 14:32:44 +0000 | [diff] [blame] | 13 | * |
Daniel Borca | 84396a7 | 2005-02-14 15:04:52 +0000 | [diff] [blame] | 14 | * The above copyright notice and this permission notice shall be included |
| 15 | * in all copies or substantial portions of the Software. |
Brian Paul | 642699a | 2003-06-16 14:32:44 +0000 | [diff] [blame] | 16 | * |
Daniel Borca | 84396a7 | 2005-02-14 15:04:52 +0000 | [diff] [blame] | 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 18 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 20 | * DANIEL BORCA BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER |
| 21 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
Brian Paul | 642699a | 2003-06-16 14:32:44 +0000 | [diff] [blame] | 23 | */ |
| 24 | |
| 25 | |
Daniel Borca | 6c520ef | 2003-10-13 11:05:36 +0000 | [diff] [blame] | 26 | #include <stdio.h> |
| 27 | |
Daniel Borca | 84396a7 | 2005-02-14 15:04:52 +0000 | [diff] [blame] | 28 | #include "internal.h" |
Brian Paul | 642699a | 2003-06-16 14:32:44 +0000 | [diff] [blame] | 29 | |
| 30 | |
Daniel Borca | 0c68589 | 2005-01-14 08:44:29 +0000 | [diff] [blame] | 31 | #define FREQUENCY 100 /* set this to zero to use the default timer */ |
Brian Paul | 642699a | 2003-06-16 14:32:44 +0000 | [diff] [blame] | 32 | |
| 33 | |
| 34 | static int timer_installed; |
Daniel Borca | 0c68589 | 2005-01-14 08:44:29 +0000 | [diff] [blame] | 35 | #if FREQUENCY |
Brian Paul | 642699a | 2003-06-16 14:32:44 +0000 | [diff] [blame] | 36 | static volatile int ticks; |
| 37 | |
| 38 | |
Daniel Borca | 0c68589 | 2005-01-14 08:44:29 +0000 | [diff] [blame] | 39 | static void |
| 40 | ticks_timer (void *p) |
Brian Paul | 642699a | 2003-06-16 14:32:44 +0000 | [diff] [blame] | 41 | { |
Daniel Borca | 0c68589 | 2005-01-14 08:44:29 +0000 | [diff] [blame] | 42 | (void)p; |
| 43 | ticks++; |
Brian Paul | 642699a | 2003-06-16 14:32:44 +0000 | [diff] [blame] | 44 | } ENDOFUNC(ticks_timer) |
Daniel Borca | 0c68589 | 2005-01-14 08:44:29 +0000 | [diff] [blame] | 45 | #else |
| 46 | #include <time.h> |
| 47 | |
| 48 | static struct timeval then; |
| 49 | #endif |
Brian Paul | 642699a | 2003-06-16 14:32:44 +0000 | [diff] [blame] | 50 | |
| 51 | |
Daniel Borca | 0c68589 | 2005-01-14 08:44:29 +0000 | [diff] [blame] | 52 | int APIENTRY |
| 53 | glutGet (GLenum type) |
Brian Paul | 642699a | 2003-06-16 14:32:44 +0000 | [diff] [blame] | 54 | { |
Daniel Borca | 0c68589 | 2005-01-14 08:44:29 +0000 | [diff] [blame] | 55 | switch (type) { |
| 56 | case GLUT_WINDOW_X: |
Daniel Borca | 84396a7 | 2005-02-14 15:04:52 +0000 | [diff] [blame] | 57 | return _glut_current->xpos; |
Daniel Borca | 0c68589 | 2005-01-14 08:44:29 +0000 | [diff] [blame] | 58 | case GLUT_WINDOW_Y: |
Daniel Borca | 84396a7 | 2005-02-14 15:04:52 +0000 | [diff] [blame] | 59 | return _glut_current->ypos; |
Daniel Borca | 0c68589 | 2005-01-14 08:44:29 +0000 | [diff] [blame] | 60 | case GLUT_WINDOW_WIDTH: |
Daniel Borca | 84396a7 | 2005-02-14 15:04:52 +0000 | [diff] [blame] | 61 | return _glut_current->width; |
Daniel Borca | 0c68589 | 2005-01-14 08:44:29 +0000 | [diff] [blame] | 62 | case GLUT_WINDOW_HEIGHT: |
Daniel Borca | 84396a7 | 2005-02-14 15:04:52 +0000 | [diff] [blame] | 63 | return _glut_current->height; |
Daniel Borca | 0c68589 | 2005-01-14 08:44:29 +0000 | [diff] [blame] | 64 | case GLUT_WINDOW_STENCIL_SIZE: |
Daniel Borca | 84396a7 | 2005-02-14 15:04:52 +0000 | [diff] [blame] | 65 | return _glut_visual.stencil; |
Daniel Borca | 0c68589 | 2005-01-14 08:44:29 +0000 | [diff] [blame] | 66 | case GLUT_WINDOW_DEPTH_SIZE: |
Daniel Borca | 84396a7 | 2005-02-14 15:04:52 +0000 | [diff] [blame] | 67 | return _glut_visual.depth; |
Daniel Borca | 0c68589 | 2005-01-14 08:44:29 +0000 | [diff] [blame] | 68 | case GLUT_WINDOW_RGBA: |
Daniel Borca | 84396a7 | 2005-02-14 15:04:52 +0000 | [diff] [blame] | 69 | return !(_glut_default.mode & GLUT_INDEX); |
Daniel Borca | 0c68589 | 2005-01-14 08:44:29 +0000 | [diff] [blame] | 70 | case GLUT_WINDOW_COLORMAP_SIZE: |
Daniel Borca | 84396a7 | 2005-02-14 15:04:52 +0000 | [diff] [blame] | 71 | return (_glut_default.mode & GLUT_INDEX) ? (256 - RESERVED_COLORS) : 0; |
Daniel Borca | 0c68589 | 2005-01-14 08:44:29 +0000 | [diff] [blame] | 72 | case GLUT_SCREEN_WIDTH: |
Daniel Borca | 84396a7 | 2005-02-14 15:04:52 +0000 | [diff] [blame] | 73 | return _glut_visual.geometry[0]; |
Daniel Borca | 0c68589 | 2005-01-14 08:44:29 +0000 | [diff] [blame] | 74 | case GLUT_SCREEN_HEIGHT: |
Daniel Borca | 84396a7 | 2005-02-14 15:04:52 +0000 | [diff] [blame] | 75 | return _glut_visual.geometry[1]; |
Daniel Borca | 0c68589 | 2005-01-14 08:44:29 +0000 | [diff] [blame] | 76 | case GLUT_INIT_WINDOW_X: |
Daniel Borca | 84396a7 | 2005-02-14 15:04:52 +0000 | [diff] [blame] | 77 | return _glut_default.x; |
Daniel Borca | 0c68589 | 2005-01-14 08:44:29 +0000 | [diff] [blame] | 78 | case GLUT_INIT_WINDOW_Y: |
Daniel Borca | 84396a7 | 2005-02-14 15:04:52 +0000 | [diff] [blame] | 79 | return _glut_default.y; |
Daniel Borca | 0c68589 | 2005-01-14 08:44:29 +0000 | [diff] [blame] | 80 | case GLUT_INIT_WINDOW_WIDTH: |
Daniel Borca | 84396a7 | 2005-02-14 15:04:52 +0000 | [diff] [blame] | 81 | return _glut_default.width; |
Daniel Borca | 0c68589 | 2005-01-14 08:44:29 +0000 | [diff] [blame] | 82 | case GLUT_INIT_WINDOW_HEIGHT: |
Daniel Borca | 84396a7 | 2005-02-14 15:04:52 +0000 | [diff] [blame] | 83 | return _glut_default.height; |
Daniel Borca | 0c68589 | 2005-01-14 08:44:29 +0000 | [diff] [blame] | 84 | case GLUT_INIT_DISPLAY_MODE: |
Daniel Borca | 84396a7 | 2005-02-14 15:04:52 +0000 | [diff] [blame] | 85 | return _glut_default.mode; |
Daniel Borca | 0c68589 | 2005-01-14 08:44:29 +0000 | [diff] [blame] | 86 | case GLUT_ELAPSED_TIME: |
| 87 | #if FREQUENCY |
| 88 | if (!timer_installed) { |
| 89 | timer_installed = GL_TRUE; |
| 90 | LOCKDATA(ticks); |
| 91 | LOCKFUNC(ticks_timer); |
| 92 | pc_install_int(ticks_timer, NULL, FREQUENCY); |
| 93 | } |
| 94 | return ticks * 1000 / FREQUENCY; |
| 95 | #else |
| 96 | if (!timer_installed) { |
| 97 | timer_installed = GL_TRUE; |
| 98 | gettimeofday(&then, NULL); |
| 99 | return 0; |
| 100 | } else { |
| 101 | struct timeval now; |
| 102 | gettimeofday(&now, NULL); |
| 103 | return (now.tv_usec - then.tv_usec) / 1000 + |
| 104 | (now.tv_sec - then.tv_sec) * 1000; |
| 105 | } |
| 106 | #endif |
| 107 | default: |
| 108 | return -1; |
| 109 | } |
Brian Paul | 642699a | 2003-06-16 14:32:44 +0000 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | |
Daniel Borca | 0c68589 | 2005-01-14 08:44:29 +0000 | [diff] [blame] | 113 | int APIENTRY |
| 114 | glutDeviceGet (GLenum type) |
Brian Paul | 642699a | 2003-06-16 14:32:44 +0000 | [diff] [blame] | 115 | { |
Daniel Borca | 0c68589 | 2005-01-14 08:44:29 +0000 | [diff] [blame] | 116 | switch (type) { |
| 117 | case GLUT_HAS_KEYBOARD: |
| 118 | return GL_TRUE; |
| 119 | case GLUT_HAS_MOUSE: |
Daniel Borca | 84396a7 | 2005-02-14 15:04:52 +0000 | [diff] [blame] | 120 | return (_glut_mouse != 0); |
Daniel Borca | 0c68589 | 2005-01-14 08:44:29 +0000 | [diff] [blame] | 121 | case GLUT_NUM_MOUSE_BUTTONS: |
Daniel Borca | 84396a7 | 2005-02-14 15:04:52 +0000 | [diff] [blame] | 122 | return _glut_mouse; |
Daniel Borca | 0c68589 | 2005-01-14 08:44:29 +0000 | [diff] [blame] | 123 | case GLUT_HAS_SPACEBALL: |
| 124 | case GLUT_HAS_DIAL_AND_BUTTON_BOX: |
| 125 | case GLUT_HAS_TABLET: |
| 126 | return GL_FALSE; |
| 127 | case GLUT_NUM_SPACEBALL_BUTTONS: |
| 128 | case GLUT_NUM_BUTTON_BOX_BUTTONS: |
| 129 | case GLUT_NUM_DIALS: |
| 130 | case GLUT_NUM_TABLET_BUTTONS: |
| 131 | return 0; |
| 132 | default: |
| 133 | return -1; |
| 134 | } |
Brian Paul | 642699a | 2003-06-16 14:32:44 +0000 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | |
Daniel Borca | 0c68589 | 2005-01-14 08:44:29 +0000 | [diff] [blame] | 138 | int APIENTRY |
| 139 | glutGetModifiers (void) |
Brian Paul | 642699a | 2003-06-16 14:32:44 +0000 | [diff] [blame] | 140 | { |
Daniel Borca | 0c68589 | 2005-01-14 08:44:29 +0000 | [diff] [blame] | 141 | int mod = 0; |
| 142 | int shifts = pc_keyshifts(); |
Brian Paul | 642699a | 2003-06-16 14:32:44 +0000 | [diff] [blame] | 143 | |
Daniel Borca | 0c68589 | 2005-01-14 08:44:29 +0000 | [diff] [blame] | 144 | if (shifts & (KB_SHIFT_FLAG | KB_CAPSLOCK_FLAG)) { |
| 145 | mod |= GLUT_ACTIVE_SHIFT; |
| 146 | } |
Brian Paul | 642699a | 2003-06-16 14:32:44 +0000 | [diff] [blame] | 147 | |
Daniel Borca | 0c68589 | 2005-01-14 08:44:29 +0000 | [diff] [blame] | 148 | if (shifts & KB_ALT_FLAG) { |
| 149 | mod |= GLUT_ACTIVE_ALT; |
| 150 | } |
Brian Paul | 642699a | 2003-06-16 14:32:44 +0000 | [diff] [blame] | 151 | |
Daniel Borca | 0c68589 | 2005-01-14 08:44:29 +0000 | [diff] [blame] | 152 | if (shifts & KB_CTRL_FLAG) { |
| 153 | mod |= GLUT_ACTIVE_CTRL; |
| 154 | } |
Brian Paul | 642699a | 2003-06-16 14:32:44 +0000 | [diff] [blame] | 155 | |
Daniel Borca | 0c68589 | 2005-01-14 08:44:29 +0000 | [diff] [blame] | 156 | return mod; |
Brian Paul | 642699a | 2003-06-16 14:32:44 +0000 | [diff] [blame] | 157 | } |
Daniel Borca | 6c520ef | 2003-10-13 11:05:36 +0000 | [diff] [blame] | 158 | |
| 159 | |
Daniel Borca | 84396a7 | 2005-02-14 15:04:52 +0000 | [diff] [blame] | 160 | void APIENTRY |
| 161 | glutReportErrors (void) |
| 162 | { |
| 163 | /* reports all the OpenGL errors that happened till now */ |
| 164 | } |
| 165 | |
| 166 | |
Daniel Borca | 6c520ef | 2003-10-13 11:05:36 +0000 | [diff] [blame] | 167 | /* GAME MODE |
| 168 | * Hack alert: incomplete... what is GameMode, anyway? |
| 169 | */ |
Daniel Borca | 84396a7 | 2005-02-14 15:04:52 +0000 | [diff] [blame] | 170 | static GLint game; |
Daniel Borca | 6c520ef | 2003-10-13 11:05:36 +0000 | [diff] [blame] | 171 | static GLboolean game_possible; |
| 172 | static GLboolean game_active; |
| 173 | static GLuint game_width; |
| 174 | static GLuint game_height; |
| 175 | static GLuint game_bpp; |
| 176 | static GLuint game_refresh; |
| 177 | |
| 178 | |
Daniel Borca | 0c68589 | 2005-01-14 08:44:29 +0000 | [diff] [blame] | 179 | void APIENTRY |
| 180 | glutGameModeString (const char *string) |
Daniel Borca | 6c520ef | 2003-10-13 11:05:36 +0000 | [diff] [blame] | 181 | { |
Daniel Borca | 0c68589 | 2005-01-14 08:44:29 +0000 | [diff] [blame] | 182 | if (sscanf(string, "%ux%u:%u@%u", &game_width, &game_height, &game_bpp, &game_refresh) == 4) { |
| 183 | game_possible = GL_TRUE; |
| 184 | } |
Daniel Borca | 6c520ef | 2003-10-13 11:05:36 +0000 | [diff] [blame] | 185 | } |
| 186 | |
| 187 | |
Daniel Borca | 0c68589 | 2005-01-14 08:44:29 +0000 | [diff] [blame] | 188 | int APIENTRY |
| 189 | glutGameModeGet (GLenum mode) |
Daniel Borca | 6c520ef | 2003-10-13 11:05:36 +0000 | [diff] [blame] | 190 | { |
Daniel Borca | 0c68589 | 2005-01-14 08:44:29 +0000 | [diff] [blame] | 191 | switch (mode) { |
| 192 | case GLUT_GAME_MODE_ACTIVE: |
| 193 | return game_active; |
| 194 | case GLUT_GAME_MODE_POSSIBLE: |
Daniel Borca | 84396a7 | 2005-02-14 15:04:52 +0000 | [diff] [blame] | 195 | return game_possible && !_glut_current; |
Daniel Borca | 0c68589 | 2005-01-14 08:44:29 +0000 | [diff] [blame] | 196 | case GLUT_GAME_MODE_WIDTH: |
| 197 | return game_active ? (int)game_width : -1; |
| 198 | case GLUT_GAME_MODE_HEIGHT: |
| 199 | return game_active ? (int)game_height : -1; |
| 200 | case GLUT_GAME_MODE_PIXEL_DEPTH: |
| 201 | return game_active ? (int)game_bpp : -1; |
| 202 | case GLUT_GAME_MODE_REFRESH_RATE: |
| 203 | return game_active ? (int)game_refresh : -1; |
| 204 | default: |
| 205 | return -1; |
| 206 | } |
Daniel Borca | 6c520ef | 2003-10-13 11:05:36 +0000 | [diff] [blame] | 207 | } |
| 208 | |
| 209 | |
Daniel Borca | 0c68589 | 2005-01-14 08:44:29 +0000 | [diff] [blame] | 210 | int APIENTRY |
| 211 | glutEnterGameMode (void) |
Daniel Borca | 6c520ef | 2003-10-13 11:05:36 +0000 | [diff] [blame] | 212 | { |
Daniel Borca | 0c68589 | 2005-01-14 08:44:29 +0000 | [diff] [blame] | 213 | if (glutGameModeGet(GLUT_GAME_MODE_POSSIBLE)) { |
Daniel Borca | 84396a7 | 2005-02-14 15:04:52 +0000 | [diff] [blame] | 214 | _glut_visual.bpp = game_bpp; |
| 215 | _glut_visual.refresh = game_refresh; |
Daniel Borca | 6c520ef | 2003-10-13 11:05:36 +0000 | [diff] [blame] | 216 | |
Daniel Borca | 0c68589 | 2005-01-14 08:44:29 +0000 | [diff] [blame] | 217 | glutInitWindowSize(game_width, game_height); |
Daniel Borca | 6c520ef | 2003-10-13 11:05:36 +0000 | [diff] [blame] | 218 | |
Daniel Borca | 84396a7 | 2005-02-14 15:04:52 +0000 | [diff] [blame] | 219 | if ((game = glutCreateWindow("<game>")) > 0) { |
Daniel Borca | 0c68589 | 2005-01-14 08:44:29 +0000 | [diff] [blame] | 220 | game_active = GL_TRUE; |
| 221 | } |
Daniel Borca | 6c520ef | 2003-10-13 11:05:36 +0000 | [diff] [blame] | 222 | |
Daniel Borca | 84396a7 | 2005-02-14 15:04:52 +0000 | [diff] [blame] | 223 | return game; |
Daniel Borca | 0c68589 | 2005-01-14 08:44:29 +0000 | [diff] [blame] | 224 | } else { |
| 225 | return 0; |
| 226 | } |
Daniel Borca | 6c520ef | 2003-10-13 11:05:36 +0000 | [diff] [blame] | 227 | } |
| 228 | |
| 229 | |
Daniel Borca | 0c68589 | 2005-01-14 08:44:29 +0000 | [diff] [blame] | 230 | void GLUTAPIENTRY |
| 231 | glutLeaveGameMode (void) |
Daniel Borca | 6c520ef | 2003-10-13 11:05:36 +0000 | [diff] [blame] | 232 | { |
Daniel Borca | 0c68589 | 2005-01-14 08:44:29 +0000 | [diff] [blame] | 233 | if (glutGameModeGet(GLUT_GAME_MODE_ACTIVE)) { |
| 234 | game_active = GL_FALSE; |
Daniel Borca | 6c520ef | 2003-10-13 11:05:36 +0000 | [diff] [blame] | 235 | |
Daniel Borca | 84396a7 | 2005-02-14 15:04:52 +0000 | [diff] [blame] | 236 | glutDestroyWindow(game); |
Daniel Borca | 0c68589 | 2005-01-14 08:44:29 +0000 | [diff] [blame] | 237 | } |
Daniel Borca | 6c520ef | 2003-10-13 11:05:36 +0000 | [diff] [blame] | 238 | } |