1 /***********************************************************
2 * Copyright (C) 1997, Be Inc. All rights reserved.
6 * DESCRIPTION: get state information from GL
7 ***********************************************************/
9 /***********************************************************
11 ***********************************************************/
16 #include "glutState.h"
18 /***********************************************************
20 ***********************************************************/
21 // rough guess, since we don't know how big the monitor really is
22 const float dots_per_mm
= (72/25.4); // dots per millimeter
24 /***********************************************************
25 * FUNCTION: glutGet (9.1)
27 * DESCRIPTION: retrieve window and GL state
28 ***********************************************************/
29 int glutGet(GLenum state
) {
32 {BAutolock
winlock(gState
.currentWindow
->Window()); // need to lock the window
33 if (gState
.currentWindow
->parent
)
34 return (int)gState
.currentWindow
->Frame().left
;
36 return (int)gState
.currentWindow
->Window()->Frame().left
;
39 {BAutolock
winlock(gState
.currentWindow
->Window());
40 if (gState
.currentWindow
->parent
)
41 return (int)gState
.currentWindow
->Frame().top
;
43 return (int)gState
.currentWindow
->Window()->Frame().top
;
45 case GLUT_WINDOW_WIDTH
:
46 {BAutolock
winlock(gState
.currentWindow
->Window());
47 return gState
.currentWindow
->m_width
;
49 case GLUT_WINDOW_HEIGHT
:
50 {BAutolock
winlock(gState
.currentWindow
->Window());
51 return gState
.currentWindow
->m_height
;
53 case GLUT_WINDOW_PARENT
:
54 {BAutolock
winlock(gState
.currentWindow
->Window());
55 if(gState
.currentWindow
->parent
)
56 return gState
.currentWindow
->parent
->num
+ 1;
60 case GLUT_WINDOW_NUM_CHILDREN
:
61 {BAutolock
winlock(gState
.currentWindow
->Window());
63 GlutWindow
*children
= gState
.currentWindow
->children
;
66 children
= children
->siblings
;
70 case GLUT_WINDOW_BUFFER_SIZE
: // best guesses
71 case GLUT_WINDOW_DEPTH_SIZE
:
74 case GLUT_WINDOW_STENCIL_SIZE
:
75 case GLUT_WINDOW_RED_SIZE
: // always 24-bit color
76 case GLUT_WINDOW_GREEN_SIZE
:
77 case GLUT_WINDOW_BLUE_SIZE
:
78 case GLUT_WINDOW_ALPHA_SIZE
:
79 case GLUT_WINDOW_ACCUM_RED_SIZE
:
80 case GLUT_WINDOW_ACCUM_GREEN_SIZE
:
81 case GLUT_WINDOW_ACCUM_BLUE_SIZE
:
82 case GLUT_WINDOW_ACCUM_ALPHA_SIZE
:
85 case GLUT_WINDOW_DOUBLEBUFFER
: // always double-buffered RGBA
86 case GLUT_WINDOW_RGBA
:
89 case GLUT_WINDOW_COLORMAP_SIZE
: // don't support these
90 case GLUT_WINDOW_NUM_SAMPLES
:
91 case GLUT_WINDOW_STEREO
:
94 case GLUT_WINDOW_CURSOR
:
95 return gState
.currentWindow
->cursor
; // don't need to lock window since it won't change
97 case GLUT_SCREEN_WIDTH
:
98 return (int)(BScreen().Frame().Width()) + 1;
99 case GLUT_SCREEN_HEIGHT
:
100 return (int)(BScreen().Frame().Height()) + 1;
101 case GLUT_SCREEN_WIDTH_MM
:
102 return (int)((BScreen().Frame().Width() + 1) / dots_per_mm
);
103 case GLUT_SCREEN_HEIGHT_MM
:
104 return (int)((BScreen().Frame().Height() + 1) / dots_per_mm
);
105 case GLUT_MENU_NUM_ITEMS
:
106 return gState
.currentMenu
->num
;
107 case GLUT_DISPLAY_MODE_POSSIBLE
:
108 return __glutConvertDisplayMode(0); // returns 1 if possible
109 case GLUT_INIT_DISPLAY_MODE
:
110 return gState
.displayMode
;
111 case GLUT_INIT_WINDOW_X
:
113 case GLUT_INIT_WINDOW_Y
:
115 case GLUT_INIT_WINDOW_WIDTH
:
116 return gState
.initWidth
;
117 case GLUT_INIT_WINDOW_HEIGHT
:
118 return gState
.initHeight
;
119 case GLUT_ELAPSED_TIME
:
120 bigtime_t elapsed
, beginning
, now
;
121 __glutInitTime(&beginning
);
123 elapsed
= now
- beginning
;
124 return (int) (elapsed
/ 1000); // 1000 ticks in a millisecond
126 __glutWarning("invalid glutGet parameter: %d", state
);
131 /***********************************************************
132 * FUNCTION: glutLayerGet (9.2)
134 * DESCRIPTION: since we don't support layers, this is easy
135 ***********************************************************/
136 int glutLayerGet(GLenum info
) {
138 case GLUT_OVERLAY_POSSIBLE
:
139 case GLUT_HAS_OVERLAY
:
141 case GLUT_LAYER_IN_USE
:
143 case GLUT_TRANSPARENT_INDEX
:
145 case GLUT_NORMAL_DAMAGED
:
146 return gState
.currentWindow
->displayEvent
;
147 case GLUT_OVERLAY_DAMAGED
:
150 __glutWarning("invalid glutLayerGet param: %d", info
);
155 /***********************************************************
156 * FUNCTION: glutDeviceGet (9.3)
158 * DESCRIPTION: get info about I/O devices we support
159 * easy, since BeOS only supports a keyboard and mouse now
160 ***********************************************************/
161 int glutDeviceGet(GLenum info
) {
163 case GLUT_HAS_KEYBOARD
:
167 case GLUT_HAS_SPACEBALL
:
168 case GLUT_HAS_DIAL_AND_BUTTON_BOX
:
169 case GLUT_HAS_TABLET
:
170 case GLUT_NUM_SPACEBALL_BUTTONS
:
171 case GLUT_NUM_BUTTON_BOX_BUTTONS
:
173 case GLUT_NUM_TABLET_BUTTONS
:
176 case GLUT_NUM_MOUSE_BUTTONS
:
178 int32 mouseButtons
= 3; // good guess
179 if(get_mouse_type(&mouseButtons
) != B_OK
) {
180 __glutWarning("error getting number of mouse buttons");
186 __glutWarning("invalid glutDeviceGet parameter: %d", info
);
191 /***********************************************************
192 * FUNCTION: glutGetModifiers (9.4)
194 * DESCRIPTION: get the modifier key state for the current window
195 ***********************************************************/
196 int glutGetModifiers() {
197 if(gState
.modifierKeys
== (int) ~0) {
199 "glutCurrentModifiers: do not call outside core input callback.");
202 return gState
.modifierKeys
;
205 /***********************************************************
206 * FUNCTION: glutExtensionSupported (9.5)
208 * DESCRIPTION: is an OpenGL extension supported (from glut_ext.c)
209 ***********************************************************/
210 int glutExtensionSupported(const char *extension
) {
211 static const GLubyte
*extensions
= NULL
;
212 const GLubyte
*start
;
213 GLubyte
*where
, *terminator
;
215 /* Extension names should not have spaces. */
216 where
= (GLubyte
*) strchr(extension
, ' ');
217 if (where
|| *extension
== '\0')
221 extensions
= glGetString(GL_EXTENSIONS
);
222 /* It takes a bit of care to be fool-proof about parsing the
223 OpenGL extensions string. Don't be fooled by sub-strings,
228 where
= (GLubyte
*) strstr((const char *) start
, extension
);
231 terminator
= where
+ strlen(extension
);
232 if (where
== start
|| *(where
- 1) == ' ') {
233 if (*terminator
== ' ' || *terminator
== '\0') {