OpenGLWindow.cxx
Go to the documentation of this file.
1 /* Hippo OpenGLView implementation
2  *
3  */
4 
5 // this :
6 #include "OpenGLWindow.h"
7 
8 #ifdef _MSC_VER
9 #include "msdevstudio/MSconfig.h"
10 #endif
11 
13 
14 #include "OpenGL.h"
15 
16 #include <iostream>
17 
19  Display* aDisplay
20 ,Colormap aColormap
21 ,XVisualInfo* aVisualInfo
22 ,GLXContext aGLXContext
23 )
24 :m_display( aDisplay )
25 ,m_colormap(aColormap)
26 ,m_vinfo(aVisualInfo)
27 ,m_ctx(aGLXContext)
28 ,m_window(0)
29 ,m_width(0)
30 ,m_height(0)
31 {
32  if(!m_display) return;
33  if(!m_vinfo) return;
34 
35  std::string title = "OpenGLWindow";
36 
37  int x = 0;
38  int y = 0;
39  unsigned int width = 600;
40  unsigned int height = 600;
41 
42  XSetWindowAttributes swa;
43 
44  //std::cout << "depth " << m_vinfo->depth << std::endl;
45 
46  swa.colormap = m_colormap;
47  swa.border_pixel = 0L;
48  swa.event_mask = StructureNotifyMask | ExposureMask | ButtonPressMask;
49  m_window = XCreateWindow (m_display,
50  XDefaultRootWindow(m_display),
51  x,y,width,height,
52  0,
53  m_vinfo->depth,
54  InputOutput,
55  m_vinfo->visual,
56  CWBorderPixel|CWColormap|CWEventMask,
57  &swa);
58  if(!m_window) {
59  std::cout << "Can't create an X window." << std::endl;
60  return;
61  }
62  //std::cout << "X window created." << std::endl;
63 
64  XTextProperty tp;
65  char* sl = (char*)title.c_str();
66  XStringListToTextProperty (&sl, 1, &tp);
67  XSizeHints sh;
68  sh.flags = USPosition | USSize;
69  XSetWMProperties (m_display, m_window, &tp, &tp, 0, 0, &sh, 0, 0);
70  XFree (tp.value);
71 
72  //std::cout << "map X window..." << std::endl;
73  XMapWindow (m_display,m_window);
74  XRaiseWindow (m_display,m_window);
75 
76  m_width = width;
77  m_height = height;
78 }
79 
80 
82 {
83 }
85 {
86  glFinish();
87  glXSwapBuffers(m_display,m_window);
88 }
89 
90 Window OpenGLWindow::window() const
91 {
92  return m_window;
93 }
94 
95 void OpenGLWindow::resize(int aWidth,int aHeight) {
96  if(glXMakeCurrent(m_display,m_window,m_ctx)==False) {
97  std::cout << "glXMakeCurrent failed." << std::endl;
98  }
99  glViewport (0,0,aWidth,aHeight);
100  glScissor (0,0,aWidth,aHeight);
101  m_width = aWidth;
102  m_height = aHeight;
103  paint();
104  glXSwapBuffers(m_display,m_window);
105 }
107  // Pure OpenGL (no X11, no GLX).
108 
109  glEnable (GL_LINE_STIPPLE);
110  glEnable (GL_DEPTH_TEST);
111  glEnable (GL_SCISSOR_TEST);
112  glShadeModel (GL_FLAT);
113 
114  //glClearColor (0.5,0.5,0.5,0);
115  glClearColor (1,1,1,1);
116  glClear (GL_COLOR_BUFFER_BIT);
117  glClear (GL_DEPTH_BUFFER_BIT);
118 
119  glMatrixMode (GL_PROJECTION);
120  glLoadIdentity ();
121  glOrtho (0,m_width,0,m_height,-1,1);
122  glMatrixMode (GL_MODELVIEW);
123 
124  setRect(0,0,m_width,m_height);
125 
126  glLoadIdentity();
127 
128  drawSelf();
129  flush();
130 }

Generated for HippoDraw Class Library by doxygen