From d5c33850b3cef417384e8648518e95b6c04b849c Mon Sep 17 00:00:00 2001 From: Vegard Storheil Eriksen Date: Tue, 9 Feb 2010 19:49:35 +0100 Subject: Replaced GLUT with SDL. --- foo.cpp | 68 +++++++++++++++++++++++++++++++++++++++++------------------------ 1 file changed, 43 insertions(+), 25 deletions(-) (limited to 'foo.cpp') diff --git a/foo.cpp b/foo.cpp index e6354ba..3726b75 100755 --- a/foo.cpp +++ b/foo.cpp @@ -1,15 +1,11 @@ -#ifndef __APPLE__ -#include -#include -#else -#include -#include -#endif #include #include #include #include +#include +#include + #include #include @@ -74,15 +70,7 @@ ARParam cparam; ARGL_CONTEXT_SETTINGS_REF argl_ctx; -static void key_event(unsigned char key, int x, int y); -static void main_loop(void); - -static void display_func(void) { - glutKeyboardFunc(key_event); - glutDisplayFunc(main_loop); - glutIdleFunc(main_loop); -} - +SDL_Surface *surface; static void init() { ARParam wparam; @@ -110,11 +98,36 @@ static void init() { std::cout << "*** Camera Parameters ***" << std::endl; arParamDisp(&cparam); - // Open the graphics window. - glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH | GLUT_STENCIL); - glutInitWindowPosition(0, 0); - glutInitWindowSize(1280, 1024); - glutCreateWindow(""); + // Initialize SDL + if(SDL_Init(SDL_INIT_VIDEO)) { + throw(std::runtime_error("SDL initialization failed")); + } + // Fetch the video info + const SDL_VideoInfo *info = SDL_GetVideoInfo(); + if(!info) { + throw(std::runtime_error("SDL info query failed")); + } + // The SDL mode-flags + int flags = SDL_OPENGL; // OpenGL in SDL + flags |= SDL_GL_DOUBLEBUFFER; // Double buffering + flags |= SDL_HWPALETTE; // Hardware palette + // Check for hardware surface aviability + if(info->hw_available) { + flags |= SDL_HWSURFACE; + } else { + flags |= SDL_SWSURFACE; + } + // Check for hardware blit ability + if(info->blit_hw) { + flags |= SDL_HWACCEL; + } + // Setup double buffering + SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); + // Get our surface + surface = SDL_SetVideoMode(xsize, ysize, 32, flags); + if(!surface) { + throw(std::runtime_error("Video mode set failed")); + } argl_ctx = arglSetupForCurrentContext(); @@ -181,17 +194,22 @@ static void main_loop(void) { glDisable( GL_DEPTH_TEST ); arVideoCapNext(); - glutSwapBuffers(); + SDL_GL_SwapBuffers(); } int main(int argc, char **argv) { try { - glutInit(&argc, argv); init(); patt = new Pattern(); arVideoCapStart(); - glutDisplayFunc(display_func); - glutMainLoop(); + while(1) { + SDL_Event event; + SDL_PollEvent(&event); + if(event.type == SDL_QUIT) { + break; + } + main_loop(); + } } catch(std::runtime_error e) { cleanup(); std::cerr << "Exception caught: " << e.what() << std::endl; -- cgit v1.2.3