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