Main Page Class Hierarchy Compound List File List Compound Members File Members

GLXPane.cc

Go to the documentation of this file.
00001 /*
00002 File: GLXPane.cc
00003 
00004 Function: 
00005 
00006 Author: Andrew Willmott
00007 
00008 Notes: 
00009 */
00010 
00011 #include "gcl/GCLConfig.h"
00012 
00013 #ifndef GCL_NO_GL
00014 
00015 #include "gcl/GLXPane.h"
00016 
00017 // --- GLXPane class ----------------------------------------------------------
00018 
00019 // Attributes for a normal, 24-bit, z-buffered window
00020 
00021  static Int attributeList[] = 
00022 { GLX_RGBA, GLX_DEPTH_SIZE, 12, GLX_RED_SIZE, 1, None };
00023 
00024  static Int dblAttributeList[] = 
00025 { GLX_RGBA, GLX_DEPTH_SIZE, 12, GLX_RED_SIZE, 1, GLX_DOUBLEBUFFER, None };
00026 
00027 XVisualInfo *GLXPane::sGLXVisualInfo = 0;
00028 XVisualInfo *GLXPane::sGLXDblVisualInfo = 0;
00029 
00030  GLXPane::GLXPane(Bool db) :
00031 GLRenderer(),
00032 XEventPane()
00033 {
00034 doubleBuffered = db;
00035 }
00036 
00037 GLXPane::~GLXPane()
00038 {
00039 }
00040 
00041 Void GLXPane::Init()
00042 // Attach GL context to a drawing environment
00043 {
00044 XVisualInfo *theVisualInfo;
00045 
00046 XPane::Init();
00047 
00048 theVisualInfo = GetVisualInfo();
00049 
00050 context = glXCreateContext(xgs->display, theVisualInfo, 0, GL_TRUE);
00051 glXMakeCurrent(xgs->display, paneXID, context);
00052 
00053 glWidth = width; 
00054 glHeight = height;
00055 
00056 GLRenderer::Init();
00057 }
00058 
00059 XVisualInfo *GLXPane::GetVisualInfo()
00060 {
00061 if (!sGLXVisualInfo)
00062 {
00063 sGLXVisualInfo = 
00064 glXChooseVisual(xgs->display, DefaultScreen(xgs->display), attributeList);
00065 
00066 if (!sGLXVisualInfo)
00067 _Error("Can't obtain true-colour/z-buffered display for GL");
00068 
00069 sGLXDblVisualInfo = glXChooseVisual(xgs->display, DefaultScreen(xgs->display),
00070 dblAttributeList); 
00071 
00072 if (!sGLXDblVisualInfo)
00073 {
00074 _Warning("Can't get double-buffered display");
00075 
00076 // If we can't grab a double-buffered display, default to
00077 // single-buffered.
00078 sGLXDblVisualInfo = sGLXVisualInfo; 
00079 }
00080 }
00081 
00082 if (doubleBuffered)
00083 return(sGLXDblVisualInfo);
00084 else
00085 return(sGLXVisualInfo);
00086 }
00087 
00088  Void GLXPane::MakeCurrent()
00089 {
00090 if (!xgs)
00091 _Error("Tried to manipulate a non-attached GLXPane");
00092 
00093 if (!glXMakeCurrent(xgs->display, paneXID, context))
00094 _Error("Couldn't swap graphics context");
00095 }
00096 
00097  Void GLXPane::Show()
00098 {
00099 GLRenderer::Show();
00100 
00101 if (doubleBuffered)
00102 glXSwapBuffers(xgs->display, paneXID);
00103 }
00104 
00105 
00106 // --- GLXOffscreenPane class -------------------------------------------------
00107 
00108 XVisualInfo *GLXOffscreenPane::sGLXVisualInfo = 0;
00109 
00110  GLXOffscreenPane::GLXOffscreenPane() : 
00111 XOffscreenPane(),
00112 GLRenderer()
00113 {
00114 }
00115 
00116  Void GLXOffscreenPane::Init()
00117 // Attach GL context to a drawing environment
00118 {
00119 XPane::Init();
00120 
00121 pixmap = glXCreateGLXPixmap(xgs->display, sGLXVisualInfo, paneXID);
00122 context = 
00123 glXCreateContext(xgs->display, sGLXVisualInfo, 0, GL_FALSE);
00124 
00125 glXMakeCurrent(xgs->display, pixmap, context);
00126 
00127 glWidth = width; 
00128 glHeight = height;
00129 
00130 GLRenderer::Init();
00131 }
00132 
00133  Void GLXOffscreenPane::MakeCurrent()
00134 {
00135 if (!xgs)
00136 _Error("Tried to manipulate a non-attached GLXOffscreenPane");
00137 
00138 if (!glXMakeCurrent(xgs->display, pixmap, context))
00139 _Error("Couldn't swap graphics context");
00140 }
00141 
00142  XVisualInfo *GLXOffscreenPane::GetVisualInfo()
00143 {
00144 if (!sGLXVisualInfo)
00145 {
00146 sGLXVisualInfo = 
00147 glXChooseVisual(xgs->display, DefaultScreen(xgs->display), attributeList);
00148 
00149 if (!sGLXVisualInfo)
00150 _Error("Can't obtain true-colour/z-buffered display for GL");
00151 }
00152 
00153 return(sGLXVisualInfo);
00154 }
00155 
00156  GLXOffscreenPane::~GLXOffscreenPane()
00157 {
00158 if (xgs)
00159 glXDestroyGLXPixmap(xgs->display, pixmap);
00160 }
00161 
00162 #endif

Generated at Sat Aug 5 00:16:59 2000 for Graphics Class Library by doxygen 1.1.0 written by Dimitri van Heesch, © 1997-2000

AltStyle によって変換されたページ (->オリジナル) /