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::swap_buffers() {
68 glutSetWindow(fxwt_glut_win);
70 #if defined(_POSIX_PRIORITY_SCHEDULING)
78 int fxwt::main_loop() {
81 // register glut event handlers
82 glutSetWindow(fxwt_glut_win);
83 glutDisplayFunc(glut_disp_handler);
84 if(!idle_handlers.empty()) glutIdleFunc(glut_idle_handler);
85 glutKeyboardFunc(glut_keyb_handler);
86 if(!motion_handlers.empty()) {
87 glutMotionFunc(glut_motion_handler);
88 glutPassiveMotionFunc(glut_motion_handler);
90 glutMouseFunc(glut_button_handler);
96 static void glut_disp_handler() {
97 list<void (*)()>::iterator iter = disp_handlers.begin();
98 while(iter != disp_handlers.end()) {
102 static void glut_idle_handler() {
103 list<void (*)()>::iterator iter = idle_handlers.begin();
104 while(iter != idle_handlers.end()) {
109 static void glut_keyb_handler(unsigned char key, int x, int y) {
110 list<void (*)(int)>::iterator iter = keyb_handlers.begin();
111 while(iter != keyb_handlers.end()) {
116 static void glut_motion_handler(int x, int y) {
117 list<void (*)(int, int)>::iterator iter = motion_handlers.begin();
118 while(iter != motion_handlers.end()) {
123 static void glut_button_handler(int bn, int state, int x, int y) {
125 button_state[bn] = state == GLUT_DOWN;
126 list<void (*)(int, int, int, int)>::iterator iter = button_handlers.begin();
127 while(iter != button_handlers.end()) {
128 (*iter++)(bn, state == GLUT_DOWN, x, y);
132 #endif // GFX_LIBRARY == GLUT