2 This file is part of fxwt, the window system toolkit of 3dengfx.
4 Copyright (C) 2005 John Tsiombikas <nuclear@siggraph.org>
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 /* main fxwt event handling and window system abstraction through GLUT.
23 * Author: John Tsiombikas 2005
26 #include "3dengfx_config.h"
28 #if GFX_LIBRARY == GLUT
30 #include "gfx_library.h"
32 #include "3dengfx/3denginefx.hpp"
33 #include "common/err_msg.h"
35 #if defined(__unix__) || defined(unix)
37 #ifdef _POSIX_PRIORITY_SCHEDULING
39 #endif // _POSIX_PRIORITY_SCHEDULING
42 #if defined(WIN32) || defined(__WIN32__)
49 static void glut_disp_handler();
50 static void glut_idle_handler();
51 static void glut_keyb_handler(unsigned char key, int x, int y);
52 static void glut_motion_handler(int x, int y);
53 static void glut_button_handler(int bn, int state, int x, int y);
55 extern int fxwt_glut_win;
57 Vector2 fxwt::get_mouse_pos_normalized() {
58 // TODO: implement this
62 void fxwt::set_window_title(const char *title) {
63 glutSetWindow(fxwt_glut_win);
64 glutSetWindowTitle(title);
67 void fxwt::show_cursor(bool show)
69 glutSetCursor(show ? GLUT_CURSOR_LEFT_ARROW : GLUT_CURSOR_NONE);
72 void fxwt::swap_buffers() {
73 glutSetWindow(fxwt_glut_win);
75 #if defined(_POSIX_PRIORITY_SCHEDULING)
83 int fxwt::main_loop() {
86 // register glut event handlers
87 glutSetWindow(fxwt_glut_win);
88 glutDisplayFunc(glut_disp_handler);
89 if(!idle_handlers.empty()) glutIdleFunc(glut_idle_handler);
90 glutKeyboardFunc(glut_keyb_handler);
91 if(!motion_handlers.empty()) {
92 glutMotionFunc(glut_motion_handler);
93 glutPassiveMotionFunc(glut_motion_handler);
95 glutMouseFunc(glut_button_handler);
101 static void glut_disp_handler() {
102 list<void (*)()>::iterator iter = disp_handlers.begin();
103 while(iter != disp_handlers.end()) {
107 static void glut_idle_handler() {
108 list<void (*)()>::iterator iter = idle_handlers.begin();
109 while(iter != idle_handlers.end()) {
114 static void glut_keyb_handler(unsigned char key, int x, int y) {
115 list<void (*)(int)>::iterator iter = keyb_handlers.begin();
116 while(iter != keyb_handlers.end()) {
121 static void glut_motion_handler(int x, int y) {
122 list<void (*)(int, int)>::iterator iter = motion_handlers.begin();
123 while(iter != motion_handlers.end()) {
128 static void glut_button_handler(int bn, int state, int x, int y) {
130 button_state[bn] = state == GLUT_DOWN;
131 list<void (*)(int, int, int, int)>::iterator iter = button_handlers.begin();
132 while(iter != button_handlers.end()) {
133 (*iter++)(bn, state == GLUT_DOWN, x, y);
137 #endif // GFX_LIBRARY == GLUT