blob: b0d5d8ae92345976ef094ffe21c17bc5cc38527c [file] [log] [blame]
Brian Paul642699a2003-06-16 14:32:44 +00001/*
Daniel Borca84396a72005-02-14 15:04:52 +00002 * DOS/DJGPP Mesa Utility Toolkit
3 * Version: 1.0
Brian Paul642699a2003-06-16 14:32:44 +00004 *
Daniel Borca84396a72005-02-14 15:04:52 +00005 * Copyright (C) 2005 Daniel Borca All Rights Reserved.
Brian Paul642699a2003-06-16 14:32:44 +00006 *
Daniel Borca84396a72005-02-14 15:04:52 +00007 * 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 Paul642699a2003-06-16 14:32:44 +000013 *
Daniel Borca84396a72005-02-14 15:04:52 +000014 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
Brian Paul642699a2003-06-16 14:32:44 +000016 *
Daniel Borca84396a72005-02-14 15:04:52 +000017 * 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 Paul642699a2003-06-16 14:32:44 +000023 */
24
25
Daniel Borca6c520ef2003-10-13 11:05:36 +000026#include <stdio.h>
27
Daniel Borca84396a72005-02-14 15:04:52 +000028#include "internal.h"
Brian Paul642699a2003-06-16 14:32:44 +000029
30
Daniel Borca0c685892005-01-14 08:44:29 +000031#define FREQUENCY 100 /* set this to zero to use the default timer */
Brian Paul642699a2003-06-16 14:32:44 +000032
33
34static int timer_installed;
Daniel Borca0c685892005-01-14 08:44:29 +000035#if FREQUENCY
Brian Paul642699a2003-06-16 14:32:44 +000036static volatile int ticks;
37
38
Daniel Borca0c685892005-01-14 08:44:29 +000039static void
40ticks_timer (void *p)
Brian Paul642699a2003-06-16 14:32:44 +000041{
Daniel Borca0c685892005-01-14 08:44:29 +000042 (void)p;
43 ticks++;
Brian Paul642699a2003-06-16 14:32:44 +000044} ENDOFUNC(ticks_timer)
Daniel Borca0c685892005-01-14 08:44:29 +000045#else
46#include <time.h>
47
48static struct timeval then;
49#endif
Brian Paul642699a2003-06-16 14:32:44 +000050
51
Daniel Borca0c685892005-01-14 08:44:29 +000052int APIENTRY
53glutGet (GLenum type)
Brian Paul642699a2003-06-16 14:32:44 +000054{
Daniel Borca0c685892005-01-14 08:44:29 +000055 switch (type) {
56 case GLUT_WINDOW_X:
Daniel Borca84396a72005-02-14 15:04:52 +000057 return _glut_current->xpos;
Daniel Borca0c685892005-01-14 08:44:29 +000058 case GLUT_WINDOW_Y:
Daniel Borca84396a72005-02-14 15:04:52 +000059 return _glut_current->ypos;
Daniel Borca0c685892005-01-14 08:44:29 +000060 case GLUT_WINDOW_WIDTH:
Daniel Borca84396a72005-02-14 15:04:52 +000061 return _glut_current->width;
Daniel Borca0c685892005-01-14 08:44:29 +000062 case GLUT_WINDOW_HEIGHT:
Daniel Borca84396a72005-02-14 15:04:52 +000063 return _glut_current->height;
Daniel Borca0c685892005-01-14 08:44:29 +000064 case GLUT_WINDOW_STENCIL_SIZE:
Daniel Borca84396a72005-02-14 15:04:52 +000065 return _glut_visual.stencil;
Daniel Borca0c685892005-01-14 08:44:29 +000066 case GLUT_WINDOW_DEPTH_SIZE:
Daniel Borca84396a72005-02-14 15:04:52 +000067 return _glut_visual.depth;
Daniel Borca0c685892005-01-14 08:44:29 +000068 case GLUT_WINDOW_RGBA:
Daniel Borca84396a72005-02-14 15:04:52 +000069 return !(_glut_default.mode & GLUT_INDEX);
Daniel Borca0c685892005-01-14 08:44:29 +000070 case GLUT_WINDOW_COLORMAP_SIZE:
Daniel Borca84396a72005-02-14 15:04:52 +000071 return (_glut_default.mode & GLUT_INDEX) ? (256 - RESERVED_COLORS) : 0;
Daniel Borca0c685892005-01-14 08:44:29 +000072 case GLUT_SCREEN_WIDTH:
Daniel Borca84396a72005-02-14 15:04:52 +000073 return _glut_visual.geometry[0];
Daniel Borca0c685892005-01-14 08:44:29 +000074 case GLUT_SCREEN_HEIGHT:
Daniel Borca84396a72005-02-14 15:04:52 +000075 return _glut_visual.geometry[1];
Daniel Borca0c685892005-01-14 08:44:29 +000076 case GLUT_INIT_WINDOW_X:
Daniel Borca84396a72005-02-14 15:04:52 +000077 return _glut_default.x;
Daniel Borca0c685892005-01-14 08:44:29 +000078 case GLUT_INIT_WINDOW_Y:
Daniel Borca84396a72005-02-14 15:04:52 +000079 return _glut_default.y;
Daniel Borca0c685892005-01-14 08:44:29 +000080 case GLUT_INIT_WINDOW_WIDTH:
Daniel Borca84396a72005-02-14 15:04:52 +000081 return _glut_default.width;
Daniel Borca0c685892005-01-14 08:44:29 +000082 case GLUT_INIT_WINDOW_HEIGHT:
Daniel Borca84396a72005-02-14 15:04:52 +000083 return _glut_default.height;
Daniel Borca0c685892005-01-14 08:44:29 +000084 case GLUT_INIT_DISPLAY_MODE:
Daniel Borca84396a72005-02-14 15:04:52 +000085 return _glut_default.mode;
Daniel Borca0c685892005-01-14 08:44:29 +000086 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 Paul642699a2003-06-16 14:32:44 +0000110}
111
112
Daniel Borca0c685892005-01-14 08:44:29 +0000113int APIENTRY
114glutDeviceGet (GLenum type)
Brian Paul642699a2003-06-16 14:32:44 +0000115{
Daniel Borca0c685892005-01-14 08:44:29 +0000116 switch (type) {
117 case GLUT_HAS_KEYBOARD:
118 return GL_TRUE;
119 case GLUT_HAS_MOUSE:
Daniel Borca84396a72005-02-14 15:04:52 +0000120 return (_glut_mouse != 0);
Daniel Borca0c685892005-01-14 08:44:29 +0000121 case GLUT_NUM_MOUSE_BUTTONS:
Daniel Borca84396a72005-02-14 15:04:52 +0000122 return _glut_mouse;
Daniel Borca0c685892005-01-14 08:44:29 +0000123 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 Paul642699a2003-06-16 14:32:44 +0000135}
136
137
Daniel Borca0c685892005-01-14 08:44:29 +0000138int APIENTRY
139glutGetModifiers (void)
Brian Paul642699a2003-06-16 14:32:44 +0000140{
Daniel Borca0c685892005-01-14 08:44:29 +0000141 int mod = 0;
142 int shifts = pc_keyshifts();
Brian Paul642699a2003-06-16 14:32:44 +0000143
Daniel Borca0c685892005-01-14 08:44:29 +0000144 if (shifts & (KB_SHIFT_FLAG | KB_CAPSLOCK_FLAG)) {
145 mod |= GLUT_ACTIVE_SHIFT;
146 }
Brian Paul642699a2003-06-16 14:32:44 +0000147
Daniel Borca0c685892005-01-14 08:44:29 +0000148 if (shifts & KB_ALT_FLAG) {
149 mod |= GLUT_ACTIVE_ALT;
150 }
Brian Paul642699a2003-06-16 14:32:44 +0000151
Daniel Borca0c685892005-01-14 08:44:29 +0000152 if (shifts & KB_CTRL_FLAG) {
153 mod |= GLUT_ACTIVE_CTRL;
154 }
Brian Paul642699a2003-06-16 14:32:44 +0000155
Daniel Borca0c685892005-01-14 08:44:29 +0000156 return mod;
Brian Paul642699a2003-06-16 14:32:44 +0000157}
Daniel Borca6c520ef2003-10-13 11:05:36 +0000158
159
Daniel Borca84396a72005-02-14 15:04:52 +0000160void APIENTRY
161glutReportErrors (void)
162{
163 /* reports all the OpenGL errors that happened till now */
164}
165
166
Daniel Borca6c520ef2003-10-13 11:05:36 +0000167/* GAME MODE
168 * Hack alert: incomplete... what is GameMode, anyway?
169 */
Daniel Borca84396a72005-02-14 15:04:52 +0000170static GLint game;
Daniel Borca6c520ef2003-10-13 11:05:36 +0000171static GLboolean game_possible;
172static GLboolean game_active;
173static GLuint game_width;
174static GLuint game_height;
175static GLuint game_bpp;
176static GLuint game_refresh;
177
178
Daniel Borca0c685892005-01-14 08:44:29 +0000179void APIENTRY
180glutGameModeString (const char *string)
Daniel Borca6c520ef2003-10-13 11:05:36 +0000181{
Daniel Borca0c685892005-01-14 08:44:29 +0000182 if (sscanf(string, "%ux%u:%u@%u", &game_width, &game_height, &game_bpp, &game_refresh) == 4) {
183 game_possible = GL_TRUE;
184 }
Daniel Borca6c520ef2003-10-13 11:05:36 +0000185}
186
187
Daniel Borca0c685892005-01-14 08:44:29 +0000188int APIENTRY
189glutGameModeGet (GLenum mode)
Daniel Borca6c520ef2003-10-13 11:05:36 +0000190{
Daniel Borca0c685892005-01-14 08:44:29 +0000191 switch (mode) {
192 case GLUT_GAME_MODE_ACTIVE:
193 return game_active;
194 case GLUT_GAME_MODE_POSSIBLE:
Daniel Borca84396a72005-02-14 15:04:52 +0000195 return game_possible && !_glut_current;
Daniel Borca0c685892005-01-14 08:44:29 +0000196 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 Borca6c520ef2003-10-13 11:05:36 +0000207}
208
209
Daniel Borca0c685892005-01-14 08:44:29 +0000210int APIENTRY
211glutEnterGameMode (void)
Daniel Borca6c520ef2003-10-13 11:05:36 +0000212{
Daniel Borca0c685892005-01-14 08:44:29 +0000213 if (glutGameModeGet(GLUT_GAME_MODE_POSSIBLE)) {
Daniel Borca84396a72005-02-14 15:04:52 +0000214 _glut_visual.bpp = game_bpp;
215 _glut_visual.refresh = game_refresh;
Daniel Borca6c520ef2003-10-13 11:05:36 +0000216
Daniel Borca0c685892005-01-14 08:44:29 +0000217 glutInitWindowSize(game_width, game_height);
Daniel Borca6c520ef2003-10-13 11:05:36 +0000218
Daniel Borca84396a72005-02-14 15:04:52 +0000219 if ((game = glutCreateWindow("<game>")) > 0) {
Daniel Borca0c685892005-01-14 08:44:29 +0000220 game_active = GL_TRUE;
221 }
Daniel Borca6c520ef2003-10-13 11:05:36 +0000222
Daniel Borca84396a72005-02-14 15:04:52 +0000223 return game;
Daniel Borca0c685892005-01-14 08:44:29 +0000224 } else {
225 return 0;
226 }
Daniel Borca6c520ef2003-10-13 11:05:36 +0000227}
228
229
Daniel Borca0c685892005-01-14 08:44:29 +0000230void GLUTAPIENTRY
231glutLeaveGameMode (void)
Daniel Borca6c520ef2003-10-13 11:05:36 +0000232{
Daniel Borca0c685892005-01-14 08:44:29 +0000233 if (glutGameModeGet(GLUT_GAME_MODE_ACTIVE)) {
234 game_active = GL_FALSE;
Daniel Borca6c520ef2003-10-13 11:05:36 +0000235
Daniel Borca84396a72005-02-14 15:04:52 +0000236 glutDestroyWindow(game);
Daniel Borca0c685892005-01-14 08:44:29 +0000237 }
Daniel Borca6c520ef2003-10-13 11:05:36 +0000238}