OpenGLApp.cxx
Go to the documentation of this file.
1 /*
2  *
3  * $Id: OpenGLApp.cxx,v 1.5 2004/11/21 09:42:24 barrand Exp $
4  *
5  */
6 
7 // this :
8 #include "OpenGLApp.h"
9 
10 #include "OpenGLWindow.h"
11 #include "OpenGL.h"
12 
13 #include <iostream>
14 
16 :m_display(0)
17 ,m_colormap(0)
18 ,m_vinfo(0)
19 ,m_ctx(0)
20 ,m_privateColormap(true)
21 {
22 }
23 
25 {
26 }
27 
28 bool OpenGLApp::initialize ( int /*argc*/, char** /*argv*/)
29 {
30  static int attributeList[] = { GLX_RGBA,
31  GLX_RED_SIZE, 2,
32  GLX_GREEN_SIZE, 2,
33  GLX_BLUE_SIZE, 2,
34  GLX_DOUBLEBUFFER,
35  GLX_DEPTH_SIZE, 1,
36  None };
37  m_display = XOpenDisplay(NULL);
38  if(!m_display) {
39  std::cout << "Can't open display." << std::endl;
40  return false;
41  }
42 
43  m_vinfo = glXChooseVisual(m_display,XDefaultScreen(m_display),attributeList);
44  if(!m_vinfo) {
45  std::cout << "Can't choose a visual." << std::endl;
46  return false;
47  }
48 
49  m_ctx = glXCreateContext(m_display,m_vinfo,NULL,GL_FALSE);
50  if(!m_ctx) {
51  std::cout << "Can't create a GLX context." << std::endl;
52  return false;
53  }
54 
55  if(m_privateColormap) {
56  /* It is better to create a colormap adapted to the visual.*/
57  m_colormap = XCreateColormap(m_display,XDefaultRootWindow(m_display),
58  m_vinfo->visual, AllocNone);
59  } else {
60  /* Default colormap does not work on an SGI with SGI libGL.*/
61  m_colormap = XDefaultColormap(m_display,XDefaultScreen(m_display));
62  }
63  if(!m_colormap) {
64  std::cout << "Can't create X colormap." << std::endl;
65  return false;
66  }
67  //std::cout << "X, OpenGL initialized." << std::endl;
68  return true;
69 }
70 
72 {
73  if(!m_display || !m_ctx) return 0;
74  glXWaitX ();
75  while(1) {
76  XEvent xevent;
77  if(XPending(m_display)) {
78  XNextEvent (m_display,&xevent);
79  if(xevent.type==ConfigureNotify) {
80  OpenGLWindow* view = findView(xevent.xconfigure.window);
81  view->resize((int)xevent.xconfigure.width,
82  (int)xevent.xconfigure.height);
83  }
84  }
85  }
86  return 0;
87 }
88 
89 Display* OpenGLApp::getXDisplay() { return m_display; }
90 Colormap OpenGLApp::getXColormap() { return m_colormap; }
91 XVisualInfo* OpenGLApp::getXVisualInfo() { return m_vinfo; }
92 GLXContext OpenGLApp::getGLXContext() { return m_ctx; }
93 
94 OpenGLWindow* OpenGLApp::findView(Window aWindow) const {
95  for(unsigned int index=0;index<fViews.size();index++){
96  OpenGLWindow* view = fViews[index];
97  if(aWindow==view->window()) return view;
98  }
99  return 0;
100 }

Generated for HippoDraw Class Library by doxygen