Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

OpenGLWindow.cxx

Go to the documentation of this file.
00001 /* Hippo OpenGLView implementation
00002  *
00003  */
00004 
00005 // this :
00006 #include "OpenGLWindow.h"
00007 
00008 #ifdef HAVE_CONFIG_H
00009 #include "config.h"
00010 #else
00011 #ifdef _MSC_VER
00012 #include "msdevstudio/MSconfig.h"
00013 #endif
00014 #endif
00015 
00016 #include "plotters/CompositePlotter.h"
00017 
00018 #include "OpenGL.h"
00019 
00020 #include <iostream>
00021 
00022 OpenGLWindow::OpenGLWindow ( 
00023  Display* aDisplay
00024 ,Colormap aColormap
00025 ,XVisualInfo* aVisualInfo
00026 ,GLXContext aGLXContext
00027 )
00028 :m_display( aDisplay )
00029 ,m_colormap(aColormap)
00030 ,m_vinfo(aVisualInfo)
00031 ,m_ctx(aGLXContext)
00032 ,m_window(0)
00033 ,m_width(0)
00034 ,m_height(0)
00035 {
00036   if(!m_display) return;
00037   if(!m_vinfo) return;
00038 
00039   std::string title = "OpenGLWindow";
00040 
00041   int x = 0;
00042   int y = 0;
00043   unsigned int width = 600;
00044   unsigned int height = 600;
00045 
00046   XSetWindowAttributes swa;
00047 
00048   //std::cout << "depth " << m_vinfo->depth << std::endl;
00049 
00050   swa.colormap     = m_colormap;
00051   swa.border_pixel = 0L;
00052   swa.event_mask   = StructureNotifyMask | ExposureMask | ButtonPressMask;
00053   m_window = XCreateWindow (m_display, 
00054                             XDefaultRootWindow(m_display),
00055                             x,y,width,height,
00056                             0,
00057                             m_vinfo->depth,
00058                             InputOutput,
00059                             m_vinfo->visual,
00060                             CWBorderPixel|CWColormap|CWEventMask,
00061                             &swa);
00062   if(!m_window) {
00063     std::cout << "Can't create an X window." << std::endl;
00064     return;
00065   }
00066   //std::cout << "X window created." << std::endl;
00067 
00068   XTextProperty tp;
00069   char* sl = (char*)title.c_str();
00070   XStringListToTextProperty (&sl, 1, &tp);
00071   XSizeHints sh;
00072   sh.flags = USPosition | USSize;
00073   XSetWMProperties (m_display, m_window, &tp, &tp, 0, 0, &sh, 0, 0);
00074   XFree (tp.value);
00075 
00076   //std::cout << "map X window..." << std::endl;
00077   XMapWindow (m_display,m_window);
00078   XRaiseWindow (m_display,m_window);
00079 
00080   m_width = width;
00081   m_height = height;
00082 }
00083 
00084 
00085 OpenGLWindow::~OpenGLWindow()
00086 {
00087 }
00088 void OpenGLWindow::flush()
00089 {
00090   glFinish();
00091   glXSwapBuffers(m_display,m_window);
00092 }
00093 
00094 Window OpenGLWindow::window() const
00095 {
00096   return m_window;
00097 }
00098 
00099 void OpenGLWindow::resize(int aWidth,int aHeight) {
00100   if(glXMakeCurrent(m_display,m_window,m_ctx)==False) {
00101     std::cout << "glXMakeCurrent failed." << std::endl;
00102   }
00103   glViewport     (0,0,aWidth,aHeight);
00104   glScissor      (0,0,aWidth,aHeight);
00105   m_width = aWidth;
00106   m_height = aHeight;
00107   paint();
00108   glXSwapBuffers(m_display,m_window);
00109 }
00110 void OpenGLWindow::paint() {
00111   // Pure OpenGL (no X11, no GLX).
00112 
00113   glEnable       (GL_LINE_STIPPLE);
00114   glEnable       (GL_DEPTH_TEST);
00115   glEnable       (GL_SCISSOR_TEST);
00116   glShadeModel   (GL_FLAT);
00117 
00118   //glClearColor   (0.5,0.5,0.5,0);
00119   glClearColor   (1,1,1,1);
00120   glClear        (GL_COLOR_BUFFER_BIT);
00121   glClear        (GL_DEPTH_BUFFER_BIT);
00122 
00123   glMatrixMode   (GL_PROJECTION); 
00124   glLoadIdentity ();
00125   glOrtho        (0,m_width,0,m_height,-1,1);
00126   glMatrixMode   (GL_MODELVIEW);
00127 
00128   setRect(0,0,m_width,m_height);
00129 
00130   glLoadIdentity();
00131 
00132   drawSelf();
00133   flush();
00134 }

Generated for HippoDraw-1.14.8.5 by doxygen 1.4.3