1*da465207SAlexander von Gluck IV /***********************************************************
2*da465207SAlexander von Gluck IV * Copyright (C) 1997, Be Inc. Copyright (C) 1999, Jake Hamby.
3*da465207SAlexander von Gluck IV *
4*da465207SAlexander von Gluck IV * This program is freely distributable without licensing fees
5*da465207SAlexander von Gluck IV * and is provided without guarantee or warrantee expressed or
6*da465207SAlexander von Gluck IV * implied. This program is -not- in the public domain.
7*da465207SAlexander von Gluck IV *
8*da465207SAlexander von Gluck IV *
9*da465207SAlexander von Gluck IV * FILE: glutGet.cpp
10*da465207SAlexander von Gluck IV *
11*da465207SAlexander von Gluck IV * DESCRIPTION: get state information from GL
12*da465207SAlexander von Gluck IV ***********************************************************/
13*da465207SAlexander von Gluck IV
14*da465207SAlexander von Gluck IV /***********************************************************
15*da465207SAlexander von Gluck IV * Headers
16*da465207SAlexander von Gluck IV ***********************************************************/
17*da465207SAlexander von Gluck IV #include <GL/glut.h>
18*da465207SAlexander von Gluck IV #include <string.h>
19*da465207SAlexander von Gluck IV #include <Autolock.h>
20*da465207SAlexander von Gluck IV #include <Screen.h>
21*da465207SAlexander von Gluck IV
22*da465207SAlexander von Gluck IV #include "glutint.h"
23*da465207SAlexander von Gluck IV #include "glutState.h"
24*da465207SAlexander von Gluck IV
25*da465207SAlexander von Gluck IV /***********************************************************
26*da465207SAlexander von Gluck IV * Global variables
27*da465207SAlexander von Gluck IV ***********************************************************/
28*da465207SAlexander von Gluck IV // rough guess, since we don't know how big the monitor really is
29*da465207SAlexander von Gluck IV const float dots_per_mm = (72/25.4); // dots per millimeter
30*da465207SAlexander von Gluck IV
31*da465207SAlexander von Gluck IV /***********************************************************
32*da465207SAlexander von Gluck IV * FUNCTION: glutGet (9.1)
33*da465207SAlexander von Gluck IV *
34*da465207SAlexander von Gluck IV * DESCRIPTION: retrieve window and GL state
35*da465207SAlexander von Gluck IV ***********************************************************/
glutGet(GLenum state)36*da465207SAlexander von Gluck IV int glutGet(GLenum state) {
37*da465207SAlexander von Gluck IV switch(state) {
38*da465207SAlexander von Gluck IV case GLUT_WINDOW_X:
39*da465207SAlexander von Gluck IV {BAutolock winlock(gState.currentWindow->Window()); // need to lock the window
40*da465207SAlexander von Gluck IV if (gState.currentWindow->parent)
41*da465207SAlexander von Gluck IV return (int)gState.currentWindow->Frame().left;
42*da465207SAlexander von Gluck IV else
43*da465207SAlexander von Gluck IV return (int)gState.currentWindow->Window()->Frame().left;
44*da465207SAlexander von Gluck IV }
45*da465207SAlexander von Gluck IV case GLUT_WINDOW_Y:
46*da465207SAlexander von Gluck IV {BAutolock winlock(gState.currentWindow->Window());
47*da465207SAlexander von Gluck IV if (gState.currentWindow->parent)
48*da465207SAlexander von Gluck IV return (int)gState.currentWindow->Frame().top;
49*da465207SAlexander von Gluck IV else
50*da465207SAlexander von Gluck IV return (int)gState.currentWindow->Window()->Frame().top;
51*da465207SAlexander von Gluck IV }
52*da465207SAlexander von Gluck IV case GLUT_WINDOW_WIDTH:
53*da465207SAlexander von Gluck IV {BAutolock winlock(gState.currentWindow->Window());
54*da465207SAlexander von Gluck IV return gState.currentWindow->m_width;
55*da465207SAlexander von Gluck IV }
56*da465207SAlexander von Gluck IV case GLUT_WINDOW_HEIGHT:
57*da465207SAlexander von Gluck IV {BAutolock winlock(gState.currentWindow->Window());
58*da465207SAlexander von Gluck IV return gState.currentWindow->m_height;
59*da465207SAlexander von Gluck IV }
60*da465207SAlexander von Gluck IV case GLUT_WINDOW_PARENT:
61*da465207SAlexander von Gluck IV {BAutolock winlock(gState.currentWindow->Window());
62*da465207SAlexander von Gluck IV if(gState.currentWindow->parent)
63*da465207SAlexander von Gluck IV return gState.currentWindow->parent->num + 1;
64*da465207SAlexander von Gluck IV else
65*da465207SAlexander von Gluck IV return 0;
66*da465207SAlexander von Gluck IV }
67*da465207SAlexander von Gluck IV case GLUT_WINDOW_NUM_CHILDREN:
68*da465207SAlexander von Gluck IV {BAutolock winlock(gState.currentWindow->Window());
69*da465207SAlexander von Gluck IV int num = 0;
70*da465207SAlexander von Gluck IV GlutWindow *children = gState.currentWindow->children;
71*da465207SAlexander von Gluck IV while (children) {
72*da465207SAlexander von Gluck IV num++;
73*da465207SAlexander von Gluck IV children = children->siblings;
74*da465207SAlexander von Gluck IV }
75*da465207SAlexander von Gluck IV return num;
76*da465207SAlexander von Gluck IV }
77*da465207SAlexander von Gluck IV case GLUT_WINDOW_BUFFER_SIZE: // best guesses
78*da465207SAlexander von Gluck IV case GLUT_WINDOW_DEPTH_SIZE:
79*da465207SAlexander von Gluck IV return 32;
80*da465207SAlexander von Gluck IV
81*da465207SAlexander von Gluck IV case GLUT_WINDOW_STENCIL_SIZE:
82*da465207SAlexander von Gluck IV case GLUT_WINDOW_RED_SIZE: // always 24-bit color
83*da465207SAlexander von Gluck IV case GLUT_WINDOW_GREEN_SIZE:
84*da465207SAlexander von Gluck IV case GLUT_WINDOW_BLUE_SIZE:
85*da465207SAlexander von Gluck IV case GLUT_WINDOW_ALPHA_SIZE:
86*da465207SAlexander von Gluck IV case GLUT_WINDOW_ACCUM_RED_SIZE:
87*da465207SAlexander von Gluck IV case GLUT_WINDOW_ACCUM_GREEN_SIZE:
88*da465207SAlexander von Gluck IV case GLUT_WINDOW_ACCUM_BLUE_SIZE:
89*da465207SAlexander von Gluck IV case GLUT_WINDOW_ACCUM_ALPHA_SIZE:
90*da465207SAlexander von Gluck IV return 8;
91*da465207SAlexander von Gluck IV
92*da465207SAlexander von Gluck IV case GLUT_WINDOW_DOUBLEBUFFER: // always double-buffered RGBA
93*da465207SAlexander von Gluck IV case GLUT_WINDOW_RGBA:
94*da465207SAlexander von Gluck IV return 1;
95*da465207SAlexander von Gluck IV
96*da465207SAlexander von Gluck IV case GLUT_WINDOW_COLORMAP_SIZE: // don't support these
97*da465207SAlexander von Gluck IV case GLUT_WINDOW_NUM_SAMPLES:
98*da465207SAlexander von Gluck IV case GLUT_WINDOW_STEREO:
99*da465207SAlexander von Gluck IV return 0;
100*da465207SAlexander von Gluck IV
101*da465207SAlexander von Gluck IV case GLUT_WINDOW_CURSOR:
102*da465207SAlexander von Gluck IV return gState.currentWindow->cursor; // don't need to lock window since it won't change
103*da465207SAlexander von Gluck IV
104*da465207SAlexander von Gluck IV case GLUT_SCREEN_WIDTH:
105*da465207SAlexander von Gluck IV return (int)(BScreen().Frame().Width()) + 1;
106*da465207SAlexander von Gluck IV case GLUT_SCREEN_HEIGHT:
107*da465207SAlexander von Gluck IV return (int)(BScreen().Frame().Height()) + 1;
108*da465207SAlexander von Gluck IV case GLUT_SCREEN_WIDTH_MM:
109*da465207SAlexander von Gluck IV return (int)((BScreen().Frame().Width() + 1) / dots_per_mm);
110*da465207SAlexander von Gluck IV case GLUT_SCREEN_HEIGHT_MM:
111*da465207SAlexander von Gluck IV return (int)((BScreen().Frame().Height() + 1) / dots_per_mm);
112*da465207SAlexander von Gluck IV case GLUT_MENU_NUM_ITEMS:
113*da465207SAlexander von Gluck IV return gState.currentMenu->num;
114*da465207SAlexander von Gluck IV case GLUT_DISPLAY_MODE_POSSIBLE:
115*da465207SAlexander von Gluck IV return __glutConvertDisplayMode(0); // returns 1 if possible
116*da465207SAlexander von Gluck IV case GLUT_INIT_DISPLAY_MODE:
117*da465207SAlexander von Gluck IV return gState.displayMode;
118*da465207SAlexander von Gluck IV case GLUT_INIT_WINDOW_X:
119*da465207SAlexander von Gluck IV return gState.initX;
120*da465207SAlexander von Gluck IV case GLUT_INIT_WINDOW_Y:
121*da465207SAlexander von Gluck IV return gState.initY;
122*da465207SAlexander von Gluck IV case GLUT_INIT_WINDOW_WIDTH:
123*da465207SAlexander von Gluck IV return gState.initWidth;
124*da465207SAlexander von Gluck IV case GLUT_INIT_WINDOW_HEIGHT:
125*da465207SAlexander von Gluck IV return gState.initHeight;
126*da465207SAlexander von Gluck IV case GLUT_ELAPSED_TIME:
127*da465207SAlexander von Gluck IV bigtime_t elapsed, beginning, now;
128*da465207SAlexander von Gluck IV __glutInitTime(&beginning);
129*da465207SAlexander von Gluck IV now = system_time();
130*da465207SAlexander von Gluck IV elapsed = now - beginning;
131*da465207SAlexander von Gluck IV return (int) (elapsed / 1000); // 1000 ticks in a millisecond
132*da465207SAlexander von Gluck IV default:
133*da465207SAlexander von Gluck IV __glutWarning("invalid glutGet parameter: %d", state);
134*da465207SAlexander von Gluck IV return -1;
135*da465207SAlexander von Gluck IV }
136*da465207SAlexander von Gluck IV }
137*da465207SAlexander von Gluck IV
138*da465207SAlexander von Gluck IV /***********************************************************
139*da465207SAlexander von Gluck IV * FUNCTION: glutLayerGet (9.2)
140*da465207SAlexander von Gluck IV *
141*da465207SAlexander von Gluck IV * DESCRIPTION: since we don't support layers, this is easy
142*da465207SAlexander von Gluck IV ***********************************************************/
glutLayerGet(GLenum info)143*da465207SAlexander von Gluck IV int glutLayerGet(GLenum info) {
144*da465207SAlexander von Gluck IV switch(info) {
145*da465207SAlexander von Gluck IV case GLUT_OVERLAY_POSSIBLE:
146*da465207SAlexander von Gluck IV case GLUT_HAS_OVERLAY:
147*da465207SAlexander von Gluck IV return 0;
148*da465207SAlexander von Gluck IV case GLUT_LAYER_IN_USE:
149*da465207SAlexander von Gluck IV return GLUT_NORMAL;
150*da465207SAlexander von Gluck IV case GLUT_TRANSPARENT_INDEX:
151*da465207SAlexander von Gluck IV return -1;
152*da465207SAlexander von Gluck IV case GLUT_NORMAL_DAMAGED:
153*da465207SAlexander von Gluck IV return gState.currentWindow->displayEvent;
154*da465207SAlexander von Gluck IV case GLUT_OVERLAY_DAMAGED:
155*da465207SAlexander von Gluck IV return -1;
156*da465207SAlexander von Gluck IV default:
157*da465207SAlexander von Gluck IV __glutWarning("invalid glutLayerGet param: %d", info);
158*da465207SAlexander von Gluck IV return -1;
159*da465207SAlexander von Gluck IV }
160*da465207SAlexander von Gluck IV }
161*da465207SAlexander von Gluck IV
162*da465207SAlexander von Gluck IV /***********************************************************
163*da465207SAlexander von Gluck IV * FUNCTION: glutDeviceGet (9.3)
164*da465207SAlexander von Gluck IV *
165*da465207SAlexander von Gluck IV * DESCRIPTION: get info about I/O devices we support
166*da465207SAlexander von Gluck IV * easy, since BeOS only supports a keyboard and mouse now
167*da465207SAlexander von Gluck IV ***********************************************************/
glutDeviceGet(GLenum info)168*da465207SAlexander von Gluck IV int glutDeviceGet(GLenum info) {
169*da465207SAlexander von Gluck IV switch(info) {
170*da465207SAlexander von Gluck IV case GLUT_HAS_KEYBOARD:
171*da465207SAlexander von Gluck IV case GLUT_HAS_MOUSE:
172*da465207SAlexander von Gluck IV return 1;
173*da465207SAlexander von Gluck IV
174*da465207SAlexander von Gluck IV case GLUT_HAS_SPACEBALL:
175*da465207SAlexander von Gluck IV case GLUT_NUM_SPACEBALL_BUTTONS:
176*da465207SAlexander von Gluck IV case GLUT_HAS_DIAL_AND_BUTTON_BOX:
177*da465207SAlexander von Gluck IV case GLUT_NUM_DIALS:
178*da465207SAlexander von Gluck IV case GLUT_NUM_BUTTON_BOX_BUTTONS:
179*da465207SAlexander von Gluck IV case GLUT_HAS_TABLET:
180*da465207SAlexander von Gluck IV case GLUT_NUM_TABLET_BUTTONS:
181*da465207SAlexander von Gluck IV case GLUT_HAS_JOYSTICK:
182*da465207SAlexander von Gluck IV case GLUT_JOYSTICK_POLL_RATE:
183*da465207SAlexander von Gluck IV case GLUT_JOYSTICK_BUTTONS:
184*da465207SAlexander von Gluck IV case GLUT_JOYSTICK_AXES:
185*da465207SAlexander von Gluck IV return 0;
186*da465207SAlexander von Gluck IV
187*da465207SAlexander von Gluck IV case GLUT_NUM_MOUSE_BUTTONS:
188*da465207SAlexander von Gluck IV {
189*da465207SAlexander von Gluck IV int32 mouseButtons = 3; // good guess
190*da465207SAlexander von Gluck IV if(get_mouse_type(&mouseButtons) != B_OK) {
191*da465207SAlexander von Gluck IV __glutWarning("error getting number of mouse buttons");
192*da465207SAlexander von Gluck IV }
193*da465207SAlexander von Gluck IV return mouseButtons;
194*da465207SAlexander von Gluck IV }
195*da465207SAlexander von Gluck IV
196*da465207SAlexander von Gluck IV case GLUT_DEVICE_IGNORE_KEY_REPEAT:
197*da465207SAlexander von Gluck IV if (gState.currentWindow)
198*da465207SAlexander von Gluck IV return gState.currentWindow->ignoreKeyRepeat;
199*da465207SAlexander von Gluck IV return 0;
200*da465207SAlexander von Gluck IV
201*da465207SAlexander von Gluck IV case GLUT_DEVICE_KEY_REPEAT:
202*da465207SAlexander von Gluck IV return GLUT_KEY_REPEAT_DEFAULT;
203*da465207SAlexander von Gluck IV
204*da465207SAlexander von Gluck IV default:
205*da465207SAlexander von Gluck IV __glutWarning("invalid glutDeviceGet parameter: %d", info);
206*da465207SAlexander von Gluck IV return -1;
207*da465207SAlexander von Gluck IV }
208*da465207SAlexander von Gluck IV }
209*da465207SAlexander von Gluck IV
210*da465207SAlexander von Gluck IV /***********************************************************
211*da465207SAlexander von Gluck IV * FUNCTION: glutGetModifiers (9.4)
212*da465207SAlexander von Gluck IV *
213*da465207SAlexander von Gluck IV * DESCRIPTION: get the modifier key state for the current window
214*da465207SAlexander von Gluck IV ***********************************************************/
glutGetModifiers()215*da465207SAlexander von Gluck IV int glutGetModifiers() {
216*da465207SAlexander von Gluck IV if(gState.modifierKeys == (int) ~0) {
217*da465207SAlexander von Gluck IV __glutWarning(
218*da465207SAlexander von Gluck IV "glutCurrentModifiers: do not call outside core input callback.");
219*da465207SAlexander von Gluck IV return 0;
220*da465207SAlexander von Gluck IV }
221*da465207SAlexander von Gluck IV return gState.modifierKeys;
222*da465207SAlexander von Gluck IV }
223*da465207SAlexander von Gluck IV
224*da465207SAlexander von Gluck IV
225*da465207SAlexander von Gluck IV #ifdef __HAIKU__
226*da465207SAlexander von Gluck IV
227*da465207SAlexander von Gluck IV extern "C" {
228*da465207SAlexander von Gluck IV GLUTproc __glutGetProcAddress(const char* procName);
229*da465207SAlexander von Gluck IV }
230*da465207SAlexander von Gluck IV
231*da465207SAlexander von Gluck IV GLUTproc
__glutGetProcAddress(const char * procName)232*da465207SAlexander von Gluck IV __glutGetProcAddress(const char* procName)
233*da465207SAlexander von Gluck IV {
234*da465207SAlexander von Gluck IV if (gState.currentWindow)
235*da465207SAlexander von Gluck IV return (GLUTproc) gState.currentWindow->GetGLProcAddress(procName);
236*da465207SAlexander von Gluck IV return NULL;
237*da465207SAlexander von Gluck IV }
238*da465207SAlexander von Gluck IV
239*da465207SAlexander von Gluck IV #endif
240