summaryrefslogtreecommitdiff
path: root/foo.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'foo.cpp')
-rwxr-xr-xfoo.cpp68
1 files changed, 43 insertions, 25 deletions
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 <GL/gl.h>
-#include <GL/glut.h>
-#else
-#include <OpenGL/gl.h>
-#include <GLUT/glut.h>
-#endif
#include <AR/gsub_lite.h>
#include <AR/video.h>
#include <AR/param.h>
#include <AR/ar.h>
+#include <SDL/SDL.h>
+#include <SDL/SDL_opengl.h>
+
#include <stdexcept>
#include <iostream>
@@ -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;