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