Vegastrike 0.5.1 rc1  1.0
Original sources for Vegastrike Evolved
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
winsys.h File Reference
#include "config.h"
#include <GL/glut.h>

Go to the source code of this file.

Macros

#define UCHAR_MAX   255
 
#define HAVE_GLUT
 

Typedefs

typedef void(* winsys_display_func_t )()
 
typedef void(* winsys_idle_func_t )()
 
typedef void(* winsys_reshape_func_t )(int w, int h)
 
typedef void(* winsys_keyboard_func_t )(unsigned int key, unsigned int mod, bool release, int x, int y)
 
typedef void(* winsys_mouse_func_t )(int button, int state, int x, int y)
 
typedef void(* winsys_motion_func_t )(int x, int y)
 
typedef void(* winsys_atexit_func_t )(void)
 

Enumerations

enum  winsys_keysym_t {
  WSK_NOT_AVAIL = 0, WSK_KP0 = 0, WSK_KP1 = 0, WSK_KP2 = 0,
  WSK_KP3 = 0, WSK_KP4 = 0, WSK_KP5 = 0, WSK_KP6 = 0,
  WSK_KP7 = 0, WSK_KP8 = 0, WSK_KP9 = 0, WSK_KP_PERIOD = 0,
  WSK_KP_DIVIDE = 0, WSK_KP_MULTIPLY = 0, WSK_KP_MINUS = 0, WSK_KP_PLUS = 0,
  WSK_KP_ENTER = 0, WSK_KP_EQUALS = 0, WSK_RETURN = 13, WSK_TAB = '\t',
  WSK_ESCAPE = 27, WSK_BACKSPACE, WSK_DELETE, WSK_UP = GLUT_KEY_UP+128,
  WSK_DOWN = GLUT_KEY_DOWN+128, WSK_RIGHT = GLUT_KEY_RIGHT+128, WSK_LEFT = GLUT_KEY_LEFT+128, WSK_INSERT = GLUT_KEY_INSERT+128,
  WSK_HOME = GLUT_KEY_HOME+128, WSK_END = GLUT_KEY_END+128, WSK_PAGEUP = GLUT_KEY_PAGE_UP+128, WSK_PAGEDOWN = GLUT_KEY_PAGE_DOWN+128,
  WSK_F1 = GLUT_KEY_F1+128, WSK_F2 = GLUT_KEY_F2+128, WSK_F3 = GLUT_KEY_F3+128, WSK_F4 = GLUT_KEY_F4+128,
  WSK_F5 = GLUT_KEY_F5+128, WSK_F6 = GLUT_KEY_F6+128, WSK_F7 = GLUT_KEY_F7+128, WSK_F8 = GLUT_KEY_F8+128,
  WSK_F9 = GLUT_KEY_F9+128, WSK_F10 = GLUT_KEY_F10+128, WSK_F11 = GLUT_KEY_F11+128, WSK_F12 = GLUT_KEY_F12+128,
  WSK_F13 = 0, WSK_F14 = 0, WSK_F15 = 0, WSK_NUMLOCK = 0,
  WSK_CAPSLOCK = 0, WSK_SCROLLOCK = 0, WSK_RSHIFT = 0, WSK_LSHIFT = 0,
  WSK_RCTRL = 0, WSK_LCTRL = 0, WSK_RALT = 0, WSK_LALT = 0,
  WSK_RMETA = 0, WSK_LMETA = 0, WSK_BREAK = 0, WSK_PAUSE = 0,
  WSK_LAST = UCHAR_MAX
}
 
enum  winsys_modifiers {
  WSK_MOD_NONE =0, WSK_MOD_LSHIFT =GLUT_ACTIVE_SHIFT, WSK_MOD_RSHIFT =GLUT_ACTIVE_SHIFT, WSK_MOD_LCTRL =GLUT_ACTIVE_CTRL,
  WSK_MOD_RCTRL =GLUT_ACTIVE_CTRL, WSK_MOD_LALT =GLUT_ACTIVE_ALT, WSK_MOD_RALT =GLUT_ACTIVE_ALT, WSK_MOD_LMETA =0,
  WSK_MOD_RMETA =0, WSK_MOD_NUM =0, WSK_MOD_CAPS =0, WSK_MOD_MODE =0
}
 
enum  winsys_mouse_button_t {
  WS_LEFT_BUTTON = GLUT_LEFT_BUTTON, WS_MIDDLE_BUTTON = GLUT_MIDDLE_BUTTON, WS_RIGHT_BUTTON = GLUT_RIGHT_BUTTON, WS_WHEEL_UP,
  WS_WHEEL_DOWN
}
 
enum  winsys_button_state_t { WS_MOUSE_DOWN = GLUT_DOWN, WS_MOUSE_UP = GLUT_UP }
 

Functions

void winsys_post_redisplay ()
 
void winsys_set_display_func (winsys_display_func_t func)
 
void winsys_set_idle_func (winsys_idle_func_t func)
 
void winsys_set_reshape_func (winsys_reshape_func_t func)
 
void winsys_set_keyboard_func (winsys_keyboard_func_t func)
 
void winsys_set_mouse_func (winsys_mouse_func_t func)
 
void winsys_set_motion_func (winsys_motion_func_t func)
 
void winsys_set_passive_motion_func (winsys_motion_func_t func)
 
void winsys_swap_buffers ()
 
void winsys_enable_key_repeat (bool enabled)
 
void winsys_warp_pointer (int x, int y)
 
void winsys_show_cursor (bool visible)
 
void winsys_init (int *argc, char **argv, char const *window_title, char const *icon_title)
 
void winsys_shutdown ()
 
void winsys_process_events ()
 
void winsys_atexit (winsys_atexit_func_t func)
 
void winsys_exit (int code)
 

Macro Definition Documentation

#define HAVE_GLUT

Definition at line 25 of file winsys.h.

#define UCHAR_MAX   255

Definition at line 23 of file winsys.h.

Typedef Documentation

typedef void(* winsys_atexit_func_t)(void)

Definition at line 305 of file winsys.h.

typedef void(* winsys_display_func_t)()

Definition at line 297 of file winsys.h.

typedef void(* winsys_idle_func_t)()

Definition at line 298 of file winsys.h.

typedef void(* winsys_keyboard_func_t)(unsigned int key, unsigned int mod, bool release, int x, int y)

Definition at line 300 of file winsys.h.

typedef void(* winsys_motion_func_t)(int x, int y)

Definition at line 303 of file winsys.h.

typedef void(* winsys_mouse_func_t)(int button, int state, int x, int y)

Definition at line 302 of file winsys.h.

typedef void(* winsys_reshape_func_t)(int w, int h)

Definition at line 299 of file winsys.h.

Enumeration Type Documentation

Enumerator
WS_MOUSE_DOWN 
WS_MOUSE_UP 

Definition at line 289 of file winsys.h.

289  {
290  WS_MOUSE_DOWN = GLUT_DOWN,
291  WS_MOUSE_UP = GLUT_UP
Enumerator
WSK_NOT_AVAIL 
WSK_KP0 
WSK_KP1 
WSK_KP2 
WSK_KP3 
WSK_KP4 
WSK_KP5 
WSK_KP6 
WSK_KP7 
WSK_KP8 
WSK_KP9 
WSK_KP_PERIOD 
WSK_KP_DIVIDE 
WSK_KP_MULTIPLY 
WSK_KP_MINUS 
WSK_KP_PLUS 
WSK_KP_ENTER 
WSK_KP_EQUALS 
WSK_RETURN 
WSK_TAB 
WSK_ESCAPE 
WSK_BACKSPACE 
WSK_DELETE 
WSK_UP 
WSK_DOWN 
WSK_RIGHT 
WSK_LEFT 
WSK_INSERT 
WSK_HOME 
WSK_END 
WSK_PAGEUP 
WSK_PAGEDOWN 
WSK_F1 
WSK_F2 
WSK_F3 
WSK_F4 
WSK_F5 
WSK_F6 
WSK_F7 
WSK_F8 
WSK_F9 
WSK_F10 
WSK_F11 
WSK_F12 
WSK_F13 
WSK_F14 
WSK_F15 
WSK_NUMLOCK 
WSK_CAPSLOCK 
WSK_SCROLLOCK 
WSK_RSHIFT 
WSK_LSHIFT 
WSK_RCTRL 
WSK_LCTRL 
WSK_RALT 
WSK_LALT 
WSK_RMETA 
WSK_LMETA 
WSK_BREAK 
WSK_PAUSE 
WSK_LAST 

Definition at line 183 of file winsys.h.

183  {
184  WSK_NOT_AVAIL = 0,
185 
186  /* Numeric keypad */
187  WSK_KP0 = 0,
188  WSK_KP1 = 0,
189  WSK_KP2 = 0,
190  WSK_KP3 = 0,
191  WSK_KP4 = 0,
192  WSK_KP5 = 0,
193  WSK_KP6 = 0,
194  WSK_KP7 = 0,
195  WSK_KP8 = 0,
196  WSK_KP9 = 0,
197  WSK_KP_PERIOD = 0,
198  WSK_KP_DIVIDE = 0,
199  WSK_KP_MULTIPLY = 0,
200  WSK_KP_MINUS = 0,
201  WSK_KP_PLUS = 0,
202  WSK_KP_ENTER = 0,
203  WSK_KP_EQUALS = 0,
204 
205  WSK_RETURN = 13,
206  WSK_TAB = '\t',
207  WSK_ESCAPE = 27,
208  WSK_BACKSPACE =
209 #ifdef __APPLE__
210  127,
211 #else
212  8,
213 #endif
214  WSK_DELETE =
215 #ifdef __APPLE__
216  8,
217 #else
218  127,
219 #endif
220 
221  /* Arrows + Home/End pad */
222  WSK_UP = GLUT_KEY_UP+128,
223  WSK_DOWN = GLUT_KEY_DOWN+128,
224  WSK_RIGHT = GLUT_KEY_RIGHT+128,
225  WSK_LEFT = GLUT_KEY_LEFT+128,
226  WSK_INSERT = GLUT_KEY_INSERT+128,
227  WSK_HOME = GLUT_KEY_HOME+128,
228  WSK_END = GLUT_KEY_END+128,
229  WSK_PAGEUP = GLUT_KEY_PAGE_UP+128,
230  WSK_PAGEDOWN = GLUT_KEY_PAGE_DOWN+128,
231 
232  /* Function keys */
233  WSK_F1 = GLUT_KEY_F1+128,
234  WSK_F2 = GLUT_KEY_F2+128,
235  WSK_F3 = GLUT_KEY_F3+128,
236  WSK_F4 = GLUT_KEY_F4+128,
237  WSK_F5 = GLUT_KEY_F5+128,
238  WSK_F6 = GLUT_KEY_F6+128,
239  WSK_F7 = GLUT_KEY_F7+128,
240  WSK_F8 = GLUT_KEY_F8+128,
241  WSK_F9 = GLUT_KEY_F9+128,
242  WSK_F10 = GLUT_KEY_F10+128,
243  WSK_F11 = GLUT_KEY_F11+128,
244  WSK_F12 = GLUT_KEY_F12+128,
245  WSK_F13 = 0,
246  WSK_F14 = 0,
247  WSK_F15 = 0,
248 
249  /* Key state modifier keys */
250  WSK_NUMLOCK = 0,
251  WSK_CAPSLOCK = 0,
252  WSK_SCROLLOCK = 0,
253  WSK_RSHIFT = 0,
254  WSK_LSHIFT = 0,
255  WSK_RCTRL = 0,
256  WSK_LCTRL = 0,
257  WSK_RALT = 0,
258  WSK_LALT = 0,
259  WSK_RMETA = 0,
260  WSK_LMETA = 0,
261  WSK_BREAK = 0,
262  WSK_PAUSE = 0,
263  WSK_LAST = UCHAR_MAX /* GLUT doesn't define a max key, but this is more
264  than enough as of version 3.7 */
Enumerator
WSK_MOD_NONE 
WSK_MOD_LSHIFT 
WSK_MOD_RSHIFT 
WSK_MOD_LCTRL 
WSK_MOD_RCTRL 
WSK_MOD_LALT 
WSK_MOD_RALT 
WSK_MOD_LMETA 
WSK_MOD_RMETA 
WSK_MOD_NUM 
WSK_MOD_CAPS 
WSK_MOD_MODE 

Definition at line 266 of file winsys.h.

266  {
267  WSK_MOD_NONE=0,
268  WSK_MOD_LSHIFT=GLUT_ACTIVE_SHIFT,
269  WSK_MOD_RSHIFT=GLUT_ACTIVE_SHIFT,
270  WSK_MOD_LCTRL=GLUT_ACTIVE_CTRL ,
271  WSK_MOD_RCTRL=GLUT_ACTIVE_CTRL ,
272  WSK_MOD_LALT=GLUT_ACTIVE_ALT ,
273  WSK_MOD_RALT=GLUT_ACTIVE_ALT ,
274  WSK_MOD_LMETA=0 ,
275  WSK_MOD_RMETA=0,
276  WSK_MOD_NUM=0,
277  WSK_MOD_CAPS=0,
278  WSK_MOD_MODE=0
Enumerator
WS_LEFT_BUTTON 
WS_MIDDLE_BUTTON 
WS_RIGHT_BUTTON 
WS_WHEEL_UP 
WS_WHEEL_DOWN 

Definition at line 281 of file winsys.h.

281  {
282  WS_LEFT_BUTTON = GLUT_LEFT_BUTTON,
283  WS_MIDDLE_BUTTON = GLUT_MIDDLE_BUTTON,
284  WS_RIGHT_BUTTON = GLUT_RIGHT_BUTTON,
285  WS_WHEEL_UP,

Function Documentation

void winsys_atexit ( winsys_atexit_func_t  func)

Sets the function to be called when program ends. Note that this function should only be called once.

Author
jfpatry
Date
Created: 2000-10-20
Modified: 2000-10-20

Definition at line 867 of file winsys.cpp.

References VSFileSystem::vs_fprintf().

868 {
869  static bool called = false;
870  if (called)
871  VSFileSystem::vs_fprintf( stderr, "winsys_atexit called twice\n" );
872  called = true;
873 
874  //atexit(func);
875 }
void winsys_enable_key_repeat ( bool  enabled)

Enables/disables key repeat messages from being generated

Returns
Author
jfpatry
Date
Created: 2000-10-19
Modified: 2000-10-19

Definition at line 817 of file winsys.cpp.

Referenced by GFXInit().

818 {
819  glutIgnoreKeyRepeat( !enabled );
820 }
void winsys_exit ( int  code)

Exits the program

Author
jfpatry
Date
Created: 2000-10-20
Modified: 2000-10-20

Definition at line 884 of file winsys.cpp.

References winsys_shutdown().

Referenced by bootstrap_main_loop(), Mission::DirectorBenchmark(), main(), GameMenu::processExitGameButton(), and VSExit().

885 {
886  winsys_shutdown();
887  exit( code );
888 }
void winsys_init ( int argc,
char **  argv,
char const *  window_title,
char const *  icon_title 
)

Initializes the OpenGL rendering context, and creates a window (or sets up fullscreen mode if selected)

Author
jfpatry
Date
Created: 2000-10-19
Modified: 2000-10-19

Definition at line 747 of file winsys.cpp.

References gl_options_t::color_depth, gl_options_t::fullscreen, g_game, VegaConfig::getVariable(), gl_options, height, XMLSupport::parse_bool(), XMLSupport::parse_int(), vs_config, VSFileSystem::vs_dprintf(), VSFileSystem::vs_fprintf(), width, game_data_t::x_resolution, and game_data_t::y_resolution.

Referenced by GFXInit().

748 {
749  int width, height;
750  int glutWindow;
751  g_game.x_resolution = XMLSupport::parse_int( vs_config->getVariable( "graphics", "x_resolution", "1024" ) );
752  g_game.y_resolution = XMLSupport::parse_int( vs_config->getVariable( "graphics", "y_resolution", "768" ) );
753  gl_options.fullscreen = XMLSupport::parse_bool( vs_config->getVariable( "graphics", "fullscreen", "false" ) );
754  gl_options.color_depth = XMLSupport::parse_int( vs_config->getVariable( "graphics", "colordepth", "32" ) );
755  glutInit( argc, argv );
756  static bool get_stencil = XMLSupport::parse_bool( vs_config->getVariable( "graphics", "glut_stencil", "true" ) );
757  if (get_stencil) {
758 #ifdef __APPLE__
759  if ( !(glutInitDisplayMode( GLUT_RGBA|GLUT_DEPTH|GLUT_DOUBLE|GLUT_STENCIL ), 1) )
760  glutInitDisplayMode( GLUT_RGBA|GLUT_DEPTH|GLUT_DOUBLE );
761 #else
762  glutInitDisplayMode( GLUT_RGBA|GLUT_DEPTH|GLUT_DOUBLE|GLUT_STENCIL );
763 #endif
764  } else {
765  glutInitDisplayMode( GLUT_RGBA|GLUT_DEPTH|GLUT_DOUBLE );
766  }
767  char str[1024];
768  sprintf( str, "%dx%d:%d@60", g_game.x_resolution, g_game.y_resolution, gl_options.color_depth );
769  glutGameModeString( str );
770  VSFileSystem::vs_dprintf('3', "Game Mode Params %dx%d at depth %d @ %d Hz\n", glutGameModeGet( GLUT_GAME_MODE_WIDTH ),
771  glutGameModeGet( GLUT_GAME_MODE_WIDTH ), glutGameModeGet( GLUT_GAME_MODE_PIXEL_DEPTH ),
772  glutGameModeGet( GLUT_GAME_MODE_REFRESH_RATE ) );
773  /* Create a window */
774  if ( gl_options.fullscreen && (glutGameModeGet( GLUT_GAME_MODE_POSSIBLE ) != -1) ) {
775  glutInitWindowPosition( 0, 0 );
776  glutEnterGameMode();
777  VSFileSystem::vs_dprintf('3', "Game Mode Params %dx%d at depth %d @ %d Hz\n", glutGameModeGet(
778  GLUT_GAME_MODE_WIDTH ), glutGameModeGet( GLUT_GAME_MODE_WIDTH ), glutGameModeGet(
779  GLUT_GAME_MODE_PIXEL_DEPTH ), glutGameModeGet( GLUT_GAME_MODE_REFRESH_RATE ) );
780  } else {
781  /* Set the initial window size */
782  glutInitWindowSize( g_game.x_resolution, g_game.y_resolution );
783 
784  glutWindow = glutCreateWindow( window_title );
785  if (glutWindow == 0) {
786  (void) VSFileSystem::vs_fprintf( stderr, "Couldn't create a window.\n" );
787  exit( 1 );
788  }
789  }
790 }
void winsys_post_redisplay ( )

Requests that the screen be redrawn

Author
jfpatry
Date
Created: 2000-10-19
Modified: 2000-10-19

Definition at line 575 of file winsys.cpp.

576 {
577  redisplay = true;
578 }
void winsys_process_events ( )

Processes and dispatches events. This function never returns.

Returns
No.
Author
jfpatry
Date
Created: 2000-10-19
Modified: 2000-10-19

Definition at line 849 of file winsys.cpp.

References glut_keyboard_cb(), glut_keyboard_up_cb(), glut_special_cb(), and glut_special_up_cb().

Referenced by GFXLoop().

850 {
851  /* Set up keyboard callbacks */
852  glutKeyboardFunc( glut_keyboard_cb );
853  glutKeyboardUpFunc( glut_keyboard_up_cb );
854  glutSpecialFunc( glut_special_cb );
855  glutSpecialUpFunc( glut_special_up_cb );
856 
857  glutMainLoop();
858 }
void winsys_set_display_func ( winsys_display_func_t  func)

Sets the display callback

Author
jfpatry
Date
Created: 2000-10-19
Modified: 2000-10-19

Definition at line 587 of file winsys.cpp.

Referenced by GFXLoop().

588 {
589  glutDisplayFunc( func );
590 }
void winsys_set_idle_func ( winsys_idle_func_t  func)

Sets the idle callback

Author
jfpatry
Date
Created: 2000-10-19
Modified: 2000-10-19

Definition at line 599 of file winsys.cpp.

Referenced by GFXLoop().

600 {
601  glutIdleFunc( func );
602 }
void winsys_set_keyboard_func ( winsys_keyboard_func_t  func)

Sets the keyboard callback

Author
jfpatry
Date
Created: 2000-10-19
Modified: 2000-10-19

Definition at line 674 of file winsys.cpp.

Referenced by ConsoleKeys::BringConsole(), BaseInterface::InitCallbacks(), RestoreKB(), UniverseUtil::startMenuInterface(), CockpitKeys::TextMessageKey(), and NavComputer::toggleVisibility().

675 {
676  keyboard_func = func;
677 }
void winsys_set_motion_func ( winsys_motion_func_t  func)

Sets the mouse motion callback (when a mouse button is pressed)

Author
jfpatry
Date
Created: 2000-10-19
Modified: 2000-10-19

Definition at line 698 of file winsys.cpp.

Referenced by BaseInterface::InitCallbacks(), GameCockpit::NavScreen(), RestoreMouse(), UniverseUtil::startMenuInterface(), EventManager::takeOverEventManagement(), and NavComputer::toggleVisibility().

699 {
700  glutMotionFunc( func );
701 }
void winsys_set_mouse_func ( winsys_mouse_func_t  func)

Sets the mouse button-press callback

Author
jfpatry
Date
Created: 2000-10-19
Modified: 2000-10-19

Definition at line 686 of file winsys.cpp.

Referenced by BaseInterface::InitCallbacks(), GameCockpit::NavScreen(), RestoreMouse(), UniverseUtil::startMenuInterface(), EventManager::takeOverEventManagement(), and NavComputer::toggleVisibility().

687 {
688  glutMouseFunc( func );
689 }
void winsys_set_passive_motion_func ( winsys_motion_func_t  func)

Sets the mouse motion callback (when no mouse button is pressed)

Author
jfpatry
Date
Created: 2000-10-19
Modified: 2000-10-19

Definition at line 710 of file winsys.cpp.

Referenced by BaseInterface::InitCallbacks(), GameCockpit::NavScreen(), RestoreMouse(), UniverseUtil::startMenuInterface(), EventManager::takeOverEventManagement(), and NavComputer::toggleVisibility().

711 {
712  glutPassiveMotionFunc( func );
713 }
void winsys_set_reshape_func ( winsys_reshape_func_t  func)

Sets the reshape callback

Author
jfpatry
Date
Created: 2000-10-19
Modified: 2000-10-19

Definition at line 611 of file winsys.cpp.

Referenced by GFXInit().

612 {
613  glutReshapeFunc( func );
614 }
void winsys_show_cursor ( bool  visible)

Shows/hides mouse cursor

Author
jfpatry
Date
Created: 2000-10-19
Modified: 2000-10-19

Definition at line 829 of file winsys.cpp.

Referenced by ConditionalCursorDraw(), and GFXInit().

830 {
831  static bool vis = true;
832  if (visible != vis) {
833  if (visible)
834  glutSetCursor( GLUT_CURSOR_LEFT_ARROW );
835  else
836  glutSetCursor( GLUT_CURSOR_NONE );
837  vis = visible;
838  }
839 }
void winsys_shutdown ( )

Deallocates resources in preparation for program termination

Author
jfpatry
Date
Created: 2000-10-19
Modified: 2000-10-19

Definition at line 799 of file winsys.cpp.

References gl_options_t::fullscreen, and gl_options.

Referenced by cleanup(), GFXShutdown(), and winsys_exit().

800 {
801  static bool shutdown = false;
802  if (!shutdown) {
803  shutdown = true;
805  glutLeaveGameMode();
806  }
807 }
void winsys_swap_buffers ( )

Copies the OpenGL back buffer to the front buffer

Author
jfpatry
Date
Created: 2000-10-19
Modified: 2000-10-19

Definition at line 722 of file winsys.cpp.

Referenced by GFXEndScene(), and GFXInit().

723 {
724  glutSwapBuffers();
725 }
void winsys_warp_pointer ( int  x,
int  y 
)

Moves the mouse pointer to (x,y)

Author
jfpatry
Date
Created: 2000-10-19
Modified: 2000-10-19

Definition at line 734 of file winsys.cpp.

Referenced by BaseInterface::Room::Click(), and DealWithWarp().

735 {
736  glutWarpPointer( x, y );
737 }