X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=src%2F3dengfx%2Fsrc%2Ffxwt%2Ffxwt_glut.cpp;fp=src%2F3dengfx%2Fsrc%2Ffxwt%2Ffxwt_glut.cpp;h=eded4106c92d45bbdd980a245881fae9c13bbc82;hb=6e23259dbabaeb1711a2a5ca25b9cb421f693759;hp=0000000000000000000000000000000000000000;hpb=fe068fa879814784c45e0cb2e65dac489e8f5594;p=summerhack diff --git a/src/3dengfx/src/fxwt/fxwt_glut.cpp b/src/3dengfx/src/fxwt/fxwt_glut.cpp new file mode 100644 index 0000000..eded410 --- /dev/null +++ b/src/3dengfx/src/fxwt/fxwt_glut.cpp @@ -0,0 +1,132 @@ +/* +This file is part of fxwt, the window system toolkit of 3dengfx. + +Copyright (C) 2005 John Tsiombikas + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +/* main fxwt event handling and window system abstraction through GLUT. + * + * Author: John Tsiombikas 2005 + */ + +#include "3dengfx_config.h" + +#if GFX_LIBRARY == GLUT + +#include "gfx_library.h" +#include "fxwt.hpp" +#include "3dengfx/3denginefx.hpp" +#include "common/err_msg.h" + +#if defined(__unix__) || defined(unix) +#include +#ifdef _POSIX_PRIORITY_SCHEDULING +#include +#endif // _POSIX_PRIORITY_SCHEDULING +#endif // __unix__ + +#if defined(WIN32) || defined(__WIN32__) +#include +#endif // WIN32 + +using std::list; +using namespace fxwt; + +static void glut_disp_handler(); +static void glut_idle_handler(); +static void glut_keyb_handler(unsigned char key, int x, int y); +static void glut_motion_handler(int x, int y); +static void glut_button_handler(int bn, int state, int x, int y); + +extern int fxwt_glut_win; + +Vector2 fxwt::get_mouse_pos_normalized() { + // TODO: implement this + return Vector2(0, 0); +} + +void fxwt::set_window_title(const char *title) { + glutSetWindow(fxwt_glut_win); + glutSetWindowTitle(title); +} + +void fxwt::swap_buffers() { + glutSetWindow(fxwt_glut_win); + glutSwapBuffers(); +#if defined(_POSIX_PRIORITY_SCHEDULING) + sched_yield(); +#elif defined(WIN32) + Sleep(0); +#endif + +} + +int fxwt::main_loop() { + set_verbosity(3); + + // register glut event handlers + glutSetWindow(fxwt_glut_win); + glutDisplayFunc(glut_disp_handler); + if(!idle_handlers.empty()) glutIdleFunc(glut_idle_handler); + glutKeyboardFunc(glut_keyb_handler); + if(!motion_handlers.empty()) { + glutMotionFunc(glut_motion_handler); + glutPassiveMotionFunc(glut_motion_handler); + } + glutMouseFunc(glut_button_handler); + + glutMainLoop(); + return 0; +} + +static void glut_disp_handler() { + list::iterator iter = disp_handlers.begin(); + while(iter != disp_handlers.end()) { + (*iter++)(); + } +} +static void glut_idle_handler() { + list::iterator iter = idle_handlers.begin(); + while(iter != idle_handlers.end()) { + (*iter++)(); + } +} + +static void glut_keyb_handler(unsigned char key, int x, int y) { + list::iterator iter = keyb_handlers.begin(); + while(iter != keyb_handlers.end()) { + (*iter++)(key); + } +} + +static void glut_motion_handler(int x, int y) { + list::iterator iter = motion_handlers.begin(); + while(iter != motion_handlers.end()) { + (*iter++)(x, y); + } +} + +static void glut_button_handler(int bn, int state, int x, int y) { + bn++; + button_state[bn] = state == GLUT_DOWN; + list::iterator iter = button_handlers.begin(); + while(iter != button_handlers.end()) { + (*iter++)(bn, state == GLUT_DOWN, x, y); + } +} + +#endif // GFX_LIBRARY == GLUT