LiteWindow.h
Go to the documentation of this file.
00001 #ifndef LITE_WINDOW_H
00002 #define LITE_WINDOW_H
00003 
00004 //#define WINDOW_PREFER_GLUT
00005 
00006 #if defined(WINDOW_PREFER_GLUT)
00007 
00008 #ifdef __APPLE__
00009         #include "GLUT/glut.h"
00010 #else
00011         #include "GL/glut.h"
00012 #endif
00013 //for apple, use GLUT to create the window..
00014 class LiteWindow
00015 {
00016     int glut_id;
00017 public:
00018     LiteWindow()            {  glut_id = 0;         }
00019     int IsValid()           {  return glut_id > 0; }        
00020     virtual ~LiteWindow()   {  if(glut_id > 0) glutDestroyWindow(glut_id);  }
00021     void MakeCurrent()      {  glutSetWindow(glut_id);    }
00022     void Create(int x = -1, int y = -1, const char* display = NULL)
00023     {
00024             static int _glut_init_called = 0;
00025         if(glut_id != 0) return;
00026 
00027             //see if there is an existing window
00028             if(_glut_init_called) glut_id = glutGetWindow();
00029 
00030             //create one if no glut window exists
00031             if(glut_id != 0) return;
00032 
00033             if(_glut_init_called == 0)
00034             {
00035                     int argc = 1;
00036                     char * argv[4] = { "-iconic", 0 , 0, 0};
00037             if(display) 
00038             {
00039                 argc = 3;
00040                 argv[1] = "-display";
00041                 argv[2] = (char*) display;
00042             }
00043                     glutInit(&argc, argv);
00044                     glutInitDisplayMode (GLUT_RGBA ); 
00045                     _glut_init_called = 1; 
00046             }
00047             if(x != -1) glutInitWindowPosition(x, y);
00048         if(display || x != -1) std::cout << "Using display ["
00049             << (display? display : "\0" )<< "] at (" << x << "," << y << ")\n";
00050             glut_id = glutCreateWindow ("SIFT_GPU_GLUT");
00051             glutHideWindow();
00052     }
00053 };
00054 #elif defined( _WIN32)
00055 
00056 #ifndef _INC_WINDOWS
00057 #ifndef WIN32_LEAN_AND_MEAN
00058         #define WIN32_LEAN_AND_MEAN
00059 #endif
00060 #include <windows.h>
00061 #endif 
00062 
00063 class LiteWindow
00064 {
00065     HWND hWnd;
00066     HGLRC hContext;
00067     HDC hdc;
00068 public:
00069     LiteWindow()
00070     {
00071         hWnd = NULL;
00072         hContext = NULL;
00073         hdc = NULL;
00074     }
00075     virtual ~LiteWindow()
00076     {
00077         if(hContext)wglDeleteContext(hContext);
00078         if(hdc)ReleaseDC(hWnd, hdc);
00079         if(hWnd)DestroyWindow(hWnd);
00080     }
00081     int IsValid()
00082     {  
00083         return hContext != NULL;  
00084     }
00085 
00086     //display is ignored under Win32
00087     void Create(int x = -1, int y = -1, const char* display = NULL)
00088     {
00089         if(hContext) return;
00090         WNDCLASSEX wcex = { sizeof(WNDCLASSEX),  CS_HREDRAW | CS_VREDRAW,  
00091                             (WNDPROC)DefWindowProc,  0, 4, 0, 0, 0, 0, 0,
00092                             ("SIFT_GPU_LITE"),    0};
00093         RegisterClassEx(&wcex);
00094         hWnd = CreateWindow("SIFT_GPU_LITE", "SIFT_GPU", 0,    
00095                             CW_USEDEFAULT, CW_USEDEFAULT, 
00096                             100, 100, NULL, NULL, 0, 0);
00097 
00098         //move the window so that it can be on the second monitor
00099         if(x !=-1) 
00100         {
00101             MoveWindow(hWnd, x, y, 100, 100, 0);
00102             std::cout << "CreateWindow at (" << x << "," << y<<")\n";
00103         }
00104 
00106         PIXELFORMATDESCRIPTOR pfd = 
00107         {
00108             sizeof(PIXELFORMATDESCRIPTOR), 1, 
00109             PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL ,        
00110             PFD_TYPE_RGBA,16,0, 0, 0, 0, 0, 0, 0, 0, 
00111             0, 0, 0, 0, 0, 16, 0, 0, 0, 0, 0, 0, 0                     
00112         };
00113         hdc=GetDC(hWnd);
00115         int pixelformat = ChoosePixelFormat(hdc, &pfd);
00116         DescribePixelFormat(hdc, pixelformat, sizeof(pfd), &pfd);
00117         SetPixelFormat(hdc, pixelformat, &pfd);    
00118         hContext = wglCreateContext(hdc);
00119 
00120     }
00121     void MakeCurrent()
00122     {
00123         wglMakeCurrent(hdc, hContext);
00124     }
00125 };
00126 
00127 #else
00128 
00129 #include <unistd.h>
00130 #include <X11/Xlib.h>
00131 #include <GL/glx.h>
00132 
00133 class LiteWindow
00134 {
00135     Display*     xDisplay;
00136     XVisualInfo* xVisual;    
00137     Window       xWin;
00138     GLXContext   xContext;
00139     Colormap     xColormap;
00140 public:
00141     LiteWindow()
00142     {
00143         xDisplay = NULL;
00144         xVisual = NULL;
00145         xWin = 0;
00146         xColormap = 0;
00147         xContext = NULL;
00148     }
00149     int IsValid ()  
00150     {
00151         return xContext != NULL  && glXIsDirect(xDisplay, xContext);
00152     }
00153     virtual ~LiteWindow()
00154     {
00155         if(xWin) XDestroyWindow(xDisplay, xWin);
00156         if(xContext) glXDestroyContext(xDisplay, xContext);
00157         if(xColormap) XFreeColormap(xDisplay, xColormap);
00158         if(xDisplay) XCloseDisplay(xDisplay);
00159     }
00160     void Create(int x = 0, int y = 0, const char * display = NULL)
00161     {
00162         if(xDisplay) return;
00163         if(display) std::cout << "Using display ["<<display<<"]\n";
00164 
00165         xDisplay = XOpenDisplay(display && display[0] ? display : NULL);
00166         if(xDisplay == NULL) return;
00167         int attrib[] =  {GLX_RGBA, GLX_RED_SIZE, 1, 
00168                          GLX_GREEN_SIZE, 1, GLX_BLUE_SIZE, 1,  0 }; 
00169         xVisual = glXChooseVisual(xDisplay, DefaultScreen(xDisplay), attrib);
00170         if(xVisual == NULL) return;
00171         xColormap = XCreateColormap(
00172             xDisplay, RootWindow(xDisplay, xVisual->screen), 
00173             xVisual->visual, AllocNone);
00174 
00175         XSetWindowAttributes wa;
00176         wa.event_mask       = 0;
00177         wa.border_pixel     = 0;
00178         wa.colormap = xColormap;
00179            
00180         xWin = XCreateWindow( xDisplay, RootWindow(xDisplay, xVisual->screen) , 
00181                               x, y, 100, 100, 0, xVisual->depth, 
00182                               InputOutput, xVisual->visual, 
00183                               CWBorderPixel |CWColormap | CWEventMask, &wa);
00184             
00185         xContext = glXCreateContext(xDisplay, xVisual,  0, GL_TRUE); 
00186     }
00187     void MakeCurrent()
00188     {
00189         if(xContext) glXMakeCurrent(xDisplay, xWin, xContext);
00190     }
00191 };
00192 
00193 #endif
00194 
00195 
00196 #endif
00197 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines


rgbd_registration
Author(s): Ross Kidson
autogenerated on Thu May 23 2013 15:36:53