forgotten commit. disabled until egl is adapted.
[AROS-Contrib.git] / gfx / libs / glut / state.c
blobff9e8c8920d56f96c19730a02dfc129facc28644
1 /*
2 * DOS/DJGPP Mesa Utility Toolkit
3 * Version: 1.0
5 * Copyright (C) 2005 Daniel Borca All Rights Reserved.
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:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
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.
25 #include <stdio.h>
27 #include "internal.h"
29 #include <aros/debug.h>
31 extern struct AROSMesaGLUT_TaskNode *_glut_findtask(struct Task *);
33 static int timer_installed;
34 #include <time.h>
36 static struct timeval time_start;
38 int APIENTRY
39 glutGet (GLenum type)
42 D(bug("[AMGLUT] In glutGet(type:%d) ", type));
44 struct AROSMesaGLUT_TaskNode *__glutTask = _glut_findtask(FindTask(NULL));
46 switch (type) {
47 case GLUT_WINDOW_X:
49 D(bug("GLUT_WINDOW_X = %d\n", __glutTask->AMGLUTTN_WindowCurrent->amglutwin_xpos));
51 return __glutTask->AMGLUTTN_WindowCurrent->amglutwin_xpos;
53 case GLUT_WINDOW_Y:
55 D(bug("GLUT_WINDOW_Y = %d\n", __glutTask->AMGLUTTN_WindowCurrent->amglutwin_ypos));
57 return __glutTask->AMGLUTTN_WindowCurrent->amglutwin_ypos;
59 case GLUT_WINDOW_WIDTH:
61 D(bug("GLUT_WINDOW_WIDTH = %d\n", __glutTask->AMGLUTTN_WindowCurrent->amglutwin_width));
63 return __glutTask->AMGLUTTN_WindowCurrent->amglutwin_width;
65 case GLUT_WINDOW_HEIGHT:
67 D(bug("GLUT_WINDOW_HEIGHT = %d\n", __glutTask->AMGLUTTN_WindowCurrent->amglutwin_height));
69 return __glutTask->AMGLUTTN_WindowCurrent->amglutwin_height;
71 case GLUT_WINDOW_STENCIL_SIZE:
73 D(bug("GLUT_STENCIL_SIZE = %d\n", _glut_visual.stencil));
75 return _glut_visual.stencil;
77 case GLUT_WINDOW_DEPTH_SIZE:
79 D(bug("GLUT_DEPTH_SIZE = %d\n", _glut_visual.depth));
81 return _glut_visual.depth;
83 case GLUT_WINDOW_RGBA:
85 D(bug("GLUT_WINDOW_RGBA = %d", !(_glut_default.mode & GLUT_INDEX)));
87 return !(_glut_default.mode & GLUT_INDEX);
89 case GLUT_WINDOW_COLORMAP_SIZE:
91 D(bug("GLUT_WINDOW_COLORMAP_SIZE\n"));
93 return (_glut_default.mode & GLUT_INDEX) ? (256 - RESERVED_COLORS) : 0;
95 case GLUT_SCREEN_WIDTH:
97 D(bug("GLUT_SCREEN_WIDTH = %d\n", _glut_visual.geometry[0]));
99 return _glut_visual.geometry[0];
101 case GLUT_SCREEN_HEIGHT:
103 D(bug("GLUT_SCREEN_HEIGHT = %d\n", _glut_visual.geometry[1]));
105 return _glut_visual.geometry[1];
107 case GLUT_INIT_WINDOW_X:
108 return _glut_default.x;
109 case GLUT_INIT_WINDOW_Y:
110 return _glut_default.y;
111 case GLUT_INIT_WINDOW_WIDTH:
112 return _glut_default.width;
113 case GLUT_INIT_WINDOW_HEIGHT:
114 return _glut_default.height;
115 case GLUT_INIT_DISPLAY_MODE:
116 return _glut_default.mode;
117 case GLUT_ELAPSED_TIME:
119 D(bug("GLUT_ELAPSED_TIME\n"));
121 if (!timer_installed) {
122 timer_installed = GL_TRUE;
123 /* gettimeofday(&then, NULL);*/
124 CurrentTime(&time_start.tv_sec, &time_start.tv_usec);
125 return 0;
126 } else {
127 struct timeval time_current;
128 /* gettimeofday(&now, NULL);
129 return (now.tv_usec - then.tv_usec) / 1000 +
130 (now.tv_sec - then.tv_sec) * 1000;*/
131 CurrentTime(&time_current.tv_sec, &time_current.tv_usec);
132 return (time_current.tv_usec - time_start.tv_usec) / 1000 +
133 (time_current.tv_sec - time_start.tv_sec) * 1000;
136 default:
138 D(bug("UNKNOWN VALUE!\n"));
140 return -1;
146 int APIENTRY
147 glutDeviceGet (GLenum type)
149 D(bug("[AMGLUT] In glutDeviceGet()\n"));
151 switch (type) {
152 case GLUT_HAS_KEYBOARD:
153 return GL_TRUE;
154 case GLUT_HAS_MOUSE:
155 return GL_TRUE;
156 case GLUT_NUM_MOUSE_BUTTONS:
157 return 3;
158 case GLUT_HAS_SPACEBALL:
159 case GLUT_HAS_DIAL_AND_BUTTON_BOX:
160 case GLUT_HAS_TABLET:
161 return GL_FALSE;
162 case GLUT_NUM_SPACEBALL_BUTTONS:
163 case GLUT_NUM_BUTTON_BOX_BUTTONS:
164 case GLUT_NUM_DIALS:
165 case GLUT_NUM_TABLET_BUTTONS:
166 return 0;
167 default:
168 return -1;
173 int APIENTRY
174 glutGetModifiers (void)
176 int mod = 0;
178 D(bug("[AMGLUT] In glutGetModifiers()\n"));
180 // int shifts = pc_keyshifts();
182 /* if (shifts & (KB_SHIFT_FLAG | KB_CAPSLOCK_FLAG)) {
183 mod |= GLUT_ACTIVE_SHIFT;
186 if (shifts & KB_ALT_FLAG) {
187 mod |= GLUT_ACTIVE_ALT;
190 if (shifts & KB_CTRL_FLAG) {
191 mod |= GLUT_ACTIVE_CTRL;
194 return mod;
198 void APIENTRY
199 glutReportErrors (void)
201 D(bug("[AMGLUT] In glutReportErrors()\n"));
203 /* reports all the OpenGL errors that happened till now */
207 /* GAME MODE
208 * Hack alert: incomplete... what is GameMode, anyway?
210 static GLint game;
211 static GLboolean game_possible;
212 static GLboolean game_active;
213 static GLuint game_width;
214 static GLuint game_height;
215 static GLuint game_bpp;
216 static GLuint game_refresh;
219 void APIENTRY
220 glutGameModeString (const char *string)
222 D(bug("[AMGLUT] In glutGameModeString()\n"));
224 if (sscanf(string, "%ux%u:%u@%u", &game_width, &game_height, &game_bpp, &game_refresh) == 4) {
225 game_possible = GL_TRUE;
230 int APIENTRY
231 glutGameModeGet (GLenum mode)
233 D(bug("[AMGLUT] In glutGameModeGet()\n"));
235 struct AROSMesaGLUT_TaskNode *__glutTask = _glut_findtask(FindTask(NULL));
236 switch (mode) {
237 case GLUT_GAME_MODE_ACTIVE:
238 return game_active;
239 case GLUT_GAME_MODE_POSSIBLE:
240 return game_possible && !__glutTask->AMGLUTTN_WindowCurrent;
241 case GLUT_GAME_MODE_WIDTH:
242 return game_active ? (int)game_width : -1;
243 case GLUT_GAME_MODE_HEIGHT:
244 return game_active ? (int)game_height : -1;
245 case GLUT_GAME_MODE_PIXEL_DEPTH:
246 return game_active ? (int)game_bpp : -1;
247 case GLUT_GAME_MODE_REFRESH_RATE:
248 return game_active ? (int)game_refresh : -1;
249 default:
250 return -1;
255 int APIENTRY
256 glutEnterGameMode (void)
258 D(bug("[AMGLUT] In glutEnterGameMode()\n"));
260 if (glutGameModeGet(GLUT_GAME_MODE_POSSIBLE)) {
261 _glut_visual.bpp = game_bpp;
262 _glut_visual.refresh = game_refresh;
264 glutInitWindowSize(game_width, game_height);
266 if ((game = glutCreateWindow("<game>")) > 0) {
267 game_active = GL_TRUE;
270 return game;
271 } else {
272 return 0;
277 void GLUTAPIENTRY
278 glutLeaveGameMode (void)
280 D(bug("[AMGLUT] In glutLeaveGameMode()\n"));
282 if (glutGameModeGet(GLUT_GAME_MODE_ACTIVE)) {
283 game_active = GL_FALSE;
285 glutDestroyWindow(game);